| OLD | NEW |
| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "components/safe_json/public/interfaces/safe_json.mojom.h" |
| 13 #include "components/safe_json/safe_json_parser.h" | 15 #include "components/safe_json/safe_json_parser.h" |
| 14 #include "content/public/browser/utility_process_host_client.h" | 16 #include "content/public/browser/utility_process_host_client.h" |
| 15 | 17 |
| 16 namespace base { | 18 namespace base { |
| 17 class ListValue; | 19 class ListValue; |
| 18 class SequencedTaskRunner; | 20 class SequencedTaskRunner; |
| 19 class Value; | 21 class Value; |
| 20 } | 22 } |
| 21 | 23 |
| 24 namespace content { |
| 25 class UtilityProcessHost; |
| 26 } |
| 27 |
| 22 namespace IPC { | 28 namespace IPC { |
| 23 class Message; | 29 class Message; |
| 24 } | 30 } |
| 25 | 31 |
| 26 namespace safe_json { | 32 namespace safe_json { |
| 27 | 33 |
| 28 class SafeJsonParserImpl : public content::UtilityProcessHostClient, | 34 class SafeJsonParserImpl : public content::UtilityProcessHostClient, |
| 29 public SafeJsonParser { | 35 public SafeJsonParser { |
| 30 public: | 36 public: |
| 31 SafeJsonParserImpl(const std::string& unsafe_json, | 37 SafeJsonParserImpl(const std::string& unsafe_json, |
| 32 const SuccessCallback& success_callback, | 38 const SuccessCallback& success_callback, |
| 33 const ErrorCallback& error_callback); | 39 const ErrorCallback& error_callback); |
| 34 | 40 |
| 35 private: | 41 private: |
| 36 ~SafeJsonParserImpl() override; | 42 ~SafeJsonParserImpl() override; |
| 37 | 43 |
| 38 void StartWorkOnIOThread(); | 44 void StartWorkOnIOThread(); |
| 39 | 45 |
| 40 void OnJSONParseSucceeded(const base::ListValue& wrapper); | |
| 41 void OnJSONParseFailed(const std::string& error_message); | |
| 42 | |
| 43 void ReportResults(); | 46 void ReportResults(); |
| 44 void ReportResultsOnOriginThread(); | 47 void ReportResultsOnOriginThread(); |
| 45 | 48 |
| 46 // Implementing pieces of the UtilityProcessHostClient interface. | 49 // Implementing pieces of the UtilityProcessHostClient interface. |
| 47 bool OnMessageReceived(const IPC::Message& message) override; | 50 bool OnMessageReceived(const IPC::Message& message) override; |
| 48 | 51 |
| 49 // SafeJsonParser implementation. | 52 // SafeJsonParser implementation. |
| 50 void Start() override; | 53 void Start() override; |
| 51 | 54 |
| 55 // mojom::SafeJsonParser::Parse callback. |
| 56 void OnParseDone(const base::ListValue& wrapper, mojo::String error); |
| 57 |
| 52 const std::string unsafe_json_; | 58 const std::string unsafe_json_; |
| 53 SuccessCallback success_callback_; | 59 SuccessCallback success_callback_; |
| 54 ErrorCallback error_callback_; | 60 ErrorCallback error_callback_; |
| 55 scoped_refptr<base::SequencedTaskRunner> caller_task_runner_; | 61 scoped_refptr<base::SequencedTaskRunner> caller_task_runner_; |
| 56 | 62 |
| 57 scoped_ptr<base::Value> parsed_json_; | 63 scoped_ptr<base::Value> parsed_json_; |
| 58 std::string error_; | 64 std::string error_; |
| 59 | 65 |
| 66 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; |
| 67 |
| 68 mojom::SafeJsonParserPtr service_; |
| 69 |
| 60 DISALLOW_COPY_AND_ASSIGN(SafeJsonParserImpl); | 70 DISALLOW_COPY_AND_ASSIGN(SafeJsonParserImpl); |
| 61 }; | 71 }; |
| 62 | 72 |
| 63 } // namespace safe_json | 73 } // namespace safe_json |
| 64 | 74 |
| 65 #endif // COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_IMPL_H_ | 75 #endif // COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_IMPL_H_ |
| OLD | NEW |