blob: bcb48a5cbd217061b8face84d7ba8c2e0929497b [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]7b3941052013-02-13 01:21:5913#include "net/url_request/url_fetcher_delegate.h"
[email protected]a6483d22013-07-03 22:11:0014#include "url/gurl.h"
[email protected]7b3941052013-02-13 01:21:5915
16namespace base {
[email protected]1f6a9a62013-05-22 01:53:0617class Value;
[email protected]7b3941052013-02-13 01:21:5918}
19
20namespace net {
21class URLFetcher;
22class URLRequestContextGetter;
23}
24
25namespace extensions {
26
27class WebstoreDataFetcherDelegate;
28
29// WebstoreDataFetcher fetches web store data and parses it into a
30// DictionaryValue.
31class 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);
dchengae36a4a2014-10-21 12:36:3638 ~WebstoreDataFetcher() override;
[email protected]7b3941052013-02-13 01:21:5939
40 void Start();
41
[email protected]270dccc2014-07-11 07:20:3742 void set_max_auto_retries(int max_retries) {
43 max_auto_retries_ = max_retries;
44 }
45
[email protected]7b3941052013-02-13 01:21:5946 private:
dchengc963c7142016-04-08 03:55:2247 void OnJsonParseSuccess(std::unique_ptr<base::Value> parsed_json);
[email protected]1f6a9a62013-05-22 01:53:0648 void OnJsonParseFailure(const std::string& error);
[email protected]7b3941052013-02-13 01:21:5949
50 // net::URLFetcherDelegate overrides:
dchengae36a4a2014-10-21 12:36:3651 void OnURLFetchComplete(const net::URLFetcher* source) override;
[email protected]7b3941052013-02-13 01:21:5952
53 WebstoreDataFetcherDelegate* delegate_;
54 net::URLRequestContextGetter* request_context_;
55 GURL referrer_url_;
56 std::string id_;
57
58 // For fetching webstore JSON data.
dchengc963c7142016-04-08 03:55:2259 std::unique_ptr<net::URLFetcher> webstore_data_url_fetcher_;
[email protected]7b3941052013-02-13 01:21:5960
[email protected]270dccc2014-07-11 07:20:3761 // 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]7b3941052013-02-13 01:21:5965 DISALLOW_COPY_AND_ASSIGN(WebstoreDataFetcher);
66};
67
68} // namespace extensions
69
70#endif // CHROME_BROWSER_EXTENSIONS_WEBSTORE_DATA_FETCHER_H_