[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef CHROME_BROWSER_EXTENSIONS_WEBSTORE_DATA_FETCHER_H_ | ||||
6 | #define CHROME_BROWSER_EXTENSIONS_WEBSTORE_DATA_FETCHER_H_ | ||||
7 | |||||
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 8 | #include <memory> |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 9 | #include <string> |
10 | |||||
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 12 | #include "base/memory/weak_ptr.h" |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 13 | #include "net/url_request/url_fetcher_delegate.h" |
[email protected] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame] | 14 | #include "url/gurl.h" |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 15 | |
16 | namespace base { | ||||
[email protected] | 1f6a9a6 | 2013-05-22 01:53:06 | [diff] [blame] | 17 | class Value; |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 18 | } |
19 | |||||
20 | namespace net { | ||||
21 | class URLFetcher; | ||||
22 | class URLRequestContextGetter; | ||||
23 | } | ||||
24 | |||||
25 | namespace extensions { | ||||
26 | |||||
27 | class WebstoreDataFetcherDelegate; | ||||
28 | |||||
29 | // WebstoreDataFetcher fetches web store data and parses it into a | ||||
30 | // DictionaryValue. | ||||
31 | class WebstoreDataFetcher : public base::SupportsWeakPtr<WebstoreDataFetcher>, | ||||
32 | public net::URLFetcherDelegate { | ||||
33 | public: | ||||
34 | WebstoreDataFetcher(WebstoreDataFetcherDelegate* delegate, | ||||
35 | net::URLRequestContextGetter* request_context, | ||||
36 | const GURL& referrer_url, | ||||
37 | const std::string webstore_item_id); | ||||
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 38 | ~WebstoreDataFetcher() override; |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 39 | |
40 | void Start(); | ||||
41 | |||||
[email protected] | 270dccc | 2014-07-11 07:20:37 | [diff] [blame] | 42 | void set_max_auto_retries(int max_retries) { |
43 | max_auto_retries_ = max_retries; | ||||
44 | } | ||||
45 | |||||
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 46 | private: |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 47 | void OnJsonParseSuccess(std::unique_ptr<base::Value> parsed_json); |
[email protected] | 1f6a9a6 | 2013-05-22 01:53:06 | [diff] [blame] | 48 | void OnJsonParseFailure(const std::string& error); |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 49 | |
50 | // net::URLFetcherDelegate overrides: | ||||
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 51 | void OnURLFetchComplete(const net::URLFetcher* source) override; |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 52 | |
53 | WebstoreDataFetcherDelegate* delegate_; | ||||
54 | net::URLRequestContextGetter* request_context_; | ||||
55 | GURL referrer_url_; | ||||
56 | std::string id_; | ||||
57 | |||||
58 | // For fetching webstore JSON data. | ||||
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame^] | 59 | std::unique_ptr<net::URLFetcher> webstore_data_url_fetcher_; |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 60 | |
[email protected] | 270dccc | 2014-07-11 07:20:37 | [diff] [blame] | 61 | // Maximum auto retry times on server 5xx error or ERR_NETWORK_CHANGED. |
62 | // Default is 0 which means to use the URLFetcher default behavior. | ||||
63 | int max_auto_retries_; | ||||
64 | |||||
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 65 | DISALLOW_COPY_AND_ASSIGN(WebstoreDataFetcher); |
66 | }; | ||||
67 | |||||
68 | } // namespace extensions | ||||
69 | |||||
70 | #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_DATA_FETCHER_H_ |