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

Side by Side Diff: components/safe_json/safe_json_parser_impl.h

Issue 1951863002: Revert of Convert the utility process JSON parser into a Mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_IMPL_H_ 5 #ifndef COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_IMPL_H_
6 #define COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_IMPL_H_ 6 #define COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_IMPL_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/threading/thread_checker.h"
15 #include "components/safe_json/public/interfaces/safe_json.mojom.h"
16 #include "components/safe_json/safe_json_parser.h" 13 #include "components/safe_json/safe_json_parser.h"
17 #include "content/public/browser/utility_process_host_client.h" 14 #include "content/public/browser/utility_process_host_client.h"
18 15
19 namespace base { 16 namespace base {
20 class ListValue; 17 class ListValue;
21 class SequencedTaskRunner; 18 class SequencedTaskRunner;
22 class Value; 19 class Value;
23 } 20 }
24 21
25 namespace content {
26 class UtilityProcessHost;
27 }
28
29 namespace IPC { 22 namespace IPC {
30 class Message; 23 class Message;
31 } 24 }
32 25
33 namespace safe_json { 26 namespace safe_json {
34 27
35 class SafeJsonParserImpl : public content::UtilityProcessHostClient, 28 class SafeJsonParserImpl : public content::UtilityProcessHostClient,
36 public SafeJsonParser { 29 public SafeJsonParser {
37 public: 30 public:
38 SafeJsonParserImpl(const std::string& unsafe_json, 31 SafeJsonParserImpl(const std::string& unsafe_json,
39 const SuccessCallback& success_callback, 32 const SuccessCallback& success_callback,
40 const ErrorCallback& error_callback); 33 const ErrorCallback& error_callback);
41 34
42 private: 35 private:
43 ~SafeJsonParserImpl() override; 36 ~SafeJsonParserImpl() override;
44 37
45 void StartWorkOnIOThread(); 38 void StartWorkOnIOThread();
46 39
40 void OnJSONParseSucceeded(const base::ListValue& wrapper);
41 void OnJSONParseFailed(const std::string& error_message);
42
47 void ReportResults(); 43 void ReportResults();
48 void ReportResultsOnOriginThread(); 44 void ReportResultsOnOriginThread();
49 45
50 // Implementing pieces of the UtilityProcessHostClient interface. 46 // Implementing pieces of the UtilityProcessHostClient interface.
51 bool OnMessageReceived(const IPC::Message& message) override; 47 bool OnMessageReceived(const IPC::Message& message) override;
52 48
53 // SafeJsonParser implementation. 49 // SafeJsonParser implementation.
54 void Start() override; 50 void Start() override;
55 51
56 // mojom::SafeJsonParser::Parse callback.
57 void OnParseDone(const base::ListValue& wrapper, mojo::String error);
58
59 const std::string unsafe_json_; 52 const std::string unsafe_json_;
60 SuccessCallback success_callback_; 53 SuccessCallback success_callback_;
61 ErrorCallback error_callback_; 54 ErrorCallback error_callback_;
62 scoped_refptr<base::SequencedTaskRunner> caller_task_runner_; 55 scoped_refptr<base::SequencedTaskRunner> caller_task_runner_;
63 56
64 std::unique_ptr<base::Value> parsed_json_; 57 std::unique_ptr<base::Value> parsed_json_;
65 std::string error_; 58 std::string error_;
66 59
67 base::WeakPtr<content::UtilityProcessHost> utility_process_host_;
68
69 mojom::SafeJsonParserPtr service_;
70
71 // To ensure the UtilityProcessHost and Mojo service are only accessed on the
72 // IO thread.
73 base::ThreadChecker io_thread_checker_;
74
75 DISALLOW_COPY_AND_ASSIGN(SafeJsonParserImpl); 60 DISALLOW_COPY_AND_ASSIGN(SafeJsonParserImpl);
76 }; 61 };
77 62
78 } // namespace safe_json 63 } // namespace safe_json
79 64
80 #endif // COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_IMPL_H_ 65 #endif // COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_IMPL_H_
OLDNEW
« no previous file with comments | « components/safe_json/public/interfaces/safe_json.typemap ('k') | components/safe_json/safe_json_parser_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698