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

Side by Side Diff: google_apis/drive/base_requests.h

Issue 649283003: Standardize usage of virtual/override/final in google_apis/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « google_apis/drive/auth_service.cc ('k') | google_apis/drive/base_requests_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ 8 #ifndef GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_
9 #define GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ 9 #define GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_
10 10
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 //=========================== ResponseWriter ================================== 82 //=========================== ResponseWriter ==================================
83 83
84 // Saves the response for the request to a file or string. 84 // Saves the response for the request to a file or string.
85 class ResponseWriter : public net::URLFetcherResponseWriter { 85 class ResponseWriter : public net::URLFetcherResponseWriter {
86 public: 86 public:
87 // If file_path is not empty, the response will be saved with file_writer_, 87 // If file_path is not empty, the response will be saved with file_writer_,
88 // otherwise it will be saved to data_. 88 // otherwise it will be saved to data_.
89 ResponseWriter(base::SequencedTaskRunner* file_task_runner, 89 ResponseWriter(base::SequencedTaskRunner* file_task_runner,
90 const base::FilePath& file_path, 90 const base::FilePath& file_path,
91 const GetContentCallback& get_content_callback); 91 const GetContentCallback& get_content_callback);
92 virtual ~ResponseWriter(); 92 ~ResponseWriter() override;
93 93
94 const std::string& data() const { return data_; } 94 const std::string& data() const { return data_; }
95 95
96 // Disowns the output file. 96 // Disowns the output file.
97 void DisownFile(); 97 void DisownFile();
98 98
99 // URLFetcherResponseWriter overrides: 99 // URLFetcherResponseWriter overrides:
100 virtual int Initialize(const net::CompletionCallback& callback) override; 100 int Initialize(const net::CompletionCallback& callback) override;
101 virtual int Write(net::IOBuffer* buffer, 101 int Write(net::IOBuffer* buffer,
102 int num_bytes, 102 int num_bytes,
103 const net::CompletionCallback& callback) override; 103 const net::CompletionCallback& callback) override;
104 virtual int Finish(const net::CompletionCallback& callback) override; 104 int Finish(const net::CompletionCallback& callback) override;
105 105
106 private: 106 private:
107 void DidWrite(scoped_refptr<net::IOBuffer> buffer, 107 void DidWrite(scoped_refptr<net::IOBuffer> buffer,
108 const net::CompletionCallback& callback, 108 const net::CompletionCallback& callback,
109 int result); 109 int result);
110 110
111 const GetContentCallback get_content_callback_; 111 const GetContentCallback get_content_callback_;
112 std::string data_; 112 std::string data_;
113 scoped_ptr<net::URLFetcherFileWriter> file_writer_; 113 scoped_ptr<net::URLFetcherFileWriter> file_writer_;
114 base::WeakPtrFactory<ResponseWriter> weak_ptr_factory_; 114 base::WeakPtrFactory<ResponseWriter> weak_ptr_factory_;
115 115
116 DISALLOW_COPY_AND_ASSIGN(ResponseWriter); 116 DISALLOW_COPY_AND_ASSIGN(ResponseWriter);
117 }; 117 };
118 118
119 //============================ UrlFetchRequestBase =========================== 119 //============================ UrlFetchRequestBase ===========================
120 120
121 // Base class for requests that are fetching URLs. 121 // Base class for requests that are fetching URLs.
122 class UrlFetchRequestBase : public AuthenticatedRequestInterface, 122 class UrlFetchRequestBase : public AuthenticatedRequestInterface,
123 public net::URLFetcherDelegate { 123 public net::URLFetcherDelegate {
124 public: 124 public:
125 // AuthenticatedRequestInterface overrides. 125 // AuthenticatedRequestInterface overrides.
126 virtual void Start(const std::string& access_token, 126 void Start(const std::string& access_token,
127 const std::string& custom_user_agent, 127 const std::string& custom_user_agent,
128 const ReAuthenticateCallback& callback) override; 128 const ReAuthenticateCallback& callback) override;
129 virtual base::WeakPtr<AuthenticatedRequestInterface> GetWeakPtr() override; 129 base::WeakPtr<AuthenticatedRequestInterface> GetWeakPtr() override;
130 virtual void Cancel() override; 130 void Cancel() override;
131 131
132 protected: 132 protected:
133 explicit UrlFetchRequestBase(RequestSender* sender); 133 explicit UrlFetchRequestBase(RequestSender* sender);
134 virtual ~UrlFetchRequestBase(); 134 ~UrlFetchRequestBase() override;
135 135
136 // Gets URL for the request. 136 // Gets URL for the request.
137 virtual GURL GetURL() const = 0; 137 virtual GURL GetURL() const = 0;
138 138
139 // Returns the request type. A derived class should override this method 139 // Returns the request type. A derived class should override this method
140 // for a request type other than HTTP GET. 140 // for a request type other than HTTP GET.
141 virtual net::URLFetcher::RequestType GetRequestType() const; 141 virtual net::URLFetcher::RequestType GetRequestType() const;
142 142
143 // Returns the extra HTTP headers for the request. A derived class should 143 // Returns the extra HTTP headers for the request. A derived class should
144 // override this method to specify any extra headers needed for the request. 144 // override this method to specify any extra headers needed for the request.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 bool CalledOnValidThread(); 187 bool CalledOnValidThread();
188 188
189 // Returns the writer which is used to save the response for the request. 189 // Returns the writer which is used to save the response for the request.
190 ResponseWriter* response_writer() const { return response_writer_; } 190 ResponseWriter* response_writer() const { return response_writer_; }
191 191
192 // Returns the task runner that should be used for blocking tasks. 192 // Returns the task runner that should be used for blocking tasks.
193 base::SequencedTaskRunner* blocking_task_runner() const; 193 base::SequencedTaskRunner* blocking_task_runner() const;
194 194
195 private: 195 private:
196 // URLFetcherDelegate overrides. 196 // URLFetcherDelegate overrides.
197 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; 197 void OnURLFetchComplete(const net::URLFetcher* source) override;
198 198
199 // AuthenticatedRequestInterface overrides. 199 // AuthenticatedRequestInterface overrides.
200 virtual void OnAuthFailed(GDataErrorCode code) override; 200 void OnAuthFailed(GDataErrorCode code) override;
201 201
202 ReAuthenticateCallback re_authenticate_callback_; 202 ReAuthenticateCallback re_authenticate_callback_;
203 int re_authenticate_count_; 203 int re_authenticate_count_;
204 scoped_ptr<net::URLFetcher> url_fetcher_; 204 scoped_ptr<net::URLFetcher> url_fetcher_;
205 ResponseWriter* response_writer_; // Owned by |url_fetcher_|. 205 ResponseWriter* response_writer_; // Owned by |url_fetcher_|.
206 RequestSender* sender_; 206 RequestSender* sender_;
207 GDataErrorCode error_code_; 207 GDataErrorCode error_code_;
208 208
209 base::ThreadChecker thread_checker_; 209 base::ThreadChecker thread_checker_;
210 210
(...skipping 10 matching lines...) Expand all
221 typedef base::Callback<void(GDataErrorCode error)> EntryActionCallback; 221 typedef base::Callback<void(GDataErrorCode error)> EntryActionCallback;
222 222
223 // This class performs a simple action over a given entry (document/file). 223 // This class performs a simple action over a given entry (document/file).
224 // It is meant to be used for requests that return no JSON blobs. 224 // It is meant to be used for requests that return no JSON blobs.
225 class EntryActionRequest : public UrlFetchRequestBase { 225 class EntryActionRequest : public UrlFetchRequestBase {
226 public: 226 public:
227 // |callback| is called when the request is finished either by success or by 227 // |callback| is called when the request is finished either by success or by
228 // failure. It must not be null. 228 // failure. It must not be null.
229 EntryActionRequest(RequestSender* sender, 229 EntryActionRequest(RequestSender* sender,
230 const EntryActionCallback& callback); 230 const EntryActionCallback& callback);
231 virtual ~EntryActionRequest(); 231 ~EntryActionRequest() override;
232 232
233 protected: 233 protected:
234 // Overridden from UrlFetchRequestBase. 234 // Overridden from UrlFetchRequestBase.
235 virtual void ProcessURLFetchResults(const net::URLFetcher* source) override; 235 void ProcessURLFetchResults(const net::URLFetcher* source) override;
236 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) override; 236 void RunCallbackOnPrematureFailure(GDataErrorCode code) override;
237 237
238 private: 238 private:
239 const EntryActionCallback callback_; 239 const EntryActionCallback callback_;
240 240
241 DISALLOW_COPY_AND_ASSIGN(EntryActionRequest); 241 DISALLOW_COPY_AND_ASSIGN(EntryActionRequest);
242 }; 242 };
243 243
244 //=========================== InitiateUploadRequestBase======================= 244 //=========================== InitiateUploadRequestBase=======================
245 245
246 // Callback type for DriveServiceInterface::InitiateUpload. 246 // Callback type for DriveServiceInterface::InitiateUpload.
(...skipping 14 matching lines...) Expand all
261 class InitiateUploadRequestBase : public UrlFetchRequestBase { 261 class InitiateUploadRequestBase : public UrlFetchRequestBase {
262 protected: 262 protected:
263 // |callback| will be called with the upload URL, where upload data is 263 // |callback| will be called with the upload URL, where upload data is
264 // uploaded to with ResumeUploadRequestBase. It must not be null. 264 // uploaded to with ResumeUploadRequestBase. It must not be null.
265 // |content_type| and |content_length| should be the attributes of the 265 // |content_type| and |content_length| should be the attributes of the
266 // uploading file. 266 // uploading file.
267 InitiateUploadRequestBase(RequestSender* sender, 267 InitiateUploadRequestBase(RequestSender* sender,
268 const InitiateUploadCallback& callback, 268 const InitiateUploadCallback& callback,
269 const std::string& content_type, 269 const std::string& content_type,
270 int64 content_length); 270 int64 content_length);
271 virtual ~InitiateUploadRequestBase(); 271 ~InitiateUploadRequestBase() override;
272 272
273 // UrlFetchRequestBase overrides. 273 // UrlFetchRequestBase overrides.
274 virtual void ProcessURLFetchResults(const net::URLFetcher* source) override; 274 void ProcessURLFetchResults(const net::URLFetcher* source) override;
275 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) override; 275 void RunCallbackOnPrematureFailure(GDataErrorCode code) override;
276 virtual std::vector<std::string> GetExtraRequestHeaders() const override; 276 std::vector<std::string> GetExtraRequestHeaders() const override;
277 277
278 private: 278 private:
279 const InitiateUploadCallback callback_; 279 const InitiateUploadCallback callback_;
280 const std::string content_type_; 280 const std::string content_type_;
281 const int64 content_length_; 281 const int64 content_length_;
282 282
283 DISALLOW_COPY_AND_ASSIGN(InitiateUploadRequestBase); 283 DISALLOW_COPY_AND_ASSIGN(InitiateUploadRequestBase);
284 }; 284 };
285 285
286 //========================== UploadRangeRequestBase ========================== 286 //========================== UploadRangeRequestBase ==========================
(...skipping 17 matching lines...) Expand all
304 int64 end_position_received; 304 int64 end_position_received;
305 }; 305 };
306 306
307 // Base class for a URL fetch request expecting the response containing the 307 // Base class for a URL fetch request expecting the response containing the
308 // current uploading range. This class processes the response containing 308 // current uploading range. This class processes the response containing
309 // "Range" header and invoke OnRangeRequestComplete. 309 // "Range" header and invoke OnRangeRequestComplete.
310 class UploadRangeRequestBase : public UrlFetchRequestBase { 310 class UploadRangeRequestBase : public UrlFetchRequestBase {
311 protected: 311 protected:
312 // |upload_url| is the URL of where to upload the file to. 312 // |upload_url| is the URL of where to upload the file to.
313 UploadRangeRequestBase(RequestSender* sender, const GURL& upload_url); 313 UploadRangeRequestBase(RequestSender* sender, const GURL& upload_url);
314 virtual ~UploadRangeRequestBase(); 314 ~UploadRangeRequestBase() override;
315 315
316 // UrlFetchRequestBase overrides. 316 // UrlFetchRequestBase overrides.
317 virtual GURL GetURL() const override; 317 GURL GetURL() const override;
318 virtual net::URLFetcher::RequestType GetRequestType() const override; 318 net::URLFetcher::RequestType GetRequestType() const override;
319 virtual void ProcessURLFetchResults(const net::URLFetcher* source) override; 319 void ProcessURLFetchResults(const net::URLFetcher* source) override;
320 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) override; 320 void RunCallbackOnPrematureFailure(GDataErrorCode code) override;
321 321
322 // This method will be called when the request is done, regardless of 322 // This method will be called when the request is done, regardless of
323 // whether it is succeeded or failed. 323 // whether it is succeeded or failed.
324 // 324 //
325 // 1) If there is more data to upload, |code| of |response| is set to 325 // 1) If there is more data to upload, |code| of |response| is set to
326 // HTTP_RESUME_INCOMPLETE, and positions are set appropriately. Also, |value| 326 // HTTP_RESUME_INCOMPLETE, and positions are set appropriately. Also, |value|
327 // will be set to NULL. 327 // will be set to NULL.
328 // 2) If the upload is complete, |code| is set to HTTP_CREATED for a new file 328 // 2) If the upload is complete, |code| is set to HTTP_CREATED for a new file
329 // or HTTP_SUCCESS for an existing file. Positions are set to -1, and |value| 329 // or HTTP_SUCCESS for an existing file. Positions are set to -1, and |value|
330 // is set to a parsed JSON value representing the uploaded file. 330 // is set to a parsed JSON value representing the uploaded file.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // |buf| holds current content to be uploaded. 371 // |buf| holds current content to be uploaded.
372 // See also UploadRangeRequestBase's comment for remaining parameters 372 // See also UploadRangeRequestBase's comment for remaining parameters
373 // meaning. 373 // meaning.
374 ResumeUploadRequestBase(RequestSender* sender, 374 ResumeUploadRequestBase(RequestSender* sender,
375 const GURL& upload_location, 375 const GURL& upload_location,
376 int64 start_position, 376 int64 start_position,
377 int64 end_position, 377 int64 end_position,
378 int64 content_length, 378 int64 content_length,
379 const std::string& content_type, 379 const std::string& content_type,
380 const base::FilePath& local_file_path); 380 const base::FilePath& local_file_path);
381 virtual ~ResumeUploadRequestBase(); 381 ~ResumeUploadRequestBase() override;
382 382
383 // UrlFetchRequestBase overrides. 383 // UrlFetchRequestBase overrides.
384 virtual std::vector<std::string> GetExtraRequestHeaders() const override; 384 std::vector<std::string> GetExtraRequestHeaders() const override;
385 virtual bool GetContentFile(base::FilePath* local_file_path, 385 bool GetContentFile(base::FilePath* local_file_path,
386 int64* range_offset, 386 int64* range_offset,
387 int64* range_length, 387 int64* range_length,
388 std::string* upload_content_type) override; 388 std::string* upload_content_type) override;
389 389
390 private: 390 private:
391 // The parameters for the request. See ResumeUploadParams for the details. 391 // The parameters for the request. See ResumeUploadParams for the details.
392 const int64 start_position_; 392 const int64 start_position_;
393 const int64 end_position_; 393 const int64 end_position_;
394 const int64 content_length_; 394 const int64 content_length_;
395 const std::string content_type_; 395 const std::string content_type_;
396 const base::FilePath local_file_path_; 396 const base::FilePath local_file_path_;
397 397
398 DISALLOW_COPY_AND_ASSIGN(ResumeUploadRequestBase); 398 DISALLOW_COPY_AND_ASSIGN(ResumeUploadRequestBase);
(...skipping 10 matching lines...) Expand all
409 // for the uploaded data, if a file has been completely uploaded. 409 // for the uploaded data, if a file has been completely uploaded.
410 // See also UploadRangeRequestBase. 410 // See also UploadRangeRequestBase.
411 class GetUploadStatusRequestBase : public UploadRangeRequestBase { 411 class GetUploadStatusRequestBase : public UploadRangeRequestBase {
412 public: 412 public:
413 // |content_length| is the whole data size to be uploaded. 413 // |content_length| is the whole data size to be uploaded.
414 // See also UploadRangeRequestBase's constructor comment for other 414 // See also UploadRangeRequestBase's constructor comment for other
415 // parameters. 415 // parameters.
416 GetUploadStatusRequestBase(RequestSender* sender, 416 GetUploadStatusRequestBase(RequestSender* sender,
417 const GURL& upload_url, 417 const GURL& upload_url,
418 int64 content_length); 418 int64 content_length);
419 virtual ~GetUploadStatusRequestBase(); 419 ~GetUploadStatusRequestBase() override;
420 420
421 protected: 421 protected:
422 // UrlFetchRequestBase overrides. 422 // UrlFetchRequestBase overrides.
423 virtual std::vector<std::string> GetExtraRequestHeaders() const override; 423 std::vector<std::string> GetExtraRequestHeaders() const override;
424 424
425 private: 425 private:
426 const int64 content_length_; 426 const int64 content_length_;
427 427
428 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequestBase); 428 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusRequestBase);
429 }; 429 };
430 430
431 //============================ DownloadFileRequest =========================== 431 //============================ DownloadFileRequest ===========================
432 432
433 // Callback type for receiving the completion of DownloadFileRequest. 433 // Callback type for receiving the completion of DownloadFileRequest.
(...skipping 21 matching lines...) Expand all
455 // output_file_path: 455 // output_file_path:
456 // Specifies the file path to save the downloaded file. 456 // Specifies the file path to save the downloaded file.
457 // 457 //
458 DownloadFileRequestBase( 458 DownloadFileRequestBase(
459 RequestSender* sender, 459 RequestSender* sender,
460 const DownloadActionCallback& download_action_callback, 460 const DownloadActionCallback& download_action_callback,
461 const GetContentCallback& get_content_callback, 461 const GetContentCallback& get_content_callback,
462 const ProgressCallback& progress_callback, 462 const ProgressCallback& progress_callback,
463 const GURL& download_url, 463 const GURL& download_url,
464 const base::FilePath& output_file_path); 464 const base::FilePath& output_file_path);
465 virtual ~DownloadFileRequestBase(); 465 ~DownloadFileRequestBase() override;
466 466
467 protected: 467 protected:
468 // UrlFetchRequestBase overrides. 468 // UrlFetchRequestBase overrides.
469 virtual GURL GetURL() const override; 469 GURL GetURL() const override;
470 virtual void GetOutputFilePath( 470 void GetOutputFilePath(base::FilePath* local_file_path,
471 base::FilePath* local_file_path, 471 GetContentCallback* get_content_callback) override;
472 GetContentCallback* get_content_callback) override; 472 void ProcessURLFetchResults(const net::URLFetcher* source) override;
473 virtual void ProcessURLFetchResults(const net::URLFetcher* source) override; 473 void RunCallbackOnPrematureFailure(GDataErrorCode code) override;
474 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) override;
475 474
476 // net::URLFetcherDelegate overrides. 475 // net::URLFetcherDelegate overrides.
477 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, 476 void OnURLFetchDownloadProgress(const net::URLFetcher* source,
478 int64 current, int64 total) override; 477 int64 current,
478 int64 total) override;
479 479
480 private: 480 private:
481 const DownloadActionCallback download_action_callback_; 481 const DownloadActionCallback download_action_callback_;
482 const GetContentCallback get_content_callback_; 482 const GetContentCallback get_content_callback_;
483 const ProgressCallback progress_callback_; 483 const ProgressCallback progress_callback_;
484 const GURL download_url_; 484 const GURL download_url_;
485 const base::FilePath output_file_path_; 485 const base::FilePath output_file_path_;
486 486
487 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase); 487 DISALLOW_COPY_AND_ASSIGN(DownloadFileRequestBase);
488 }; 488 };
489 489
490 } // namespace google_apis 490 } // namespace google_apis
491 491
492 #endif // GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_ 492 #endif // GOOGLE_APIS_DRIVE_BASE_REQUESTS_H_
OLDNEW
« no previous file with comments | « google_apis/drive/auth_service.cc ('k') | google_apis/drive/base_requests_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698