[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" |
Ken Rockot | dc32df89 | 2019-11-01 06:32:10 | [diff] [blame] | 13 | #include "services/data_decoder/public/cpp/data_decoder.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 | |
Mark Pilgrim | 1a72e051 | 2018-04-25 13:48:48 | [diff] [blame] | 16 | namespace network { |
17 | class SimpleURLLoader; | ||||
18 | namespace mojom { | ||||
19 | class URLLoaderFactory; | ||||
20 | } // namespace mojom | ||||
21 | } // namespace network | ||||
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 22 | |
23 | namespace extensions { | ||||
24 | |||||
25 | class WebstoreDataFetcherDelegate; | ||||
26 | |||||
27 | // WebstoreDataFetcher fetches web store data and parses it into a | ||||
28 | // DictionaryValue. | ||||
Mark Pilgrim | 1a72e051 | 2018-04-25 13:48:48 | [diff] [blame] | 29 | class WebstoreDataFetcher : public base::SupportsWeakPtr<WebstoreDataFetcher> { |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 30 | public: |
31 | WebstoreDataFetcher(WebstoreDataFetcherDelegate* delegate, | ||||
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 32 | const GURL& referrer_url, |
33 | const std::string webstore_item_id); | ||||
Mark Pilgrim | 1a72e051 | 2018-04-25 13:48:48 | [diff] [blame] | 34 | ~WebstoreDataFetcher(); |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 35 | |
Mark Pilgrim | 1a72e051 | 2018-04-25 13:48:48 | [diff] [blame] | 36 | void Start(network::mojom::URLLoaderFactory* url_loader_factory); |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 37 | |
[email protected] | 270dccc | 2014-07-11 07:20:37 | [diff] [blame] | 38 | void set_max_auto_retries(int max_retries) { |
39 | max_auto_retries_ = max_retries; | ||||
40 | } | ||||
41 | |||||
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 42 | private: |
Ken Rockot | dc32df89 | 2019-11-01 06:32:10 | [diff] [blame] | 43 | void OnJsonParsed(data_decoder::DataDecoder::ValueOrError result); |
Mark Pilgrim | 1a72e051 | 2018-04-25 13:48:48 | [diff] [blame] | 44 | void OnSimpleLoaderComplete(std::unique_ptr<std::string> response_body); |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 45 | |
46 | WebstoreDataFetcherDelegate* delegate_; | ||||
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 47 | GURL referrer_url_; |
48 | std::string id_; | ||||
Jialiu Lin | fc668ec1 | 2018-01-31 01:28:44 | [diff] [blame] | 49 | std::string post_data_; |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 50 | |
51 | // For fetching webstore JSON data. | ||||
Mark Pilgrim | 1a72e051 | 2018-04-25 13:48:48 | [diff] [blame] | 52 | std::unique_ptr<network::SimpleURLLoader> simple_url_loader_; |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 53 | |
[email protected] | 270dccc | 2014-07-11 07:20:37 | [diff] [blame] | 54 | // Maximum auto retry times on server 5xx error or ERR_NETWORK_CHANGED. |
55 | // Default is 0 which means to use the URLFetcher default behavior. | ||||
56 | int max_auto_retries_; | ||||
57 | |||||
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 58 | DISALLOW_COPY_AND_ASSIGN(WebstoreDataFetcher); |
59 | }; | ||||
60 | |||||
61 | } // namespace extensions | ||||
62 | |||||
63 | #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_DATA_FETCHER_H_ |