blob: 4a5a1f47dcdb1734cc9dda529b3942fc9483a295 [file] [log] [blame]
sfiera6e6e5412016-11-18 20:13:191// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_NTP_TILES_JSON_UNSAFE_PARSER_H_
6#define COMPONENTS_NTP_TILES_JSON_UNSAFE_PARSER_H_
7
8#include <memory>
9#include <string>
10
11#include "base/callback_forward.h"
12
13namespace base {
14class Value;
15}
16
17namespace ntp_tiles {
18
19// Mimics SafeJsonParser, but parses unsafely.
20//
21// Do not use this class, unless you can't help it. On most platforms,
22// SafeJsonParser is available and is safer. If it is not available (e.g. on
23// iOS), then this class mimics its API without its safety.
24class JsonUnsafeParser {
25 public:
26 using SuccessCallback = base::Callback<void(std::unique_ptr<base::Value>)>;
27 using ErrorCallback = base::Callback<void(const std::string&)>;
28
29 // As with SafeJsonParser, runs either success_callback or error_callback on
30 // the calling thread, but not before the call returns.
31 static void Parse(const std::string& unsafe_json,
32 const SuccessCallback& success_callback,
33 const ErrorCallback& error_callback);
34
35 JsonUnsafeParser() = delete;
36};
37
38} // namespace ntp_tiles
39
40#endif // COMPONENTS_NTP_TILES_POPULAR_SITES_H_