| 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 "google_apis/drive/base_requests.h" | 5 #include "google_apis/drive/base_requests.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 if (!callback.is_null()) | 284 if (!callback.is_null()) |
| 285 callback.Run(result); | 285 callback.Run(result); |
| 286 } | 286 } |
| 287 | 287 |
| 288 //============================ UrlFetchRequestBase =========================== | 288 //============================ UrlFetchRequestBase =========================== |
| 289 | 289 |
| 290 UrlFetchRequestBase::UrlFetchRequestBase(RequestSender* sender) | 290 UrlFetchRequestBase::UrlFetchRequestBase(RequestSender* sender) |
| 291 : re_authenticate_count_(0), | 291 : re_authenticate_count_(0), |
| 292 response_writer_(NULL), | 292 response_writer_(NULL), |
| 293 sender_(sender), | 293 sender_(sender), |
| 294 error_code_(GDATA_OTHER_ERROR), | 294 error_code_(DRIVE_OTHER_ERROR), |
| 295 weak_ptr_factory_(this) { | 295 weak_ptr_factory_(this) { |
| 296 } | 296 } |
| 297 | 297 |
| 298 UrlFetchRequestBase::~UrlFetchRequestBase() {} | 298 UrlFetchRequestBase::~UrlFetchRequestBase() {} |
| 299 | 299 |
| 300 void UrlFetchRequestBase::Start(const std::string& access_token, | 300 void UrlFetchRequestBase::Start(const std::string& access_token, |
| 301 const std::string& custom_user_agent, | 301 const std::string& custom_user_agent, |
| 302 const ReAuthenticateCallback& callback) { | 302 const ReAuthenticateCallback& callback) { |
| 303 DCHECK(CalledOnValidThread()); | 303 DCHECK(CalledOnValidThread()); |
| 304 DCHECK(!access_token.empty()); | 304 DCHECK(!access_token.empty()); |
| 305 DCHECK(!callback.is_null()); | 305 DCHECK(!callback.is_null()); |
| 306 DCHECK(re_authenticate_callback_.is_null()); | 306 DCHECK(re_authenticate_callback_.is_null()); |
| 307 | 307 |
| 308 re_authenticate_callback_ = callback; | 308 re_authenticate_callback_ = callback; |
| 309 | 309 |
| 310 GURL url = GetURL(); | 310 GURL url = GetURL(); |
| 311 if (url.is_empty()) { | 311 if (url.is_empty()) { |
| 312 // Error is found on generating the url. Send the error message to the | 312 // Error is found on generating the url. Send the error message to the |
| 313 // callback, and then return immediately without trying to connect | 313 // callback, and then return immediately without trying to connect |
| 314 // to the server. | 314 // to the server. |
| 315 RunCallbackOnPrematureFailure(GDATA_OTHER_ERROR); | 315 RunCallbackOnPrematureFailure(DRIVE_OTHER_ERROR); |
| 316 return; | 316 return; |
| 317 } | 317 } |
| 318 DVLOG(1) << "URL: " << url.spec(); | 318 DVLOG(1) << "URL: " << url.spec(); |
| 319 | 319 |
| 320 URLFetcher::RequestType request_type = GetRequestType(); | 320 URLFetcher::RequestType request_type = GetRequestType(); |
| 321 url_fetcher_.reset(URLFetcher::Create(url, request_type, this)); | 321 url_fetcher_.reset(URLFetcher::Create(url, request_type, this)); |
| 322 url_fetcher_->SetRequestContext(sender_->url_request_context_getter()); | 322 url_fetcher_->SetRequestContext(sender_->url_request_context_getter()); |
| 323 // Always set flags to neither send nor save cookies. | 323 // Always set flags to neither send nor save cookies. |
| 324 url_fetcher_->SetLoadFlags( | 324 url_fetcher_->SetLoadFlags( |
| 325 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES | | 325 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES | |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 } | 407 } |
| 408 | 408 |
| 409 void UrlFetchRequestBase::GetOutputFilePath( | 409 void UrlFetchRequestBase::GetOutputFilePath( |
| 410 base::FilePath* local_file_path, | 410 base::FilePath* local_file_path, |
| 411 GetContentCallback* get_content_callback) { | 411 GetContentCallback* get_content_callback) { |
| 412 } | 412 } |
| 413 | 413 |
| 414 void UrlFetchRequestBase::Cancel() { | 414 void UrlFetchRequestBase::Cancel() { |
| 415 response_writer_ = NULL; | 415 response_writer_ = NULL; |
| 416 url_fetcher_.reset(NULL); | 416 url_fetcher_.reset(NULL); |
| 417 RunCallbackOnPrematureFailure(GDATA_CANCELLED); | 417 RunCallbackOnPrematureFailure(DRIVE_CANCELLED); |
| 418 sender_->RequestFinished(this); | 418 sender_->RequestFinished(this); |
| 419 } | 419 } |
| 420 | 420 |
| 421 GDataErrorCode UrlFetchRequestBase::GetErrorCode() { | 421 DriveApiErrorCode UrlFetchRequestBase::GetErrorCode() { |
| 422 return error_code_; | 422 return error_code_; |
| 423 } | 423 } |
| 424 | 424 |
| 425 bool UrlFetchRequestBase::CalledOnValidThread() { | 425 bool UrlFetchRequestBase::CalledOnValidThread() { |
| 426 return thread_checker_.CalledOnValidThread(); | 426 return thread_checker_.CalledOnValidThread(); |
| 427 } | 427 } |
| 428 | 428 |
| 429 base::SequencedTaskRunner* UrlFetchRequestBase::blocking_task_runner() const { | 429 base::SequencedTaskRunner* UrlFetchRequestBase::blocking_task_runner() const { |
| 430 return sender_->blocking_task_runner(); | 430 return sender_->blocking_task_runner(); |
| 431 } | 431 } |
| 432 | 432 |
| 433 void UrlFetchRequestBase::OnProcessURLFetchResultsComplete() { | 433 void UrlFetchRequestBase::OnProcessURLFetchResultsComplete() { |
| 434 sender_->RequestFinished(this); | 434 sender_->RequestFinished(this); |
| 435 } | 435 } |
| 436 | 436 |
| 437 void UrlFetchRequestBase::OnURLFetchComplete(const URLFetcher* source) { | 437 void UrlFetchRequestBase::OnURLFetchComplete(const URLFetcher* source) { |
| 438 DVLOG(1) << "Response headers:\n" << GetResponseHeadersAsString(source); | 438 DVLOG(1) << "Response headers:\n" << GetResponseHeadersAsString(source); |
| 439 | 439 |
| 440 // Determine error code. | 440 // Determine error code. |
| 441 error_code_ = static_cast<GDataErrorCode>(source->GetResponseCode()); | 441 error_code_ = static_cast<DriveApiErrorCode>(source->GetResponseCode()); |
| 442 if (!source->GetStatus().is_success()) { | 442 if (!source->GetStatus().is_success()) { |
| 443 switch (source->GetStatus().error()) { | 443 switch (source->GetStatus().error()) { |
| 444 case net::ERR_NETWORK_CHANGED: | 444 case net::ERR_NETWORK_CHANGED: |
| 445 error_code_ = GDATA_NO_CONNECTION; | 445 error_code_ = DRIVE_NO_CONNECTION; |
| 446 break; | 446 break; |
| 447 default: | 447 default: |
| 448 error_code_ = GDATA_OTHER_ERROR; | 448 error_code_ = DRIVE_OTHER_ERROR; |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 | 451 |
| 452 // The server may return detailed error status in JSON. | 452 // The server may return detailed error status in JSON. |
| 453 // See https://developers.google.com/drive/handle-errors | 453 // See https://developers.google.com/drive/handle-errors |
| 454 if (!IsSuccessfulResponseCode(error_code_)) { | 454 if (!IsSuccessfulResponseCode(error_code_)) { |
| 455 DVLOG(1) << response_writer_->data(); | 455 DVLOG(1) << response_writer_->data(); |
| 456 | 456 |
| 457 const char kErrorKey[] = "error"; | 457 const char kErrorKey[] = "error"; |
| 458 const char kErrorErrorsKey[] = "errors"; | 458 const char kErrorErrorsKey[] = "errors"; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 477 base::ListValue* errors = NULL; | 477 base::ListValue* errors = NULL; |
| 478 base::DictionaryValue* first_error = NULL; | 478 base::DictionaryValue* first_error = NULL; |
| 479 if (error->GetListWithoutPathExpansion(kErrorErrorsKey, &errors) && | 479 if (error->GetListWithoutPathExpansion(kErrorErrorsKey, &errors) && |
| 480 errors->GetDictionary(0, &first_error)) { | 480 errors->GetDictionary(0, &first_error)) { |
| 481 std::string reason; | 481 std::string reason; |
| 482 first_error->GetStringWithoutPathExpansion(kErrorReasonKey, &reason); | 482 first_error->GetStringWithoutPathExpansion(kErrorReasonKey, &reason); |
| 483 if (reason == kErrorReasonRateLimitExceeded || | 483 if (reason == kErrorReasonRateLimitExceeded || |
| 484 reason == kErrorReasonUserRateLimitExceeded) | 484 reason == kErrorReasonUserRateLimitExceeded) |
| 485 error_code_ = HTTP_SERVICE_UNAVAILABLE; | 485 error_code_ = HTTP_SERVICE_UNAVAILABLE; |
| 486 if (reason == kErrorReasonQuotaExceeded) | 486 if (reason == kErrorReasonQuotaExceeded) |
| 487 error_code_ = GDATA_NO_SPACE; | 487 error_code_ = DRIVE_NO_SPACE; |
| 488 } | 488 } |
| 489 } | 489 } |
| 490 } | 490 } |
| 491 | 491 |
| 492 // Handle authentication failure. | 492 // Handle authentication failure. |
| 493 if (error_code_ == HTTP_UNAUTHORIZED) { | 493 if (error_code_ == HTTP_UNAUTHORIZED) { |
| 494 if (++re_authenticate_count_ <= kMaxReAuthenticateAttemptsPerRequest) { | 494 if (++re_authenticate_count_ <= kMaxReAuthenticateAttemptsPerRequest) { |
| 495 // Reset re_authenticate_callback_ so Start() can be called again. | 495 // Reset re_authenticate_callback_ so Start() can be called again. |
| 496 ReAuthenticateCallback callback = re_authenticate_callback_; | 496 ReAuthenticateCallback callback = re_authenticate_callback_; |
| 497 re_authenticate_callback_.Reset(); | 497 re_authenticate_callback_.Reset(); |
| 498 callback.Run(this); | 498 callback.Run(this); |
| 499 return; | 499 return; |
| 500 } | 500 } |
| 501 | 501 |
| 502 OnAuthFailed(error_code_); | 502 OnAuthFailed(error_code_); |
| 503 return; | 503 return; |
| 504 } | 504 } |
| 505 | 505 |
| 506 // Overridden by each specialization | 506 // Overridden by each specialization |
| 507 ProcessURLFetchResults(source); | 507 ProcessURLFetchResults(source); |
| 508 } | 508 } |
| 509 | 509 |
| 510 void UrlFetchRequestBase::OnAuthFailed(GDataErrorCode code) { | 510 void UrlFetchRequestBase::OnAuthFailed(DriveApiErrorCode code) { |
| 511 RunCallbackOnPrematureFailure(code); | 511 RunCallbackOnPrematureFailure(code); |
| 512 sender_->RequestFinished(this); | 512 sender_->RequestFinished(this); |
| 513 } | 513 } |
| 514 | 514 |
| 515 base::WeakPtr<AuthenticatedRequestInterface> | 515 base::WeakPtr<AuthenticatedRequestInterface> |
| 516 UrlFetchRequestBase::GetWeakPtr() { | 516 UrlFetchRequestBase::GetWeakPtr() { |
| 517 return weak_ptr_factory_.GetWeakPtr(); | 517 return weak_ptr_factory_.GetWeakPtr(); |
| 518 } | 518 } |
| 519 | 519 |
| 520 //============================ EntryActionRequest ============================ | 520 //============================ EntryActionRequest ============================ |
| 521 | 521 |
| 522 EntryActionRequest::EntryActionRequest(RequestSender* sender, | 522 EntryActionRequest::EntryActionRequest(RequestSender* sender, |
| 523 const EntryActionCallback& callback) | 523 const EntryActionCallback& callback) |
| 524 : UrlFetchRequestBase(sender), | 524 : UrlFetchRequestBase(sender), |
| 525 callback_(callback) { | 525 callback_(callback) { |
| 526 DCHECK(!callback_.is_null()); | 526 DCHECK(!callback_.is_null()); |
| 527 } | 527 } |
| 528 | 528 |
| 529 EntryActionRequest::~EntryActionRequest() {} | 529 EntryActionRequest::~EntryActionRequest() {} |
| 530 | 530 |
| 531 void EntryActionRequest::ProcessURLFetchResults(const URLFetcher* source) { | 531 void EntryActionRequest::ProcessURLFetchResults(const URLFetcher* source) { |
| 532 callback_.Run(GetErrorCode()); | 532 callback_.Run(GetErrorCode()); |
| 533 OnProcessURLFetchResultsComplete(); | 533 OnProcessURLFetchResultsComplete(); |
| 534 } | 534 } |
| 535 | 535 |
| 536 void EntryActionRequest::RunCallbackOnPrematureFailure(GDataErrorCode code) { | 536 void EntryActionRequest::RunCallbackOnPrematureFailure(DriveApiErrorCode code) { |
| 537 callback_.Run(code); | 537 callback_.Run(code); |
| 538 } | 538 } |
| 539 | 539 |
| 540 //========================= InitiateUploadRequestBase ======================== | 540 //========================= InitiateUploadRequestBase ======================== |
| 541 | 541 |
| 542 InitiateUploadRequestBase::InitiateUploadRequestBase( | 542 InitiateUploadRequestBase::InitiateUploadRequestBase( |
| 543 RequestSender* sender, | 543 RequestSender* sender, |
| 544 const InitiateUploadCallback& callback, | 544 const InitiateUploadCallback& callback, |
| 545 const std::string& content_type, | 545 const std::string& content_type, |
| 546 int64 content_length) | 546 int64 content_length) |
| 547 : UrlFetchRequestBase(sender), | 547 : UrlFetchRequestBase(sender), |
| 548 callback_(callback), | 548 callback_(callback), |
| 549 content_type_(content_type), | 549 content_type_(content_type), |
| 550 content_length_(content_length) { | 550 content_length_(content_length) { |
| 551 DCHECK(!callback_.is_null()); | 551 DCHECK(!callback_.is_null()); |
| 552 DCHECK(!content_type_.empty()); | 552 DCHECK(!content_type_.empty()); |
| 553 DCHECK_GE(content_length_, 0); | 553 DCHECK_GE(content_length_, 0); |
| 554 } | 554 } |
| 555 | 555 |
| 556 InitiateUploadRequestBase::~InitiateUploadRequestBase() {} | 556 InitiateUploadRequestBase::~InitiateUploadRequestBase() {} |
| 557 | 557 |
| 558 void InitiateUploadRequestBase::ProcessURLFetchResults( | 558 void InitiateUploadRequestBase::ProcessURLFetchResults( |
| 559 const URLFetcher* source) { | 559 const URLFetcher* source) { |
| 560 GDataErrorCode code = GetErrorCode(); | 560 DriveApiErrorCode code = GetErrorCode(); |
| 561 | 561 |
| 562 std::string upload_location; | 562 std::string upload_location; |
| 563 if (code == HTTP_SUCCESS) { | 563 if (code == HTTP_SUCCESS) { |
| 564 // Retrieve value of the first "Location" header. | 564 // Retrieve value of the first "Location" header. |
| 565 source->GetResponseHeaders()->EnumerateHeader(NULL, | 565 source->GetResponseHeaders()->EnumerateHeader(NULL, |
| 566 kUploadResponseLocation, | 566 kUploadResponseLocation, |
| 567 &upload_location); | 567 &upload_location); |
| 568 } | 568 } |
| 569 | 569 |
| 570 callback_.Run(code, GURL(upload_location)); | 570 callback_.Run(code, GURL(upload_location)); |
| 571 OnProcessURLFetchResultsComplete(); | 571 OnProcessURLFetchResultsComplete(); |
| 572 } | 572 } |
| 573 | 573 |
| 574 void InitiateUploadRequestBase::RunCallbackOnPrematureFailure( | 574 void InitiateUploadRequestBase::RunCallbackOnPrematureFailure( |
| 575 GDataErrorCode code) { | 575 DriveApiErrorCode code) { |
| 576 callback_.Run(code, GURL()); | 576 callback_.Run(code, GURL()); |
| 577 } | 577 } |
| 578 | 578 |
| 579 std::vector<std::string> | 579 std::vector<std::string> |
| 580 InitiateUploadRequestBase::GetExtraRequestHeaders() const { | 580 InitiateUploadRequestBase::GetExtraRequestHeaders() const { |
| 581 std::vector<std::string> headers; | 581 std::vector<std::string> headers; |
| 582 headers.push_back(kUploadContentType + content_type_); | 582 headers.push_back(kUploadContentType + content_type_); |
| 583 headers.push_back( | 583 headers.push_back( |
| 584 kUploadContentLength + base::Int64ToString(content_length_)); | 584 kUploadContentLength + base::Int64ToString(content_length_)); |
| 585 return headers; | 585 return headers; |
| 586 } | 586 } |
| 587 | 587 |
| 588 //============================ UploadRangeResponse ============================= | 588 //============================ UploadRangeResponse ============================= |
| 589 | 589 |
| 590 UploadRangeResponse::UploadRangeResponse() | 590 UploadRangeResponse::UploadRangeResponse() |
| 591 : code(HTTP_SUCCESS), | 591 : code(HTTP_SUCCESS), |
| 592 start_position_received(0), | 592 start_position_received(0), |
| 593 end_position_received(0) { | 593 end_position_received(0) { |
| 594 } | 594 } |
| 595 | 595 |
| 596 UploadRangeResponse::UploadRangeResponse(GDataErrorCode code, | 596 UploadRangeResponse::UploadRangeResponse(DriveApiErrorCode code, |
| 597 int64 start_position_received, | 597 int64 start_position_received, |
| 598 int64 end_position_received) | 598 int64 end_position_received) |
| 599 : code(code), | 599 : code(code), |
| 600 start_position_received(start_position_received), | 600 start_position_received(start_position_received), |
| 601 end_position_received(end_position_received) { | 601 end_position_received(end_position_received) { |
| 602 } | 602 } |
| 603 | 603 |
| 604 UploadRangeResponse::~UploadRangeResponse() { | 604 UploadRangeResponse::~UploadRangeResponse() { |
| 605 } | 605 } |
| 606 | 606 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 620 // has to be appended not here but in InitiateUploadRequestBase::GetURL(). | 620 // has to be appended not here but in InitiateUploadRequestBase::GetURL(). |
| 621 return upload_url_; | 621 return upload_url_; |
| 622 } | 622 } |
| 623 | 623 |
| 624 URLFetcher::RequestType UploadRangeRequestBase::GetRequestType() const { | 624 URLFetcher::RequestType UploadRangeRequestBase::GetRequestType() const { |
| 625 return URLFetcher::PUT; | 625 return URLFetcher::PUT; |
| 626 } | 626 } |
| 627 | 627 |
| 628 void UploadRangeRequestBase::ProcessURLFetchResults( | 628 void UploadRangeRequestBase::ProcessURLFetchResults( |
| 629 const URLFetcher* source) { | 629 const URLFetcher* source) { |
| 630 GDataErrorCode code = GetErrorCode(); | 630 DriveApiErrorCode code = GetErrorCode(); |
| 631 net::HttpResponseHeaders* hdrs = source->GetResponseHeaders(); | 631 net::HttpResponseHeaders* hdrs = source->GetResponseHeaders(); |
| 632 | 632 |
| 633 if (code == HTTP_RESUME_INCOMPLETE) { | 633 if (code == HTTP_RESUME_INCOMPLETE) { |
| 634 // Retrieve value of the first "Range" header. | 634 // Retrieve value of the first "Range" header. |
| 635 // The Range header is appeared only if there is at least one received | 635 // The Range header is appeared only if there is at least one received |
| 636 // byte. So, initialize the positions by 0 so that the [0,0) will be | 636 // byte. So, initialize the positions by 0 so that the [0,0) will be |
| 637 // returned via the |callback_| for empty data case. | 637 // returned via the |callback_| for empty data case. |
| 638 int64 start_position_received = 0; | 638 int64 start_position_received = 0; |
| 639 int64 end_position_received = 0; | 639 int64 end_position_received = 0; |
| 640 std::string range_received; | 640 std::string range_received; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 671 weak_ptr_factory_.GetWeakPtr(), | 671 weak_ptr_factory_.GetWeakPtr(), |
| 672 code)); | 672 code)); |
| 673 } else { | 673 } else { |
| 674 // Failed to upload. Run callbacks to notify the error. | 674 // Failed to upload. Run callbacks to notify the error. |
| 675 OnRangeRequestComplete( | 675 OnRangeRequestComplete( |
| 676 UploadRangeResponse(code, -1, -1), scoped_ptr<base::Value>()); | 676 UploadRangeResponse(code, -1, -1), scoped_ptr<base::Value>()); |
| 677 OnProcessURLFetchResultsComplete(); | 677 OnProcessURLFetchResultsComplete(); |
| 678 } | 678 } |
| 679 } | 679 } |
| 680 | 680 |
| 681 void UploadRangeRequestBase::OnDataParsed(GDataErrorCode code, | 681 void UploadRangeRequestBase::OnDataParsed(DriveApiErrorCode code, |
| 682 scoped_ptr<base::Value> value) { | 682 scoped_ptr<base::Value> value) { |
| 683 DCHECK(CalledOnValidThread()); | 683 DCHECK(CalledOnValidThread()); |
| 684 DCHECK(code == HTTP_CREATED || code == HTTP_SUCCESS); | 684 DCHECK(code == HTTP_CREATED || code == HTTP_SUCCESS); |
| 685 | 685 |
| 686 OnRangeRequestComplete(UploadRangeResponse(code, -1, -1), value.Pass()); | 686 OnRangeRequestComplete(UploadRangeResponse(code, -1, -1), value.Pass()); |
| 687 OnProcessURLFetchResultsComplete(); | 687 OnProcessURLFetchResultsComplete(); |
| 688 } | 688 } |
| 689 | 689 |
| 690 void UploadRangeRequestBase::RunCallbackOnPrematureFailure( | 690 void UploadRangeRequestBase::RunCallbackOnPrematureFailure( |
| 691 GDataErrorCode code) { | 691 DriveApiErrorCode code) { |
| 692 OnRangeRequestComplete( | 692 OnRangeRequestComplete( |
| 693 UploadRangeResponse(code, 0, 0), scoped_ptr<base::Value>()); | 693 UploadRangeResponse(code, 0, 0), scoped_ptr<base::Value>()); |
| 694 } | 694 } |
| 695 | 695 |
| 696 //========================== ResumeUploadRequestBase ========================= | 696 //========================== ResumeUploadRequestBase ========================= |
| 697 | 697 |
| 698 ResumeUploadRequestBase::ResumeUploadRequestBase( | 698 ResumeUploadRequestBase::ResumeUploadRequestBase( |
| 699 RequestSender* sender, | 699 RequestSender* sender, |
| 700 const GURL& upload_location, | 700 const GURL& upload_location, |
| 701 int64 start_position, | 701 int64 start_position, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 } | 835 } |
| 836 | 836 |
| 837 void MultipartUploadRequestBase::OnPrepareUploadContent( | 837 void MultipartUploadRequestBase::OnPrepareUploadContent( |
| 838 const std::string& access_token, | 838 const std::string& access_token, |
| 839 const std::string& custom_user_agent, | 839 const std::string& custom_user_agent, |
| 840 const ReAuthenticateCallback& callback, | 840 const ReAuthenticateCallback& callback, |
| 841 std::string* upload_content_type, | 841 std::string* upload_content_type, |
| 842 std::string* upload_content_data, | 842 std::string* upload_content_data, |
| 843 bool result) { | 843 bool result) { |
| 844 if (!result) { | 844 if (!result) { |
| 845 RunCallbackOnPrematureFailure(GDATA_FILE_ERROR); | 845 RunCallbackOnPrematureFailure(DRIVE_FILE_ERROR); |
| 846 return; | 846 return; |
| 847 } | 847 } |
| 848 upload_content_type_.swap(*upload_content_type); | 848 upload_content_type_.swap(*upload_content_type); |
| 849 upload_content_data_.swap(*upload_content_data); | 849 upload_content_data_.swap(*upload_content_data); |
| 850 UrlFetchRequestBase::Start(access_token, custom_user_agent, callback); | 850 UrlFetchRequestBase::Start(access_token, custom_user_agent, callback); |
| 851 } | 851 } |
| 852 | 852 |
| 853 void MultipartUploadRequestBase::SetBoundaryForTesting( | 853 void MultipartUploadRequestBase::SetBoundaryForTesting( |
| 854 const std::string& boundary) { | 854 const std::string& boundary) { |
| 855 boundary_ = boundary; | 855 boundary_ = boundary; |
| 856 } | 856 } |
| 857 | 857 |
| 858 bool MultipartUploadRequestBase::GetContentData( | 858 bool MultipartUploadRequestBase::GetContentData( |
| 859 std::string* upload_content_type, | 859 std::string* upload_content_type, |
| 860 std::string* upload_content_data) { | 860 std::string* upload_content_data) { |
| 861 // TODO(hirono): Pass stream instead of actual data to reduce memory usage. | 861 // TODO(hirono): Pass stream instead of actual data to reduce memory usage. |
| 862 upload_content_type->swap(upload_content_type_); | 862 upload_content_type->swap(upload_content_type_); |
| 863 upload_content_data->swap(upload_content_data_); | 863 upload_content_data->swap(upload_content_data_); |
| 864 return true; | 864 return true; |
| 865 } | 865 } |
| 866 | 866 |
| 867 void MultipartUploadRequestBase::ProcessURLFetchResults( | 867 void MultipartUploadRequestBase::ProcessURLFetchResults( |
| 868 const URLFetcher* source) { | 868 const URLFetcher* source) { |
| 869 // The upload is successfully done. Parse the response which should be | 869 // The upload is successfully done. Parse the response which should be |
| 870 // the entry's metadata. | 870 // the entry's metadata. |
| 871 const GDataErrorCode code = GetErrorCode(); | 871 const DriveApiErrorCode code = GetErrorCode(); |
| 872 if (code == HTTP_CREATED || code == HTTP_SUCCESS) { | 872 if (code == HTTP_CREATED || code == HTTP_SUCCESS) { |
| 873 ParseJsonOnBlockingPool( | 873 ParseJsonOnBlockingPool( |
| 874 blocking_task_runner(), response_writer()->data(), | 874 blocking_task_runner(), response_writer()->data(), |
| 875 base::Bind(&MultipartUploadRequestBase::OnDataParsed, | 875 base::Bind(&MultipartUploadRequestBase::OnDataParsed, |
| 876 weak_ptr_factory_.GetWeakPtr(), code)); | 876 weak_ptr_factory_.GetWeakPtr(), code)); |
| 877 } else { | 877 } else { |
| 878 OnDataParsed(code, scoped_ptr<base::Value>()); | 878 OnDataParsed(code, scoped_ptr<base::Value>()); |
| 879 } | 879 } |
| 880 } | 880 } |
| 881 | 881 |
| 882 void MultipartUploadRequestBase::RunCallbackOnPrematureFailure( | 882 void MultipartUploadRequestBase::RunCallbackOnPrematureFailure( |
| 883 GDataErrorCode code) { | 883 DriveApiErrorCode code) { |
| 884 callback_.Run(code, scoped_ptr<FileResource>()); | 884 callback_.Run(code, scoped_ptr<FileResource>()); |
| 885 } | 885 } |
| 886 | 886 |
| 887 void MultipartUploadRequestBase::OnURLFetchUploadProgress( | 887 void MultipartUploadRequestBase::OnURLFetchUploadProgress( |
| 888 const net::URLFetcher* source, | 888 const net::URLFetcher* source, |
| 889 int64 current, | 889 int64 current, |
| 890 int64 total) { | 890 int64 total) { |
| 891 if (!progress_callback_.is_null()) | 891 if (!progress_callback_.is_null()) |
| 892 progress_callback_.Run(current, total); | 892 progress_callback_.Run(current, total); |
| 893 } | 893 } |
| 894 | 894 |
| 895 void MultipartUploadRequestBase::OnDataParsed(GDataErrorCode code, | 895 void MultipartUploadRequestBase::OnDataParsed(DriveApiErrorCode code, |
| 896 scoped_ptr<base::Value> value) { | 896 scoped_ptr<base::Value> value) { |
| 897 DCHECK(CalledOnValidThread()); | 897 DCHECK(CalledOnValidThread()); |
| 898 if (value) | 898 if (value) |
| 899 callback_.Run(code, google_apis::FileResource::CreateFrom(*value)); | 899 callback_.Run(code, google_apis::FileResource::CreateFrom(*value)); |
| 900 else | 900 else |
| 901 callback_.Run(GDATA_PARSE_ERROR, scoped_ptr<FileResource>()); | 901 callback_.Run(DRIVE_PARSE_ERROR, scoped_ptr<FileResource>()); |
| 902 OnProcessURLFetchResultsComplete(); | 902 OnProcessURLFetchResultsComplete(); |
| 903 } | 903 } |
| 904 | 904 |
| 905 //============================ DownloadFileRequestBase ========================= | 905 //============================ DownloadFileRequestBase ========================= |
| 906 | 906 |
| 907 DownloadFileRequestBase::DownloadFileRequestBase( | 907 DownloadFileRequestBase::DownloadFileRequestBase( |
| 908 RequestSender* sender, | 908 RequestSender* sender, |
| 909 const DownloadActionCallback& download_action_callback, | 909 const DownloadActionCallback& download_action_callback, |
| 910 const GetContentCallback& get_content_callback, | 910 const GetContentCallback& get_content_callback, |
| 911 const ProgressCallback& progress_callback, | 911 const ProgressCallback& progress_callback, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 939 | 939 |
| 940 void DownloadFileRequestBase::OnURLFetchDownloadProgress( | 940 void DownloadFileRequestBase::OnURLFetchDownloadProgress( |
| 941 const URLFetcher* source, | 941 const URLFetcher* source, |
| 942 int64 current, | 942 int64 current, |
| 943 int64 total) { | 943 int64 total) { |
| 944 if (!progress_callback_.is_null()) | 944 if (!progress_callback_.is_null()) |
| 945 progress_callback_.Run(current, total); | 945 progress_callback_.Run(current, total); |
| 946 } | 946 } |
| 947 | 947 |
| 948 void DownloadFileRequestBase::ProcessURLFetchResults(const URLFetcher* source) { | 948 void DownloadFileRequestBase::ProcessURLFetchResults(const URLFetcher* source) { |
| 949 GDataErrorCode code = GetErrorCode(); | 949 DriveApiErrorCode code = GetErrorCode(); |
| 950 | 950 |
| 951 // Take over the ownership of the the downloaded temp file. | 951 // Take over the ownership of the the downloaded temp file. |
| 952 base::FilePath temp_file; | 952 base::FilePath temp_file; |
| 953 if (code == HTTP_SUCCESS) { | 953 if (code == HTTP_SUCCESS) { |
| 954 response_writer()->DisownFile(); | 954 response_writer()->DisownFile(); |
| 955 temp_file = output_file_path_; | 955 temp_file = output_file_path_; |
| 956 } | 956 } |
| 957 | 957 |
| 958 download_action_callback_.Run(code, temp_file); | 958 download_action_callback_.Run(code, temp_file); |
| 959 OnProcessURLFetchResultsComplete(); | 959 OnProcessURLFetchResultsComplete(); |
| 960 } | 960 } |
| 961 | 961 |
| 962 void DownloadFileRequestBase::RunCallbackOnPrematureFailure( | 962 void DownloadFileRequestBase::RunCallbackOnPrematureFailure( |
| 963 GDataErrorCode code) { | 963 DriveApiErrorCode code) { |
| 964 download_action_callback_.Run(code, base::FilePath()); | 964 download_action_callback_.Run(code, base::FilePath()); |
| 965 } | 965 } |
| 966 | 966 |
| 967 } // namespace google_apis | 967 } // namespace google_apis |
| OLD | NEW |