OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file provides base classes used to issue HTTP requests for Google | 5 // This file provides base classes used to issue HTTP requests for Google |
6 // APIs. | 6 // APIs. |
7 | 7 |
8 #ifndef CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ | 8 #ifndef CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ |
9 #define CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ | 9 #define CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/files/file_path.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "chrome/browser/google_apis/gdata_errorcode.h" | 17 #include "chrome/browser/google_apis/gdata_errorcode.h" |
17 #include "chrome/browser/google_apis/request_registry.h" | 18 #include "chrome/browser/google_apis/request_registry.h" |
18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
19 #include "net/url_request/url_fetcher.h" | 20 #include "net/url_request/url_fetcher.h" |
20 #include "net/url_request/url_fetcher_delegate.h" | 21 #include "net/url_request/url_fetcher_delegate.h" |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 class Value; | 24 class Value; |
24 } // namespace base | 25 } // namespace base |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // Invoked when the authentication failed with an error code |code|. | 71 // Invoked when the authentication failed with an error code |code|. |
71 virtual void OnAuthFailed(GDataErrorCode code) = 0; | 72 virtual void OnAuthFailed(GDataErrorCode code) = 0; |
72 | 73 |
73 // Gets a weak pointer to this request object. Since requests may be | 74 // Gets a weak pointer to this request object. Since requests may be |
74 // deleted when it is canceled by user action, for posting asynchronous tasks | 75 // deleted when it is canceled by user action, for posting asynchronous tasks |
75 // on the authentication request object, weak pointers have to be used. | 76 // on the authentication request object, weak pointers have to be used. |
76 // TODO(kinaba): crbug.com/134814 use more clean life time management than | 77 // TODO(kinaba): crbug.com/134814 use more clean life time management than |
77 // using weak pointers, while deprecating RequestRegistry. | 78 // using weak pointers, while deprecating RequestRegistry. |
78 virtual base::WeakPtr<AuthenticatedRequestInterface> GetWeakPtr() = 0; | 79 virtual base::WeakPtr<AuthenticatedRequestInterface> GetWeakPtr() = 0; |
79 | 80 |
80 // TODO(kinaba): crbug.com/{164089, 231209} This is temporarily added during | 81 // Cancels the request. It will invoke the callback object passed in |
81 // migration of cancellation from RequestRegistry to JobScheduler. It should | 82 // each request's constructor with error code GDATA_CANCELLED. |
82 // go away *very soon*. | 83 virtual void Cancel() = 0; |
83 virtual RequestRegistry::Request* AsRequestRegistryRequest() = 0; | |
84 }; | 84 }; |
85 | 85 |
86 //============================ UrlFetchRequestBase =========================== | 86 //============================ UrlFetchRequestBase =========================== |
87 | 87 |
88 // Base class for requests that are fetching URLs. | 88 // Base class for requests that are fetching URLs. |
89 class UrlFetchRequestBase : public AuthenticatedRequestInterface, | 89 class UrlFetchRequestBase : public AuthenticatedRequestInterface, |
90 public RequestRegistry::Request, | 90 public RequestRegistry::Request, |
91 public net::URLFetcherDelegate { | 91 public net::URLFetcherDelegate { |
92 public: | 92 public: |
93 // AuthenticatedRequestInterface overrides. | 93 // AuthenticatedRequestInterface overrides. |
94 virtual void Start(const std::string& access_token, | 94 virtual void Start(const std::string& access_token, |
95 const std::string& custom_user_agent, | 95 const std::string& custom_user_agent, |
96 const ReAuthenticateCallback& callback) OVERRIDE; | 96 const ReAuthenticateCallback& callback) OVERRIDE; |
97 virtual base::WeakPtr<AuthenticatedRequestInterface> GetWeakPtr() OVERRIDE; | 97 virtual base::WeakPtr<AuthenticatedRequestInterface> GetWeakPtr() OVERRIDE; |
| 98 virtual void Cancel() OVERRIDE; |
98 | 99 |
99 protected: | 100 protected: |
100 UrlFetchRequestBase(RequestSender* runner, | 101 UrlFetchRequestBase(RequestSender* runner, |
101 net::URLRequestContextGetter* url_request_context_getter); | 102 net::URLRequestContextGetter* url_request_context_getter); |
102 virtual ~UrlFetchRequestBase(); | 103 virtual ~UrlFetchRequestBase(); |
103 | 104 |
104 // Gets URL for the request. | 105 // Gets URL for the request. |
105 virtual GURL GetURL() const = 0; | 106 virtual GURL GetURL() const = 0; |
106 | 107 |
107 // Returns the request type. A derived class should override this method | 108 // Returns the request type. A derived class should override this method |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 153 } |
153 | 154 |
154 // By default, no file will be saved. Derived classes can set an output | 155 // By default, no file will be saved. Derived classes can set an output |
155 // file path in their constructors, if they want to save the downloaded | 156 // file path in their constructors, if they want to save the downloaded |
156 // content to a file at a specific path. | 157 // content to a file at a specific path. |
157 void set_output_file_path(const base::FilePath& output_file_path) { | 158 void set_output_file_path(const base::FilePath& output_file_path) { |
158 output_file_path_ = output_file_path; | 159 output_file_path_ = output_file_path; |
159 } | 160 } |
160 | 161 |
161 private: | 162 private: |
162 // RequestRegistry::Request overrides. | |
163 virtual void DoCancel() OVERRIDE; | |
164 | |
165 // URLFetcherDelegate overrides. | 163 // URLFetcherDelegate overrides. |
166 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 164 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
167 | 165 |
168 // AuthenticatedRequestInterface overrides. | 166 // AuthenticatedRequestInterface overrides. |
169 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; | 167 virtual void OnAuthFailed(GDataErrorCode code) OVERRIDE; |
170 virtual RequestRegistry::Request* AsRequestRegistryRequest() OVERRIDE; | |
171 | 168 |
172 net::URLRequestContextGetter* url_request_context_getter_; | 169 net::URLRequestContextGetter* url_request_context_getter_; |
173 ReAuthenticateCallback re_authenticate_callback_; | 170 ReAuthenticateCallback re_authenticate_callback_; |
174 int re_authenticate_count_; | 171 int re_authenticate_count_; |
175 scoped_ptr<net::URLFetcher> url_fetcher_; | 172 scoped_ptr<net::URLFetcher> url_fetcher_; |
176 bool started_; | 173 bool started_; |
177 | 174 |
178 bool save_temp_file_; | 175 bool save_temp_file_; |
179 base::FilePath output_file_path_; | 176 base::FilePath output_file_path_; |
180 | 177 |
181 // WeakPtrFactory bound to the UI thread. | |
182 // Note: This should remain the last member so it'll be destroyed and | 178 // Note: This should remain the last member so it'll be destroyed and |
183 // invalidate its weak pointers before any other members are destroyed. | 179 // invalidate its weak pointers before any other members are destroyed. |
184 base::WeakPtrFactory<UrlFetchRequestBase> weak_ptr_factory_; | 180 base::WeakPtrFactory<UrlFetchRequestBase> weak_ptr_factory_; |
185 }; | 181 }; |
186 | 182 |
187 //============================ EntryActionRequest ============================ | 183 //============================ EntryActionRequest ============================ |
188 | 184 |
189 // Callback type for Delete/Move DocumentServiceInterface calls. | 185 // Callback type for Delete/Move DocumentServiceInterface calls. |
190 typedef base::Callback<void(GDataErrorCode error)> EntryActionCallback; | 186 typedef base::Callback<void(GDataErrorCode error)> EntryActionCallback; |
191 | 187 |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 const GetContentCallback get_content_callback_; | 511 const GetContentCallback get_content_callback_; |
516 const ProgressCallback progress_callback_; | 512 const ProgressCallback progress_callback_; |
517 const GURL download_url_; | 513 const GURL download_url_; |
518 | 514 |
519 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequest); | 515 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequest); |
520 }; | 516 }; |
521 | 517 |
522 } // namespace google_apis | 518 } // namespace google_apis |
523 | 519 |
524 #endif // CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ | 520 #endif // CHROME_BROWSER_GOOGLE_APIS_BASE_REQUESTS_H_ |
OLD | NEW |