Introduce ProfilerMetricsProvider
[chromium-blink-merge.git] / chrome / browser / safe_json_parser.h
blob1133a7806984bb0bb28d98798dcb93fb7fbc5687
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 CHROME_BROWSER_SAFE_JSON_PARSER_H_
6 #define CHROME_BROWSER_SAFE_JSON_PARSER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/public/browser/utility_process_host_client.h"
15 namespace base {
16 class ListValue;
17 class Value;
20 namespace IPC {
21 class Message;
24 // SafeJsonParser parses a given JSON safely via a utility process. The object
25 // is ref-counted and kept alive after Start() is called until one of the two
26 // callbacks is called.
27 class SafeJsonParser : public content::UtilityProcessHostClient {
28 public:
29 typedef base::Callback<void(scoped_ptr<base::Value>)> SuccessCallback;
30 typedef base::Callback<void(const std::string&)> ErrorCallback;
32 SafeJsonParser(const std::string& unsafe_json,
33 const SuccessCallback& success_callback,
34 const ErrorCallback& error_callback);
36 void Start();
38 private:
39 virtual ~SafeJsonParser();
41 void StartWorkOnIOThread();
43 void OnJSONParseSucceeded(const base::ListValue& wrapper);
44 void OnJSONParseFailed(const std::string& error_message);
46 void ReportResults();
47 void ReportResultOnUIThread();
49 // Implementing pieces of the UtilityProcessHostClient interface.
50 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
52 const std::string unsafe_json_;
53 SuccessCallback success_callback_;
54 ErrorCallback error_callback_;
56 scoped_ptr<base::Value> parsed_json_;
57 std::string error_;
59 DISALLOW_COPY_AND_ASSIGN(SafeJsonParser);
62 #endif // CHROME_BROWSER_SAFE_JSON_PARSER_H_