summaryrefslogtreecommitdiffstats
path: root/chrome/browser/web_resource/json_asynchronous_unpacker.h
diff options
context:
space:
mode:
authornoyau@chromium.org <noyau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-09 17:14:06 +0000
committernoyau@chromium.org <noyau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-09 17:14:06 +0000
commit7e2d6e1cdbc0f6c05c5db1262f9d2a8d2eec1edb (patch)
tree3a700ff04f62791cb9f02c60cf2f787c9849bdc9 /chrome/browser/web_resource/json_asynchronous_unpacker.h
parentab491977050564d2af239ea7294d1de22d3a570d (diff)
downloadchromium_src-7e2d6e1cdbc0f6c05c5db1262f9d2a8d2eec1edb.zip
chromium_src-7e2d6e1cdbc0f6c05c5db1262f9d2a8d2eec1edb.tar.gz
chromium_src-7e2d6e1cdbc0f6c05c5db1262f9d2a8d2eec1edb.tar.bz2
Extracted inner class doing process dispatch.
The inner class WebResourceService::UnpackerClient is dispatching a json parsing job to a subprocess. In iOS launching a subprocess is not supported. In order to replace this class on this particular platform by one doing a thread dispatch the class has been renamed and refactored in its own file. In doing so an abstract superclass was crated to make the API more obvious. The iOS subclass already exists in the iOS tree, and will be brought up with the rest of the iOS browser changes. BUG=b/6753678 TEST=No user visible changes. Review URL: https://chromiumcodereview.appspot.com/10690096 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145689 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/web_resource/json_asynchronous_unpacker.h')
-rw-r--r--chrome/browser/web_resource/json_asynchronous_unpacker.h55
1 files changed, 55 insertions, 0 deletions
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 0000000..4a58047
--- /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> methods.
+class JSONAsynchronousUnpacker {
+ public:
+ // Creates a WebResourceServiceUnpacker appropriate for the platform. The
+ // delegate must be kept around until one of the delegate methods is called.
+ // 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_