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

Unified Diff: chrome/browser/web_resource/json_asynchronous_unpacker.h

Issue 10690096: Extracted inner class doing process dispatch. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: FIxing initialization bug. Created 8 years, 5 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
Index: chrome/browser/web_resource/json_asynchronous_unpacker.h
diff --git a/chrome/browser/web_resource/json_asynchronous_unpacker.h b/chrome/browser/web_resource/json_asynchronous_unpacker.h
new file mode 100644
index 0000000000000000000000000000000000000000..9fca180d01d8f1c582babd732b44c5c8f3719454
--- /dev/null
+++ b/chrome/browser/web_resource/json_asynchronous_unpacker.h
@@ -0,0 +1,55 @@
+// Copyright (c) 2012 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_WEB_RESOURCE_JSON_ASYNCHRONOUS_UNPACKER_H_
+#define CHROME_BROWSER_WEB_RESOURCE_JSON_ASYNCHRONOUS_UNPACKER_H_
+
+#include <string>
+
+#include "base/values.h"
+
+// A delegate interface for users of JSONAsynchronousUnpacker.
+class JSONAsynchronousUnpackerDelegate {
+ public:
+ virtual ~JSONAsynchronousUnpackerDelegate() {}
+
+ // This will be called when the response is parsed properly. |parsed_json|
+ // contains the decoded information.
+ virtual void OnUnpackFinished(const DictionaryValue& parsed_json) = 0;
+
+ // This will be called if there is an error while parsing the data.
+ virtual void OnUnpackError(const std::string& error_message) = 0;
+};
+
+// This class coordinates a web resource unpack and parse task which is run
+// asynchronously. Results are sent back to the delegate via one of its
+// OnUnpack<xxx> method.
Miranda Callahan 2012/07/09 14:24:30 nit: s/method/methods.
noyau (Ping after 24h) 2012/07/09 15:23:57 Done.
+class JSONAsynchronousUnpacker {
+ public:
+ // Creates a WebResourceServiceUnpacker appropriate for the platform. The
+ // delegate must be kept around until one of the delegate method is called.
Miranda Callahan 2012/07/09 14:24:30 nit: s/method/methods.
noyau (Ping after 24h) 2012/07/09 15:23:57 Done.
+ // In case the delegate is no longer valid, ClearDelegate() must be called.
+ static JSONAsynchronousUnpacker*
+ Create(JSONAsynchronousUnpackerDelegate* delegate);
+
+ virtual ~JSONAsynchronousUnpacker() {}
+
+ // Start the decoding. The concrete implementation should delete itself after
+ // calling the delegate method.
+ virtual void Start(const std::string& json_data) = 0;
+
+ // If the delegate is going away it needs to inform the unpacker about it.
+ void ClearDelegate() {
+ delegate_ = NULL;
+ };
+
+ protected:
+ explicit JSONAsynchronousUnpacker(JSONAsynchronousUnpackerDelegate* delegate)
+ : delegate_(delegate) {
+ }
+
+ JSONAsynchronousUnpackerDelegate* delegate_;
+};
+
+#endif // CHROME_BROWSER_WEB_RESOURCE_JSON_ASYNCHRONOUS_UNPACKER_H_

Powered by Google App Engine
This is Rietveld 408576698