| 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 #include "chrome/browser/google_apis/base_requests.h" | 5 #include "chrome/browser/google_apis/base_requests.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 "chrome/browser/google_apis/request_sender.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
| 16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "net/http/http_byte_range.h" | 17 #include "net/http/http_byte_range.h" |
| 18 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
| 19 #include "net/http/http_util.h" | 19 #include "net/http/http_util.h" |
| 20 #include "net/url_request/url_fetcher.h" | 20 #include "net/url_request/url_fetcher.h" |
| 21 #include "net/url_request/url_request_status.h" | 21 #include "net/url_request/url_request_status.h" |
| 22 | 22 |
| 23 using content::BrowserThread; | 23 using content::BrowserThread; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 base::PostTaskAndReplyWithResult( | 86 base::PostTaskAndReplyWithResult( |
| 87 BrowserThread::GetBlockingPool(), | 87 BrowserThread::GetBlockingPool(), |
| 88 FROM_HERE, | 88 FROM_HERE, |
| 89 base::Bind(&ParseJsonOnBlockingPool, json), | 89 base::Bind(&ParseJsonOnBlockingPool, json), |
| 90 callback); | 90 callback); |
| 91 } | 91 } |
| 92 | 92 |
| 93 //============================ UrlFetchRequestBase =========================== | 93 //============================ UrlFetchRequestBase =========================== |
| 94 | 94 |
| 95 UrlFetchRequestBase::UrlFetchRequestBase( | 95 UrlFetchRequestBase::UrlFetchRequestBase( |
| 96 OperationRunner* runner, | 96 RequestSender* runner, |
| 97 net::URLRequestContextGetter* url_request_context_getter) | 97 net::URLRequestContextGetter* url_request_context_getter) |
| 98 : OperationRegistry::Operation(runner->operation_registry()), | 98 : OperationRegistry::Operation(runner->operation_registry()), |
| 99 url_request_context_getter_(url_request_context_getter), | 99 url_request_context_getter_(url_request_context_getter), |
| 100 re_authenticate_count_(0), | 100 re_authenticate_count_(0), |
| 101 started_(false), | 101 started_(false), |
| 102 save_temp_file_(false), | 102 save_temp_file_(false), |
| 103 weak_ptr_factory_(this) { | 103 weak_ptr_factory_(this) { |
| 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 UrlFetchRequestBase::UrlFetchRequestBase( | 107 UrlFetchRequestBase::UrlFetchRequestBase( |
| 108 OperationRunner* runner, | 108 RequestSender* runner, |
| 109 net::URLRequestContextGetter* url_request_context_getter, | 109 net::URLRequestContextGetter* url_request_context_getter, |
| 110 const base::FilePath& path) | 110 const base::FilePath& path) |
| 111 : OperationRegistry::Operation(runner->operation_registry(), path), | 111 : OperationRegistry::Operation(runner->operation_registry(), path), |
| 112 url_request_context_getter_(url_request_context_getter), | 112 url_request_context_getter_(url_request_context_getter), |
| 113 re_authenticate_count_(0), | 113 re_authenticate_count_(0), |
| 114 started_(false), | 114 started_(false), |
| 115 save_temp_file_(false), | 115 save_temp_file_(false), |
| 116 weak_ptr_factory_(this) { | 116 weak_ptr_factory_(this) { |
| 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 118 } | 118 } |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 302 } |
| 303 | 303 |
| 304 base::WeakPtr<AuthenticatedRequestInterface> | 304 base::WeakPtr<AuthenticatedRequestInterface> |
| 305 UrlFetchRequestBase::GetWeakPtr() { | 305 UrlFetchRequestBase::GetWeakPtr() { |
| 306 return weak_ptr_factory_.GetWeakPtr(); | 306 return weak_ptr_factory_.GetWeakPtr(); |
| 307 } | 307 } |
| 308 | 308 |
| 309 //============================ EntryActionRequest ============================ | 309 //============================ EntryActionRequest ============================ |
| 310 | 310 |
| 311 EntryActionRequest::EntryActionRequest( | 311 EntryActionRequest::EntryActionRequest( |
| 312 OperationRunner* runner, | 312 RequestSender* runner, |
| 313 net::URLRequestContextGetter* url_request_context_getter, | 313 net::URLRequestContextGetter* url_request_context_getter, |
| 314 const EntryActionCallback& callback) | 314 const EntryActionCallback& callback) |
| 315 : UrlFetchRequestBase(runner, url_request_context_getter), | 315 : UrlFetchRequestBase(runner, url_request_context_getter), |
| 316 callback_(callback) { | 316 callback_(callback) { |
| 317 DCHECK(!callback_.is_null()); | 317 DCHECK(!callback_.is_null()); |
| 318 } | 318 } |
| 319 | 319 |
| 320 EntryActionRequest::~EntryActionRequest() {} | 320 EntryActionRequest::~EntryActionRequest() {} |
| 321 | 321 |
| 322 void EntryActionRequest::ProcessURLFetchResults(const URLFetcher* source) { | 322 void EntryActionRequest::ProcessURLFetchResults(const URLFetcher* source) { |
| 323 GDataErrorCode code = GetErrorCode(source); | 323 GDataErrorCode code = GetErrorCode(source); |
| 324 callback_.Run(code); | 324 callback_.Run(code); |
| 325 const bool success = true; | 325 const bool success = true; |
| 326 OnProcessURLFetchResultsComplete(success); | 326 OnProcessURLFetchResultsComplete(success); |
| 327 } | 327 } |
| 328 | 328 |
| 329 void EntryActionRequest::RunCallbackOnPrematureFailure(GDataErrorCode code) { | 329 void EntryActionRequest::RunCallbackOnPrematureFailure(GDataErrorCode code) { |
| 330 callback_.Run(code); | 330 callback_.Run(code); |
| 331 } | 331 } |
| 332 | 332 |
| 333 //============================== GetDataRequest ============================== | 333 //============================== GetDataRequest ============================== |
| 334 | 334 |
| 335 GetDataRequest::GetDataRequest( | 335 GetDataRequest::GetDataRequest( |
| 336 OperationRunner* runner, | 336 RequestSender* runner, |
| 337 net::URLRequestContextGetter* url_request_context_getter, | 337 net::URLRequestContextGetter* url_request_context_getter, |
| 338 const GetDataCallback& callback) | 338 const GetDataCallback& callback) |
| 339 : UrlFetchRequestBase(runner, url_request_context_getter), | 339 : UrlFetchRequestBase(runner, url_request_context_getter), |
| 340 callback_(callback), | 340 callback_(callback), |
| 341 weak_ptr_factory_(this) { | 341 weak_ptr_factory_(this) { |
| 342 DCHECK(!callback_.is_null()); | 342 DCHECK(!callback_.is_null()); |
| 343 } | 343 } |
| 344 | 344 |
| 345 GetDataRequest::~GetDataRequest() {} | 345 GetDataRequest::~GetDataRequest() {} |
| 346 | 346 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 | 399 |
| 400 void GetDataRequest::RunCallbackOnSuccess(GDataErrorCode fetch_error_code, | 400 void GetDataRequest::RunCallbackOnSuccess(GDataErrorCode fetch_error_code, |
| 401 scoped_ptr<base::Value> value) { | 401 scoped_ptr<base::Value> value) { |
| 402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 403 callback_.Run(fetch_error_code, value.Pass()); | 403 callback_.Run(fetch_error_code, value.Pass()); |
| 404 } | 404 } |
| 405 | 405 |
| 406 //========================= InitiateUploadRequestBase ======================== | 406 //========================= InitiateUploadRequestBase ======================== |
| 407 | 407 |
| 408 InitiateUploadRequestBase::InitiateUploadRequestBase( | 408 InitiateUploadRequestBase::InitiateUploadRequestBase( |
| 409 OperationRunner* runner, | 409 RequestSender* runner, |
| 410 net::URLRequestContextGetter* url_request_context_getter, | 410 net::URLRequestContextGetter* url_request_context_getter, |
| 411 const InitiateUploadCallback& callback, | 411 const InitiateUploadCallback& callback, |
| 412 const base::FilePath& drive_file_path, | 412 const base::FilePath& drive_file_path, |
| 413 const std::string& content_type, | 413 const std::string& content_type, |
| 414 int64 content_length) | 414 int64 content_length) |
| 415 : UrlFetchRequestBase(runner, | 415 : UrlFetchRequestBase(runner, |
| 416 url_request_context_getter, | 416 url_request_context_getter, |
| 417 drive_file_path), | 417 drive_file_path), |
| 418 callback_(callback), | 418 callback_(callback), |
| 419 drive_file_path_(drive_file_path), | 419 drive_file_path_(drive_file_path), |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 start_position_received(start_position_received), | 478 start_position_received(start_position_received), |
| 479 end_position_received(end_position_received) { | 479 end_position_received(end_position_received) { |
| 480 } | 480 } |
| 481 | 481 |
| 482 UploadRangeResponse::~UploadRangeResponse() { | 482 UploadRangeResponse::~UploadRangeResponse() { |
| 483 } | 483 } |
| 484 | 484 |
| 485 //========================== UploadRangeRequestBase ========================== | 485 //========================== UploadRangeRequestBase ========================== |
| 486 | 486 |
| 487 UploadRangeRequestBase::UploadRangeRequestBase( | 487 UploadRangeRequestBase::UploadRangeRequestBase( |
| 488 OperationRunner* runner, | 488 RequestSender* runner, |
| 489 net::URLRequestContextGetter* url_request_context_getter, | 489 net::URLRequestContextGetter* url_request_context_getter, |
| 490 const base::FilePath& drive_file_path, | 490 const base::FilePath& drive_file_path, |
| 491 const GURL& upload_url) | 491 const GURL& upload_url) |
| 492 : UrlFetchRequestBase(runner, | 492 : UrlFetchRequestBase(runner, |
| 493 url_request_context_getter, | 493 url_request_context_getter, |
| 494 drive_file_path), | 494 drive_file_path), |
| 495 drive_file_path_(drive_file_path), | 495 drive_file_path_(drive_file_path), |
| 496 upload_url_(upload_url), | 496 upload_url_(upload_url), |
| 497 last_chunk_completed_(false), | 497 last_chunk_completed_(false), |
| 498 weak_ptr_factory_(this) { | 498 weak_ptr_factory_(this) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 | 589 |
| 590 void UploadRangeRequestBase::RunCallbackOnPrematureFailure( | 590 void UploadRangeRequestBase::RunCallbackOnPrematureFailure( |
| 591 GDataErrorCode code) { | 591 GDataErrorCode code) { |
| 592 OnRangeRequestComplete( | 592 OnRangeRequestComplete( |
| 593 UploadRangeResponse(code, 0, 0), scoped_ptr<base::Value>()); | 593 UploadRangeResponse(code, 0, 0), scoped_ptr<base::Value>()); |
| 594 } | 594 } |
| 595 | 595 |
| 596 //========================== ResumeUploadRequestBase ========================= | 596 //========================== ResumeUploadRequestBase ========================= |
| 597 | 597 |
| 598 ResumeUploadRequestBase::ResumeUploadRequestBase( | 598 ResumeUploadRequestBase::ResumeUploadRequestBase( |
| 599 OperationRunner* runner, | 599 RequestSender* runner, |
| 600 net::URLRequestContextGetter* url_request_context_getter, | 600 net::URLRequestContextGetter* url_request_context_getter, |
| 601 const base::FilePath& drive_file_path, | 601 const base::FilePath& drive_file_path, |
| 602 const GURL& upload_location, | 602 const GURL& upload_location, |
| 603 int64 start_position, | 603 int64 start_position, |
| 604 int64 end_position, | 604 int64 end_position, |
| 605 int64 content_length, | 605 int64 content_length, |
| 606 const std::string& content_type, | 606 const std::string& content_type, |
| 607 const base::FilePath& local_file_path) | 607 const base::FilePath& local_file_path) |
| 608 : UploadRangeRequestBase(runner, | 608 : UploadRangeRequestBase(runner, |
| 609 url_request_context_getter, | 609 url_request_context_getter, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 return true; | 663 return true; |
| 664 } | 664 } |
| 665 | 665 |
| 666 void ResumeUploadRequestBase::NotifyStartToOperationRegistry() { | 666 void ResumeUploadRequestBase::NotifyStartToOperationRegistry() { |
| 667 NotifyResume(); | 667 NotifyResume(); |
| 668 } | 668 } |
| 669 | 669 |
| 670 //======================== GetUploadStatusRequestBase ======================== | 670 //======================== GetUploadStatusRequestBase ======================== |
| 671 | 671 |
| 672 GetUploadStatusRequestBase::GetUploadStatusRequestBase( | 672 GetUploadStatusRequestBase::GetUploadStatusRequestBase( |
| 673 OperationRunner* runner, | 673 RequestSender* runner, |
| 674 net::URLRequestContextGetter* url_request_context_getter, | 674 net::URLRequestContextGetter* url_request_context_getter, |
| 675 const base::FilePath& drive_file_path, | 675 const base::FilePath& drive_file_path, |
| 676 const GURL& upload_url, | 676 const GURL& upload_url, |
| 677 int64 content_length) | 677 int64 content_length) |
| 678 : UploadRangeRequestBase(runner, | 678 : UploadRangeRequestBase(runner, |
| 679 url_request_context_getter, | 679 url_request_context_getter, |
| 680 drive_file_path, | 680 drive_file_path, |
| 681 upload_url), | 681 upload_url), |
| 682 content_length_(content_length) {} | 682 content_length_(content_length) {} |
| 683 | 683 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 694 std::vector<std::string> headers; | 694 std::vector<std::string> headers; |
| 695 headers.push_back( | 695 headers.push_back( |
| 696 std::string(kUploadContentRange) + "*/" + | 696 std::string(kUploadContentRange) + "*/" + |
| 697 base::Int64ToString(content_length_)); | 697 base::Int64ToString(content_length_)); |
| 698 return headers; | 698 return headers; |
| 699 } | 699 } |
| 700 | 700 |
| 701 //============================ DownloadFileRequest =========================== | 701 //============================ DownloadFileRequest =========================== |
| 702 | 702 |
| 703 DownloadFileRequest::DownloadFileRequest( | 703 DownloadFileRequest::DownloadFileRequest( |
| 704 OperationRunner* runner, | 704 RequestSender* runner, |
| 705 net::URLRequestContextGetter* url_request_context_getter, | 705 net::URLRequestContextGetter* url_request_context_getter, |
| 706 const DownloadActionCallback& download_action_callback, | 706 const DownloadActionCallback& download_action_callback, |
| 707 const GetContentCallback& get_content_callback, | 707 const GetContentCallback& get_content_callback, |
| 708 const ProgressCallback& progress_callback, | 708 const ProgressCallback& progress_callback, |
| 709 const GURL& download_url, | 709 const GURL& download_url, |
| 710 const base::FilePath& drive_file_path, | 710 const base::FilePath& drive_file_path, |
| 711 const base::FilePath& output_file_path) | 711 const base::FilePath& output_file_path) |
| 712 : UrlFetchRequestBase(runner, | 712 : UrlFetchRequestBase(runner, |
| 713 url_request_context_getter, | 713 url_request_context_getter, |
| 714 drive_file_path), | 714 drive_file_path), |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 | 764 |
| 765 download_action_callback_.Run(code, temp_file); | 765 download_action_callback_.Run(code, temp_file); |
| 766 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); | 766 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); |
| 767 } | 767 } |
| 768 | 768 |
| 769 void DownloadFileRequest::RunCallbackOnPrematureFailure(GDataErrorCode code) { | 769 void DownloadFileRequest::RunCallbackOnPrematureFailure(GDataErrorCode code) { |
| 770 download_action_callback_.Run(code, base::FilePath()); | 770 download_action_callback_.Run(code, base::FilePath()); |
| 771 } | 771 } |
| 772 | 772 |
| 773 } // namespace google_apis | 773 } // namespace google_apis |
| OLD | NEW |