Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: components/offline_pages/core/prefetch/prefetch_request_fetcher.h

Issue 2921783002: [Offline Prefetch] Pass api key to offline prefetch requests (Closed)
Patch Set: Rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_REQUEST_FETCHER_H_ 5 #ifndef COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_REQUEST_FETCHER_H_
6 #define COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_REQUEST_FETCHER_H_ 6 #define COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_REQUEST_FETCHER_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "components/offline_pages/core/prefetch/prefetch_types.h" 11 #include "components/offline_pages/core/prefetch/prefetch_types.h"
12 #include "components/version_info/channel.h"
12 #include "net/url_request/url_fetcher_delegate.h" 13 #include "net/url_request/url_fetcher_delegate.h"
13 14
14 namespace net { 15 namespace net {
15 class URLRequestContextGetter; 16 class URLRequestContextGetter;
16 } 17 }
17 18
18 namespace offline_pages { 19 namespace offline_pages {
19 20
20 // Asynchronously fetches the offline prefetch related data from the server. 21 // Asynchronously fetches the offline prefetch related data from the server.
21 class PrefetchRequestFetcher : public net::URLFetcherDelegate { 22 class PrefetchRequestFetcher : public net::URLFetcherDelegate {
22 public: 23 public:
23 using FinishedCallback = base::Callback<void(PrefetchRequestStatus status, 24 using FinishedCallback = base::Callback<void(PrefetchRequestStatus status,
24 const std::string& data)>; 25 const std::string& data)>;
25 26
26 // Creates a fetcher that will sends a GET request to the server. 27 // Creates a fetcher that will sends a GET request to the server.
27 static std::unique_ptr<PrefetchRequestFetcher> CreateForGet( 28 static std::unique_ptr<PrefetchRequestFetcher> CreateForGet(
28 const std::string& url_path, 29 const std::string& url_path,
30 version_info::Channel channel,
29 net::URLRequestContextGetter* request_context_getter, 31 net::URLRequestContextGetter* request_context_getter,
30 const FinishedCallback& callback); 32 const FinishedCallback& callback);
31 33
32 // Creates a fetcher that will sends a POST request to the server. 34 // Creates a fetcher that will sends a POST request to the server.
33 static std::unique_ptr<PrefetchRequestFetcher> CreateForPost( 35 static std::unique_ptr<PrefetchRequestFetcher> CreateForPost(
34 const std::string& url_path, 36 const std::string& url_path,
35 const std::string& message, 37 const std::string& message,
38 version_info::Channel channel,
36 net::URLRequestContextGetter* request_context_getter, 39 net::URLRequestContextGetter* request_context_getter,
37 const FinishedCallback& callback); 40 const FinishedCallback& callback);
38 41
39 ~PrefetchRequestFetcher() override; 42 ~PrefetchRequestFetcher() override;
40 43
41 // URLFetcherDelegate implementation. 44 // URLFetcherDelegate implementation.
42 void OnURLFetchComplete(const net::URLFetcher* source) override; 45 void OnURLFetchComplete(const net::URLFetcher* source) override;
43 46
44 private: 47 private:
45 // If |message| is empty, the GET request is sent. Otherwise, the POST request 48 // If |message| is empty, the GET request is sent. Otherwise, the POST request
46 // is sent with |message| as post data. 49 // is sent with |message| as post data.
47 PrefetchRequestFetcher(const std::string& url_path, 50 PrefetchRequestFetcher(const std::string& url_path,
48 const std::string& message, 51 const std::string& message,
52 version_info::Channel channel,
49 net::URLRequestContextGetter* request_context_getter, 53 net::URLRequestContextGetter* request_context_getter,
50 const FinishedCallback& callback); 54 const FinishedCallback& callback);
51 55
52 PrefetchRequestStatus ParseResponse(const net::URLFetcher* source, 56 PrefetchRequestStatus ParseResponse(const net::URLFetcher* source,
53 std::string* data); 57 std::string* data);
54 58
55 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 59 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
56 std::unique_ptr<net::URLFetcher> url_fetcher_; 60 std::unique_ptr<net::URLFetcher> url_fetcher_;
57 FinishedCallback callback_; 61 FinishedCallback callback_;
58 62
59 DISALLOW_COPY_AND_ASSIGN(PrefetchRequestFetcher); 63 DISALLOW_COPY_AND_ASSIGN(PrefetchRequestFetcher);
60 }; 64 };
61 65
62 } // namespace offline_pages 66 } // namespace offline_pages
63 67
64 #endif // COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_REQUEST_FETCHER_H_ 68 #endif // COMPONENTS_OFFLINE_PAGES_CORE_PREFETCH_PREFETCH_REQUEST_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698