blob: af46509874a8eefca74db7fe79aa8ee329f47979 [file] [log] [blame]
[email protected]7b3941052013-02-13 01:21:591// 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
dchengc963c7142016-04-08 03:55:228#include <memory>
[email protected]7b3941052013-02-13 01:21:599#include <string>
10
avia2f4804a2015-12-24 23:11:1311#include "base/macros.h"
[email protected]7b3941052013-02-13 01:21:5912#include "base/memory/weak_ptr.h"
[email protected]a6483d22013-07-03 22:11:0013#include "url/gurl.h"
[email protected]7b3941052013-02-13 01:21:5914
15namespace base {
[email protected]1f6a9a62013-05-22 01:53:0616class Value;
[email protected]7b3941052013-02-13 01:21:5917}
18
Mark Pilgrim1a72e0512018-04-25 13:48:4819namespace network {
20class SimpleURLLoader;
21namespace mojom {
22class URLLoaderFactory;
23} // namespace mojom
24} // namespace network
[email protected]7b3941052013-02-13 01:21:5925
26namespace extensions {
27
28class WebstoreDataFetcherDelegate;
29
30// WebstoreDataFetcher fetches web store data and parses it into a
31// DictionaryValue.
Mark Pilgrim1a72e0512018-04-25 13:48:4832class WebstoreDataFetcher : public base::SupportsWeakPtr<WebstoreDataFetcher> {
[email protected]7b3941052013-02-13 01:21:5933 public:
34 WebstoreDataFetcher(WebstoreDataFetcherDelegate* delegate,
[email protected]7b3941052013-02-13 01:21:5935 const GURL& referrer_url,
36 const std::string webstore_item_id);
Mark Pilgrim1a72e0512018-04-25 13:48:4837 ~WebstoreDataFetcher();
[email protected]7b3941052013-02-13 01:21:5938
Jialiu Linfc668ec12018-01-31 01:28:4439 // 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);
robertshield1fc1a4a2017-02-01 15:18:3342
Mark Pilgrim1a72e0512018-04-25 13:48:4843 void Start(network::mojom::URLLoaderFactory* url_loader_factory);
[email protected]7b3941052013-02-13 01:21:5944
[email protected]270dccc2014-07-11 07:20:3745 void set_max_auto_retries(int max_retries) {
46 max_auto_retries_ = max_retries;
47 }
48
[email protected]7b3941052013-02-13 01:21:5949 private:
dchengc963c7142016-04-08 03:55:2250 void OnJsonParseSuccess(std::unique_ptr<base::Value> parsed_json);
[email protected]1f6a9a62013-05-22 01:53:0651 void OnJsonParseFailure(const std::string& error);
Mark Pilgrim1a72e0512018-04-25 13:48:4852 void OnSimpleLoaderComplete(std::unique_ptr<std::string> response_body);
[email protected]7b3941052013-02-13 01:21:5953
54 WebstoreDataFetcherDelegate* delegate_;
[email protected]7b3941052013-02-13 01:21:5955 GURL referrer_url_;
56 std::string id_;
Jialiu Linfc668ec12018-01-31 01:28:4457 std::string post_data_;
[email protected]7b3941052013-02-13 01:21:5958
59 // For fetching webstore JSON data.
Mark Pilgrim1a72e0512018-04-25 13:48:4860 std::unique_ptr<network::SimpleURLLoader> simple_url_loader_;
[email protected]7b3941052013-02-13 01:21:5961
[email protected]270dccc2014-07-11 07:20:3762 // 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]7b3941052013-02-13 01:21:5966 DISALLOW_COPY_AND_ASSIGN(WebstoreDataFetcher);
67};
68
69} // namespace extensions
70
71#endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_DATA_FETCHER_H_