Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(959)

Side by Side Diff: chrome/browser/safe_json_parser.h

Issue 15342003: app_list: Add web store search. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_SAFE_JSON_PARSER_H_
6 #define CHROME_BROWSER_SAFE_JSON_PARSER_H_
7
8 #include <string>
9
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"
14
15 namespace base {
16 class ListValue;
17 class Value;
18 }
19
20 namespace IPC {
21 class Message;
22 }
23
24 // Helper class to parse given JSON safely via utility process.
25 class SafeJsonParser : public content::UtilityProcessHostClient {
26 public:
27 typedef base::Callback<void(scoped_ptr<base::Value>)> SuccessCallback;
28 typedef base::Callback<void(const std::string&)> ErrorCallback;
29
30 SafeJsonParser(const std::string& unsafe_json,
James Cook 2013/05/20 14:39:34 nit: Maybe comment on memory lifetime - I presume
xiyuan 2013/05/20 16:56:31 Updated the class comment to document the lifetime
31 const SuccessCallback& success_callback,
32 const ErrorCallback& error_callback);
33
34 void Start();
35
36 private:
37 virtual ~SafeJsonParser();
38
39 void StartWorkOnIOThread();
40
41 void OnJSONParseSucceeded(const base::ListValue& wrapper);
42 void OnJSONParseFailed(const std::string& error_message);
43
44 void ReportResults();
45 void ReportResultOnUIThread();
46
47 // Implementing pieces of the UtilityProcessHostClient interface.
48 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
49
50 const std::string unsafe_json_;
51 SuccessCallback success_callback_;
52 ErrorCallback error_callback_;
53
54 scoped_ptr<base::Value> parsed_json_;
55 std::string error_;
56
57 DISALLOW_COPY_AND_ASSIGN(SafeJsonParser);
58 };
59
60 #endif // CHROME_BROWSER_SAFE_JSON_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698