Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: components/safe_json_parser/safe_json_parser.h

Issue 1211793002: Rename safe_json_parser component to safe_json. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/safe_json_parser/OWNERS ('k') | components/safe_json_parser/safe_json_parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef COMPONENTS_SAFE_JSON_PARSER_SAFE_JSON_PARSER_H_
6 #define COMPONENTS_SAFE_JSON_PARSER_SAFE_JSON_PARSER_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/public/browser/utility_process_host_client.h"
14
15 namespace base {
16 class ListValue;
17 class Value;
18 }
19
20 namespace IPC {
21 class Message;
22 }
23
24 namespace safe_json_parser {
25
26 // SafeJsonParser parses a given JSON safely via a utility process. The object
27 // is ref-counted and kept alive after Start() is called until one of the two
28 // callbacks is called.
29 class SafeJsonParser : public content::UtilityProcessHostClient {
30 public:
31 typedef base::Callback<void(scoped_ptr<base::Value>)> SuccessCallback;
32 typedef base::Callback<void(const std::string&)> ErrorCallback;
33
34 SafeJsonParser(const std::string& unsafe_json,
35 const SuccessCallback& success_callback,
36 const ErrorCallback& error_callback);
37
38 void Start();
39
40 private:
41 ~SafeJsonParser() override;
42
43 void StartWorkOnIOThread();
44
45 void OnJSONParseSucceeded(const base::ListValue& wrapper);
46 void OnJSONParseFailed(const std::string& error_message);
47
48 void ReportResults();
49 void ReportResultOnUIThread();
50
51 // Implementing pieces of the UtilityProcessHostClient interface.
52 bool OnMessageReceived(const IPC::Message& message) override;
53
54 const std::string unsafe_json_;
55 SuccessCallback success_callback_;
56 ErrorCallback error_callback_;
57
58 scoped_ptr<base::Value> parsed_json_;
59 std::string error_;
60
61 DISALLOW_COPY_AND_ASSIGN(SafeJsonParser);
62 };
63
64 } // namespace safe_json_parser
65
66 #endif // COMPONENTS_SAFE_JSON_PARSER_SAFE_JSON_PARSER_H_
OLDNEW
« no previous file with comments | « components/safe_json_parser/OWNERS ('k') | components/safe_json_parser/safe_json_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698