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

Unified 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: rebase and address nits in #3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/webstore_data_fetcher.cc ('k') | chrome/browser/safe_json_parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/safe_json_parser.h
diff --git a/chrome/browser/safe_json_parser.h b/chrome/browser/safe_json_parser.h
new file mode 100644
index 0000000000000000000000000000000000000000..1133a7806984bb0bb28d98798dcb93fb7fbc5687
--- /dev/null
+++ b/chrome/browser/safe_json_parser.h
@@ -0,0 +1,62 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SAFE_JSON_PARSER_H_
+#define CHROME_BROWSER_SAFE_JSON_PARSER_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/public/browser/utility_process_host_client.h"
+
+namespace base {
+class ListValue;
+class Value;
+}
+
+namespace IPC {
+class Message;
+}
+
+// SafeJsonParser parses a given JSON safely via a utility process. The object
+// is ref-counted and kept alive after Start() is called until one of the two
+// callbacks is called.
+class SafeJsonParser : public content::UtilityProcessHostClient {
+ public:
+ typedef base::Callback<void(scoped_ptr<base::Value>)> SuccessCallback;
+ typedef base::Callback<void(const std::string&)> ErrorCallback;
+
+ SafeJsonParser(const std::string& unsafe_json,
+ const SuccessCallback& success_callback,
+ const ErrorCallback& error_callback);
+
+ void Start();
+
+ private:
+ virtual ~SafeJsonParser();
+
+ void StartWorkOnIOThread();
+
+ void OnJSONParseSucceeded(const base::ListValue& wrapper);
+ void OnJSONParseFailed(const std::string& error_message);
+
+ void ReportResults();
+ void ReportResultOnUIThread();
+
+ // Implementing pieces of the UtilityProcessHostClient interface.
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ const std::string unsafe_json_;
+ SuccessCallback success_callback_;
+ ErrorCallback error_callback_;
+
+ scoped_ptr<base::Value> parsed_json_;
+ std::string error_;
+
+ DISALLOW_COPY_AND_ASSIGN(SafeJsonParser);
+};
+
+#endif // CHROME_BROWSER_SAFE_JSON_PARSER_H_
« no previous file with comments | « chrome/browser/extensions/webstore_data_fetcher.cc ('k') | chrome/browser/safe_json_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698