Update V8 to version 4.7.21.
[chromium-blink-merge.git] / components / safe_json / safe_json_parser.h
blob704f0680cb39b2b7edf0311964f4860a31377acc
1 // Copyright 2013 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.
5 #ifndef COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_H_
6 #define COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
14 namespace base {
15 class Value;
18 namespace safe_json {
20 // SafeJsonParser parses a given JSON safely via a platform-dependent mechanism
21 // (like parsing it in a utility process or in a memory-safe environment).
22 // Internally, an instance of this class is created when Parse() is called and
23 // is kept alive until one of the two callbacks is called, after which it
24 // deletes itself.
25 class SafeJsonParser {
26 public:
27 using SuccessCallback = base::Callback<void(scoped_ptr<base::Value>)>;
28 using ErrorCallback = base::Callback<void(const std::string&)>;
30 using Factory = SafeJsonParser* (*)(const std::string& unsafe_json,
31 const SuccessCallback& success_callback,
32 const ErrorCallback& error_callback);
34 // Starts parsing the passed in |unsafe_json| and calls either
35 // |success_callback| or |error_callback| when finished.
36 static void Parse(const std::string& unsafe_json,
37 const SuccessCallback& success_callback,
38 const ErrorCallback& error_callback);
40 static void SetFactoryForTesting(Factory factory);
42 protected:
43 virtual ~SafeJsonParser() {}
45 private:
46 virtual void Start() = 0;
49 } // namespace safe_json
51 #endif // COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_H_