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_
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"
17 class SequencedTaskRunner
;
27 class SafeJsonParserImpl
: public content::UtilityProcessHostClient
,
28 public SafeJsonParser
{
30 SafeJsonParserImpl(const std::string
& unsafe_json
,
31 const SuccessCallback
& success_callback
,
32 const ErrorCallback
& error_callback
);
35 ~SafeJsonParserImpl() override
;
37 void StartWorkOnIOThread();
39 void OnJSONParseSucceeded(const base::ListValue
& wrapper
);
40 void OnJSONParseFailed(const std::string
& error_message
);
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_
;
59 DISALLOW_COPY_AND_ASSIGN(SafeJsonParserImpl
);
62 } // namespace safe_json
64 #endif // COMPONENTS_SAFE_JSON_SAFE_JSON_PARSER_IMPL_H_