[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] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame] | 13 | #include "url/gurl.h" |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 14 | |
15 | namespace base { | ||||
[email protected] | 1f6a9a6 | 2013-05-22 01:53:06 | [diff] [blame] | 16 | class Value; |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 17 | } |
18 | |||||
Mark Pilgrim | 1a72e051 | 2018-04-25 13:48:48 | [diff] [blame] | 19 | namespace network { |
20 | class SimpleURLLoader; | ||||
21 | namespace mojom { | ||||
22 | class URLLoaderFactory; | ||||
23 | } // namespace mojom | ||||
24 | } // namespace network | ||||
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 25 | |
26 | namespace extensions { | ||||
27 | |||||
28 | class WebstoreDataFetcherDelegate; | ||||
29 | |||||
30 | // WebstoreDataFetcher fetches web store data and parses it into a | ||||
31 | // DictionaryValue. | ||||
Mark Pilgrim | 1a72e051 | 2018-04-25 13:48:48 | [diff] [blame] | 32 | class WebstoreDataFetcher : public base::SupportsWeakPtr<WebstoreDataFetcher> { |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 33 | public: |
34 | WebstoreDataFetcher(WebstoreDataFetcherDelegate* delegate, | ||||
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 35 | const GURL& referrer_url, |
36 | const std::string webstore_item_id); | ||||
Mark Pilgrim | 1a72e051 | 2018-04-25 13:48:48 | [diff] [blame] | 37 | ~WebstoreDataFetcher(); |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 38 | |
Jialiu Lin | fc668ec1 | 2018-01-31 01:28:44 | [diff] [blame] | 39 | // Makes this request use a POST instead of GET, and sends |data| in the |
40 | // body of the request. If |data| is empty, this is a no-op. | ||||
41 | void SetPostData(const std::string& data); | ||||
robertshield | 1fc1a4a | 2017-02-01 15:18:33 | [diff] [blame] | 42 | |
Mark Pilgrim | 1a72e051 | 2018-04-25 13:48:48 | [diff] [blame] | 43 | void Start(network::mojom::URLLoaderFactory* url_loader_factory); |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 44 | |
[email protected] | 270dccc | 2014-07-11 07:20:37 | [diff] [blame] | 45 | void set_max_auto_retries(int max_retries) { |
46 | max_auto_retries_ = max_retries; | ||||
47 | } | ||||
48 | |||||
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 49 | private: |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 50 | void OnJsonParseSuccess(std::unique_ptr<base::Value> parsed_json); |
[email protected] | 1f6a9a6 | 2013-05-22 01:53:06 | [diff] [blame] | 51 | void OnJsonParseFailure(const std::string& error); |
Mark Pilgrim | 1a72e051 | 2018-04-25 13:48:48 | [diff] [blame] | 52 | void OnSimpleLoaderComplete(std::unique_ptr<std::string> response_body); |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 53 | |
54 | WebstoreDataFetcherDelegate* delegate_; | ||||
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 55 | GURL referrer_url_; |
56 | std::string id_; | ||||
Jialiu Lin | fc668ec1 | 2018-01-31 01:28:44 | [diff] [blame] | 57 | std::string post_data_; |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 58 | |
59 | // For fetching webstore JSON data. | ||||
Mark Pilgrim | 1a72e051 | 2018-04-25 13:48:48 | [diff] [blame] | 60 | std::unique_ptr<network::SimpleURLLoader> simple_url_loader_; |
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 61 | |
[email protected] | 270dccc | 2014-07-11 07:20:37 | [diff] [blame] | 62 | // Maximum auto retry times on server 5xx error or ERR_NETWORK_CHANGED. |
63 | // Default is 0 which means to use the URLFetcher default behavior. | ||||
64 | int max_auto_retries_; | ||||
65 | |||||
[email protected] | 7b394105 | 2013-02-13 01:21:59 | [diff] [blame] | 66 | DISALLOW_COPY_AND_ASSIGN(WebstoreDataFetcher); |
67 | }; | ||||
68 | |||||
69 | } // namespace extensions | ||||
70 | |||||
71 | #endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_DATA_FETCHER_H_ |