Chromium Code Reviews| Index: components/safe_json/safe_json_parser_impl.h |
| diff --git a/components/safe_json/safe_json_parser_impl.h b/components/safe_json/safe_json_parser_impl.h |
| index eefa187d35b9d0f16800cfb2d6afe914d4711488..6c5dea693f6f9afe855c6f10088182cd5c913b5d 100644 |
| --- a/components/safe_json/safe_json_parser_impl.h |
| +++ b/components/safe_json/safe_json_parser_impl.h |
| @@ -8,13 +8,12 @@ |
| #include <memory> |
| #include <string> |
| +#include "base/callback.h" |
| #include "base/macros.h" |
| #include "base/memory/ref_counted.h" |
| -#include "base/memory/weak_ptr.h" |
| -#include "base/threading/thread_checker.h" |
|
Anand Mistry (off Chromium)
2016/06/10 11:13:54
thread_checker.h is still used.
Patrick Monette
2016/06/10 18:13:23
Done.
|
| #include "components/safe_json/public/interfaces/safe_json.mojom.h" |
| #include "components/safe_json/safe_json_parser.h" |
| -#include "content/public/browser/utility_process_host_client.h" |
| +#include "content/public/browser/utility_process_mojo_client.h" |
| namespace base { |
| class ListValue; |
| @@ -22,54 +21,48 @@ class SequencedTaskRunner; |
| class Value; |
| } |
| -namespace content { |
| -class UtilityProcessHost; |
| -} |
| - |
| -namespace IPC { |
| -class Message; |
| -} |
| - |
| namespace safe_json { |
| -class SafeJsonParserImpl : public content::UtilityProcessHostClient, |
| - public SafeJsonParser { |
| +class SafeJsonParserImpl |
| + : public base::RefCountedThreadSafe<SafeJsonParserImpl>, |
|
Bernhard Bauer
2016/06/09 15:16:50
Ooh, if this class now doesn't inherit from a refc
Patrick Monette
2016/06/10 18:13:23
Done.
|
| + public SafeJsonParser { |
| public: |
| SafeJsonParserImpl(const std::string& unsafe_json, |
| const SuccessCallback& success_callback, |
| const ErrorCallback& error_callback); |
| private: |
| - ~SafeJsonParserImpl() override; |
| - |
| - void StartWorkOnIOThread(); |
| - |
| - void ReportResults(); |
| - void ReportResultsOnOriginThread(); |
| + friend class base::RefCountedThreadSafe<SafeJsonParserImpl>; |
| - // Implementing pieces of the UtilityProcessHostClient interface. |
| - bool OnMessageReceived(const IPC::Message& message) override; |
| + ~SafeJsonParserImpl() override; |
| // SafeJsonParser implementation. |
| void Start() override; |
| + void StartOnIoThread(); |
|
grt (UTC plus 2)
2016/06/09 14:48:58
nit: OnIOThread is far more prevalent in the codeb
Patrick Monette
2016/06/10 18:13:23
Done.
|
| + |
|
grt (UTC plus 2)
2016/06/09 14:48:58
nit: either remove ths blank lines separating thes
Patrick Monette
2016/06/10 18:13:23
Done.
|
| + void OnConnectionError(); |
| + |
| // mojom::SafeJsonParser::Parse callback. |
| - void OnParseDone(const base::ListValue& wrapper, mojo::String error); |
| + void OnParseDone(const base::ListValue& wrapper, const mojo::String& error); |
| + |
| + // Reports the result on the calling task runner via the |success_callback_| |
| + // or the |error_callback_|. |
| + void ReportResults(std::unique_ptr<base::Value> parsed_json, |
| + const std::string& error); |
| const std::string unsafe_json_; |
| SuccessCallback success_callback_; |
| ErrorCallback error_callback_; |
| scoped_refptr<base::SequencedTaskRunner> caller_task_runner_; |
| - std::unique_ptr<base::Value> parsed_json_; |
| - std::string error_; |
| - |
| - base::WeakPtr<content::UtilityProcessHost> utility_process_host_; |
| - |
| - mojom::SafeJsonParserPtr service_; |
| + std::unique_ptr<content::UtilityProcessMojoClient<mojom::SafeJsonParser>> |
| + mojo_json_parser_; |
| - // To ensure the UtilityProcessHost and Mojo service are only accessed on the |
| - // IO thread. |
| + // Used instead of DCHECK_CURRENTLY_ON(BrowserThread::UI) because it's |
|
Bernhard Bauer
2016/06/09 15:16:50
BrowserThread::IO?
Patrick Monette
2016/06/10 18:13:23
Right!Fixed.
|
| + // posssible that it fails when the IO thread message loop is shutting down. |
| + // This happens after the IO thread has unregistered from the BrowserThread |
| + // list. |
| base::ThreadChecker io_thread_checker_; |
| DISALLOW_COPY_AND_ASSIGN(SafeJsonParserImpl); |