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

Side by Side Diff: chrome/browser/google_apis/base_operations.cc

Issue 15333013: Replace most of the occurrence of OperationRegistry with OperationRunner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
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 #include "chrome/browser/google_apis/base_operations.h" 5 #include "chrome/browser/google_apis/base_operations.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
11 #include "base/threading/sequenced_worker_pool.h" 11 #include "base/threading/sequenced_worker_pool.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/google_apis/operation_runner.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "net/base/load_flags.h" 15 #include "net/base/load_flags.h"
15 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
16 #include "net/http/http_byte_range.h" 17 #include "net/http/http_byte_range.h"
17 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
18 #include "net/http/http_util.h" 19 #include "net/http/http_util.h"
19 #include "net/url_request/url_fetcher.h" 20 #include "net/url_request/url_fetcher.h"
20 #include "net/url_request/url_request_status.h" 21 #include "net/url_request/url_request_status.h"
21 22
22 using content::BrowserThread; 23 using content::BrowserThread;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 base::PostTaskAndReplyWithResult( 86 base::PostTaskAndReplyWithResult(
86 BrowserThread::GetBlockingPool(), 87 BrowserThread::GetBlockingPool(),
87 FROM_HERE, 88 FROM_HERE,
88 base::Bind(&ParseJsonOnBlockingPool, json), 89 base::Bind(&ParseJsonOnBlockingPool, json),
89 callback); 90 callback);
90 } 91 }
91 92
92 //============================ UrlFetchOperationBase =========================== 93 //============================ UrlFetchOperationBase ===========================
93 94
94 UrlFetchOperationBase::UrlFetchOperationBase( 95 UrlFetchOperationBase::UrlFetchOperationBase(
95 OperationRegistry* registry, 96 OperationRunner* runner,
96 net::URLRequestContextGetter* url_request_context_getter) 97 net::URLRequestContextGetter* url_request_context_getter)
97 : OperationRegistry::Operation(registry), 98 : OperationRegistry::Operation(runner->operation_registry()),
98 url_request_context_getter_(url_request_context_getter), 99 url_request_context_getter_(url_request_context_getter),
99 re_authenticate_count_(0), 100 re_authenticate_count_(0),
100 started_(false), 101 started_(false),
101 save_temp_file_(false), 102 save_temp_file_(false),
102 weak_ptr_factory_(this) { 103 weak_ptr_factory_(this) {
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
104 } 105 }
105 106
106 UrlFetchOperationBase::UrlFetchOperationBase( 107 UrlFetchOperationBase::UrlFetchOperationBase(
107 OperationRegistry* registry, 108 OperationRunner* runner,
108 net::URLRequestContextGetter* url_request_context_getter, 109 net::URLRequestContextGetter* url_request_context_getter,
109 const base::FilePath& path) 110 const base::FilePath& path)
110 : OperationRegistry::Operation(registry, path), 111 : OperationRegistry::Operation(runner->operation_registry(), path),
111 url_request_context_getter_(url_request_context_getter), 112 url_request_context_getter_(url_request_context_getter),
112 re_authenticate_count_(0), 113 re_authenticate_count_(0),
113 started_(false), 114 started_(false),
114 save_temp_file_(false), 115 save_temp_file_(false),
115 weak_ptr_factory_(this) { 116 weak_ptr_factory_(this) {
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
117 } 118 }
118 119
119 UrlFetchOperationBase::~UrlFetchOperationBase() {} 120 UrlFetchOperationBase::~UrlFetchOperationBase() {}
120 121
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 } 302 }
302 303
303 base::WeakPtr<AuthenticatedOperationInterface> 304 base::WeakPtr<AuthenticatedOperationInterface>
304 UrlFetchOperationBase::GetWeakPtr() { 305 UrlFetchOperationBase::GetWeakPtr() {
305 return weak_ptr_factory_.GetWeakPtr(); 306 return weak_ptr_factory_.GetWeakPtr();
306 } 307 }
307 308
308 //============================ EntryActionOperation ============================ 309 //============================ EntryActionOperation ============================
309 310
310 EntryActionOperation::EntryActionOperation( 311 EntryActionOperation::EntryActionOperation(
311 OperationRegistry* registry, 312 OperationRunner* runner,
312 net::URLRequestContextGetter* url_request_context_getter, 313 net::URLRequestContextGetter* url_request_context_getter,
313 const EntryActionCallback& callback) 314 const EntryActionCallback& callback)
314 : UrlFetchOperationBase(registry, url_request_context_getter), 315 : UrlFetchOperationBase(runner, url_request_context_getter),
315 callback_(callback) { 316 callback_(callback) {
316 DCHECK(!callback_.is_null()); 317 DCHECK(!callback_.is_null());
317 } 318 }
318 319
319 EntryActionOperation::~EntryActionOperation() {} 320 EntryActionOperation::~EntryActionOperation() {}
320 321
321 void EntryActionOperation::ProcessURLFetchResults(const URLFetcher* source) { 322 void EntryActionOperation::ProcessURLFetchResults(const URLFetcher* source) {
322 GDataErrorCode code = GetErrorCode(source); 323 GDataErrorCode code = GetErrorCode(source);
323 callback_.Run(code); 324 callback_.Run(code);
324 const bool success = true; 325 const bool success = true;
325 OnProcessURLFetchResultsComplete(success); 326 OnProcessURLFetchResultsComplete(success);
326 } 327 }
327 328
328 void EntryActionOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { 329 void EntryActionOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) {
329 callback_.Run(code); 330 callback_.Run(code);
330 } 331 }
331 332
332 //============================== GetDataOperation ============================== 333 //============================== GetDataOperation ==============================
333 334
334 GetDataOperation::GetDataOperation( 335 GetDataOperation::GetDataOperation(
335 OperationRegistry* registry, 336 OperationRunner* runner,
336 net::URLRequestContextGetter* url_request_context_getter, 337 net::URLRequestContextGetter* url_request_context_getter,
337 const GetDataCallback& callback) 338 const GetDataCallback& callback)
338 : UrlFetchOperationBase(registry, url_request_context_getter), 339 : UrlFetchOperationBase(runner, url_request_context_getter),
339 callback_(callback), 340 callback_(callback),
340 weak_ptr_factory_(this) { 341 weak_ptr_factory_(this) {
341 DCHECK(!callback_.is_null()); 342 DCHECK(!callback_.is_null());
342 } 343 }
343 344
344 GetDataOperation::~GetDataOperation() {} 345 GetDataOperation::~GetDataOperation() {}
345 346
346 void GetDataOperation::ParseResponse(GDataErrorCode fetch_error_code, 347 void GetDataOperation::ParseResponse(GDataErrorCode fetch_error_code,
347 const std::string& data) { 348 const std::string& data) {
348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 399
399 void GetDataOperation::RunCallbackOnSuccess(GDataErrorCode fetch_error_code, 400 void GetDataOperation::RunCallbackOnSuccess(GDataErrorCode fetch_error_code,
400 scoped_ptr<base::Value> value) { 401 scoped_ptr<base::Value> value) {
401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
402 callback_.Run(fetch_error_code, value.Pass()); 403 callback_.Run(fetch_error_code, value.Pass());
403 } 404 }
404 405
405 //========================= InitiateUploadOperationBase ======================== 406 //========================= InitiateUploadOperationBase ========================
406 407
407 InitiateUploadOperationBase::InitiateUploadOperationBase( 408 InitiateUploadOperationBase::InitiateUploadOperationBase(
408 OperationRegistry* registry, 409 OperationRunner* runner,
409 net::URLRequestContextGetter* url_request_context_getter, 410 net::URLRequestContextGetter* url_request_context_getter,
410 const InitiateUploadCallback& callback, 411 const InitiateUploadCallback& callback,
411 const base::FilePath& drive_file_path, 412 const base::FilePath& drive_file_path,
412 const std::string& content_type, 413 const std::string& content_type,
413 int64 content_length) 414 int64 content_length)
414 : UrlFetchOperationBase(registry, 415 : UrlFetchOperationBase(runner,
415 url_request_context_getter, 416 url_request_context_getter,
416 drive_file_path), 417 drive_file_path),
417 callback_(callback), 418 callback_(callback),
418 drive_file_path_(drive_file_path), 419 drive_file_path_(drive_file_path),
419 content_type_(content_type), 420 content_type_(content_type),
420 content_length_(content_length) { 421 content_length_(content_length) {
421 DCHECK(!callback_.is_null()); 422 DCHECK(!callback_.is_null());
422 DCHECK(!content_type_.empty()); 423 DCHECK(!content_type_.empty());
423 DCHECK_GE(content_length_, 0); 424 DCHECK_GE(content_length_, 0);
424 } 425 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 start_position_received(start_position_received), 478 start_position_received(start_position_received),
478 end_position_received(end_position_received) { 479 end_position_received(end_position_received) {
479 } 480 }
480 481
481 UploadRangeResponse::~UploadRangeResponse() { 482 UploadRangeResponse::~UploadRangeResponse() {
482 } 483 }
483 484
484 //========================== UploadRangeOperationBase ========================== 485 //========================== UploadRangeOperationBase ==========================
485 486
486 UploadRangeOperationBase::UploadRangeOperationBase( 487 UploadRangeOperationBase::UploadRangeOperationBase(
487 OperationRegistry* registry, 488 OperationRunner* runner,
488 net::URLRequestContextGetter* url_request_context_getter, 489 net::URLRequestContextGetter* url_request_context_getter,
489 const base::FilePath& drive_file_path, 490 const base::FilePath& drive_file_path,
490 const GURL& upload_url) 491 const GURL& upload_url)
491 : UrlFetchOperationBase(registry, 492 : UrlFetchOperationBase(runner,
492 url_request_context_getter, 493 url_request_context_getter,
493 drive_file_path), 494 drive_file_path),
494 drive_file_path_(drive_file_path), 495 drive_file_path_(drive_file_path),
495 upload_url_(upload_url), 496 upload_url_(upload_url),
496 last_chunk_completed_(false), 497 last_chunk_completed_(false),
497 weak_ptr_factory_(this) { 498 weak_ptr_factory_(this) {
498 } 499 }
499 500
500 UploadRangeOperationBase::~UploadRangeOperationBase() {} 501 UploadRangeOperationBase::~UploadRangeOperationBase() {}
501 502
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 589
589 void UploadRangeOperationBase::RunCallbackOnPrematureFailure( 590 void UploadRangeOperationBase::RunCallbackOnPrematureFailure(
590 GDataErrorCode code) { 591 GDataErrorCode code) {
591 OnRangeOperationComplete( 592 OnRangeOperationComplete(
592 UploadRangeResponse(code, 0, 0), scoped_ptr<base::Value>()); 593 UploadRangeResponse(code, 0, 0), scoped_ptr<base::Value>());
593 } 594 }
594 595
595 //========================== ResumeUploadOperationBase ========================= 596 //========================== ResumeUploadOperationBase =========================
596 597
597 ResumeUploadOperationBase::ResumeUploadOperationBase( 598 ResumeUploadOperationBase::ResumeUploadOperationBase(
598 OperationRegistry* registry, 599 OperationRunner* runner,
599 net::URLRequestContextGetter* url_request_context_getter, 600 net::URLRequestContextGetter* url_request_context_getter,
600 const base::FilePath& drive_file_path, 601 const base::FilePath& drive_file_path,
601 const GURL& upload_location, 602 const GURL& upload_location,
602 int64 start_position, 603 int64 start_position,
603 int64 end_position, 604 int64 end_position,
604 int64 content_length, 605 int64 content_length,
605 const std::string& content_type, 606 const std::string& content_type,
606 const base::FilePath& local_file_path) 607 const base::FilePath& local_file_path)
607 : UploadRangeOperationBase(registry, 608 : UploadRangeOperationBase(runner,
608 url_request_context_getter, 609 url_request_context_getter,
609 drive_file_path, 610 drive_file_path,
610 upload_location), 611 upload_location),
611 start_position_(start_position), 612 start_position_(start_position),
612 end_position_(end_position), 613 end_position_(end_position),
613 content_length_(content_length), 614 content_length_(content_length),
614 content_type_(content_type), 615 content_type_(content_type),
615 local_file_path_(local_file_path) { 616 local_file_path_(local_file_path) {
616 DCHECK_LE(start_position_, end_position_); 617 DCHECK_LE(start_position_, end_position_);
617 } 618 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 return true; 663 return true;
663 } 664 }
664 665
665 void ResumeUploadOperationBase::NotifyStartToOperationRegistry() { 666 void ResumeUploadOperationBase::NotifyStartToOperationRegistry() {
666 NotifyResume(); 667 NotifyResume();
667 } 668 }
668 669
669 //======================== GetUploadStatusOperationBase ======================== 670 //======================== GetUploadStatusOperationBase ========================
670 671
671 GetUploadStatusOperationBase::GetUploadStatusOperationBase( 672 GetUploadStatusOperationBase::GetUploadStatusOperationBase(
672 OperationRegistry* registry, 673 OperationRunner* runner,
673 net::URLRequestContextGetter* url_request_context_getter, 674 net::URLRequestContextGetter* url_request_context_getter,
674 const base::FilePath& drive_file_path, 675 const base::FilePath& drive_file_path,
675 const GURL& upload_url, 676 const GURL& upload_url,
676 int64 content_length) 677 int64 content_length)
677 : UploadRangeOperationBase(registry, 678 : UploadRangeOperationBase(runner,
678 url_request_context_getter, 679 url_request_context_getter,
679 drive_file_path, 680 drive_file_path,
680 upload_url), 681 upload_url),
681 content_length_(content_length) {} 682 content_length_(content_length) {}
682 683
683 GetUploadStatusOperationBase::~GetUploadStatusOperationBase() {} 684 GetUploadStatusOperationBase::~GetUploadStatusOperationBase() {}
684 685
685 std::vector<std::string> 686 std::vector<std::string>
686 GetUploadStatusOperationBase::GetExtraRequestHeaders() const { 687 GetUploadStatusOperationBase::GetExtraRequestHeaders() const {
687 // The header looks like 688 // The header looks like
688 // Content-Range: bytes */<content_length> 689 // Content-Range: bytes */<content_length>
689 // for example: 690 // for example:
690 // Content-Range: bytes */13851821 691 // Content-Range: bytes */13851821
691 DCHECK_GE(content_length_, 0); 692 DCHECK_GE(content_length_, 0);
692 693
693 std::vector<std::string> headers; 694 std::vector<std::string> headers;
694 headers.push_back( 695 headers.push_back(
695 std::string(kUploadContentRange) + "*/" + 696 std::string(kUploadContentRange) + "*/" +
696 base::Int64ToString(content_length_)); 697 base::Int64ToString(content_length_));
697 return headers; 698 return headers;
698 } 699 }
699 700
700 //============================ DownloadFileOperation =========================== 701 //============================ DownloadFileOperation ===========================
701 702
702 DownloadFileOperation::DownloadFileOperation( 703 DownloadFileOperation::DownloadFileOperation(
703 OperationRegistry* registry, 704 OperationRunner* runner,
704 net::URLRequestContextGetter* url_request_context_getter, 705 net::URLRequestContextGetter* url_request_context_getter,
705 const DownloadActionCallback& download_action_callback, 706 const DownloadActionCallback& download_action_callback,
706 const GetContentCallback& get_content_callback, 707 const GetContentCallback& get_content_callback,
707 const ProgressCallback& progress_callback, 708 const ProgressCallback& progress_callback,
708 const GURL& download_url, 709 const GURL& download_url,
709 const base::FilePath& drive_file_path, 710 const base::FilePath& drive_file_path,
710 const base::FilePath& output_file_path) 711 const base::FilePath& output_file_path)
711 : UrlFetchOperationBase(registry, 712 : UrlFetchOperationBase(runner,
712 url_request_context_getter, 713 url_request_context_getter,
713 drive_file_path), 714 drive_file_path),
714 download_action_callback_(download_action_callback), 715 download_action_callback_(download_action_callback),
715 get_content_callback_(get_content_callback), 716 get_content_callback_(get_content_callback),
716 progress_callback_(progress_callback), 717 progress_callback_(progress_callback),
717 download_url_(download_url) { 718 download_url_(download_url) {
718 DCHECK(!download_action_callback_.is_null()); 719 DCHECK(!download_action_callback_.is_null());
719 // get_content_callback may be null. 720 // get_content_callback may be null.
720 721
721 // Make sure we download the content into a temp file. 722 // Make sure we download the content into a temp file.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 764
764 download_action_callback_.Run(code, temp_file); 765 download_action_callback_.Run(code, temp_file);
765 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); 766 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS);
766 } 767 }
767 768
768 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { 769 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) {
769 download_action_callback_.Run(code, base::FilePath()); 770 download_action_callback_.Run(code, base::FilePath());
770 } 771 }
771 772
772 } // namespace google_apis 773 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/base_operations.h ('k') | chrome/browser/google_apis/base_operations_server_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698