Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / web_resource / json_asynchronous_unpacker.h
blob9ae22189222858ec3e3e6fa3810d5d012916e46c
1 // Copyright (c) 2012 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_WEB_RESOURCE_JSON_ASYNCHRONOUS_UNPACKER_H_
6 #define CHROME_BROWSER_WEB_RESOURCE_JSON_ASYNCHRONOUS_UNPACKER_H_
8 #include <string>
10 #include "base/values.h"
12 // A delegate interface for users of JSONAsynchronousUnpacker.
13 class JSONAsynchronousUnpackerDelegate {
14 public:
15 virtual ~JSONAsynchronousUnpackerDelegate() {}
17 // This will be called when the response is parsed properly. |parsed_json|
18 // contains the decoded information.
19 virtual void OnUnpackFinished(const base::DictionaryValue& parsed_json) = 0;
21 // This will be called if there is an error while parsing the data.
22 virtual void OnUnpackError(const std::string& error_message) = 0;
25 // This class coordinates a web resource unpack and parse task which is run
26 // asynchronously. Results are sent back to the delegate via one of its
27 // OnUnpack<xxx> methods.
28 class JSONAsynchronousUnpacker {
29 public:
30 // Creates a WebResourceServiceUnpacker appropriate for the platform. The
31 // delegate must be kept around until one of the delegate methods is called.
32 // In case the delegate is no longer valid, ClearDelegate() must be called.
33 static JSONAsynchronousUnpacker*
34 Create(JSONAsynchronousUnpackerDelegate* delegate);
36 virtual ~JSONAsynchronousUnpacker() {}
38 // Start the decoding. The concrete implementation should delete itself after
39 // calling the delegate method.
40 virtual void Start(const std::string& json_data) = 0;
42 // If the delegate is going away it needs to inform the unpacker about it.
43 void ClearDelegate() {
44 delegate_ = NULL;
47 protected:
48 explicit JSONAsynchronousUnpacker(JSONAsynchronousUnpackerDelegate* delegate)
49 : delegate_(delegate) {
52 JSONAsynchronousUnpackerDelegate* delegate_;
55 #endif // CHROME_BROWSER_WEB_RESOURCE_JSON_ASYNCHRONOUS_UNPACKER_H_