OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_DATA_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_DATA_FETCHER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_DATA_FETCHER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_DATA_FETCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
11 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
12 #include "net/url_request/url_fetcher_delegate.h" | 13 #include "net/url_request/url_fetcher_delegate.h" |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 class DictionaryValue; | 16 class Value; |
16 } | 17 } |
17 | 18 |
18 namespace net { | 19 namespace net { |
19 class URLFetcher; | 20 class URLFetcher; |
20 class URLRequestContextGetter; | 21 class URLRequestContextGetter; |
21 } | 22 } |
22 | 23 |
23 namespace extensions { | 24 namespace extensions { |
24 | 25 |
25 class WebstoreDataFetcherDelegate; | 26 class WebstoreDataFetcherDelegate; |
26 | 27 |
27 // WebstoreDataFetcher fetches web store data and parses it into a | 28 // WebstoreDataFetcher fetches web store data and parses it into a |
28 // DictionaryValue. | 29 // DictionaryValue. |
29 class WebstoreDataFetcher : public base::SupportsWeakPtr<WebstoreDataFetcher>, | 30 class WebstoreDataFetcher : public base::SupportsWeakPtr<WebstoreDataFetcher>, |
30 public net::URLFetcherDelegate { | 31 public net::URLFetcherDelegate { |
31 public: | 32 public: |
32 WebstoreDataFetcher(WebstoreDataFetcherDelegate* delegate, | 33 WebstoreDataFetcher(WebstoreDataFetcherDelegate* delegate, |
33 net::URLRequestContextGetter* request_context, | 34 net::URLRequestContextGetter* request_context, |
34 const GURL& referrer_url, | 35 const GURL& referrer_url, |
35 const std::string webstore_item_id); | 36 const std::string webstore_item_id); |
36 virtual ~WebstoreDataFetcher(); | 37 virtual ~WebstoreDataFetcher(); |
37 | 38 |
38 void Start(); | 39 void Start(); |
39 | 40 |
40 private: | 41 private: |
41 class SafeWebstoreResponseParser; | 42 void OnJsonParseSuccess(scoped_ptr<base::Value> parsed_json); |
42 | 43 void OnJsonParseFailure(const std::string& error); |
43 // Client callbacks for SafeWebstoreResponseParser when parsing is complete. | |
44 void OnWebstoreResponseParseSuccess(base::DictionaryValue* webstore_data); | |
45 void OnWebstoreResponseParseFailure(const std::string& error); | |
46 | 44 |
47 // net::URLFetcherDelegate overrides: | 45 // net::URLFetcherDelegate overrides: |
48 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 46 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
49 | 47 |
50 WebstoreDataFetcherDelegate* delegate_; | 48 WebstoreDataFetcherDelegate* delegate_; |
51 net::URLRequestContextGetter* request_context_; | 49 net::URLRequestContextGetter* request_context_; |
52 GURL referrer_url_; | 50 GURL referrer_url_; |
53 std::string id_; | 51 std::string id_; |
54 | 52 |
55 // For fetching webstore JSON data. | 53 // For fetching webstore JSON data. |
56 scoped_ptr<net::URLFetcher> webstore_data_url_fetcher_; | 54 scoped_ptr<net::URLFetcher> webstore_data_url_fetcher_; |
57 | 55 |
58 DISALLOW_COPY_AND_ASSIGN(WebstoreDataFetcher); | 56 DISALLOW_COPY_AND_ASSIGN(WebstoreDataFetcher); |
59 }; | 57 }; |
60 | 58 |
61 } // namespace extensions | 59 } // namespace extensions |
62 | 60 |
63 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_DATA_FETCHER_H_ | 61 #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_DATA_FETCHER_H_ |
OLD | NEW |