ApplicationImpl cleanup, part 1:
[chromium-blink-merge.git] / components / safe_json / safe_json_parser_impl.h
blob277ee08f95674c0e1178ac0244e0177061638276
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_IMPL_H_
6 #define COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_IMPL_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/safe_json/safe_json_parser.h"
13 #include "content/public/browser/utility_process_host_client.h"
15 namespace base {
16 class ListValue;
17 class SequencedTaskRunner;
18 class Value;
21 namespace IPC {
22 class Message;
25 namespace safe_json {
27 class SafeJsonParserImpl : public content::UtilityProcessHostClient,
28 public SafeJsonParser {
29 public:
30 SafeJsonParserImpl(const std::string& unsafe_json,
31 const SuccessCallback& success_callback,
32 const ErrorCallback& error_callback);
34 private:
35 ~SafeJsonParserImpl() override;
37 void StartWorkOnIOThread();
39 void OnJSONParseSucceeded(const base::ListValue& wrapper);
40 void OnJSONParseFailed(const std::string& error_message);
42 void ReportResults();
43 void ReportResultsOnOriginThread();
45 // Implementing pieces of the UtilityProcessHostClient interface.
46 bool OnMessageReceived(const IPC::Message& message) override;
48 // SafeJsonParser implementation.
49 void Start() override;
51 const std::string unsafe_json_;
52 SuccessCallback success_callback_;
53 ErrorCallback error_callback_;
54 scoped_refptr<base::SequencedTaskRunner> caller_task_runner_;
56 scoped_ptr<base::Value> parsed_json_;
57 std::string error_;
59 DISALLOW_COPY_AND_ASSIGN(SafeJsonParserImpl);
62 } // namespace safe_json
64 #endif // COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_IMPL_H_