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

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

Issue 19771024: Parse content in the response for upload iff the upload is successfully done. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/google_apis/drive_api_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 #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/location.h" 8 #include "base/location.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 // The Range header has the received data range, so the start position 483 // The Range header has the received data range, so the start position
484 // should be always 0. 484 // should be always 0.
485 DCHECK_EQ(start_position_received, 0); 485 DCHECK_EQ(start_position_received, 0);
486 486
487 OnRangeRequestComplete(UploadRangeResponse(code, 487 OnRangeRequestComplete(UploadRangeResponse(code,
488 start_position_received, 488 start_position_received,
489 end_position_received), 489 end_position_received),
490 scoped_ptr<base::Value>()); 490 scoped_ptr<base::Value>());
491 491
492 OnProcessURLFetchResultsComplete(true); 492 OnProcessURLFetchResultsComplete(true);
493 } else { 493 } else if (code == HTTP_CREATED || code == HTTP_SUCCESS) {
494 // There might be explanation of unexpected error code in response. 494 // The upload is successfully done. Parse the response which should be
495 // the entry's metadata.
495 std::string response_content; 496 std::string response_content;
496 source->GetResponseAsString(&response_content); 497 source->GetResponseAsString(&response_content);
497 498
498 ParseJson(blocking_task_runner(), 499 ParseJson(blocking_task_runner(),
499 response_content, 500 response_content,
500 base::Bind(&UploadRangeRequestBase::OnDataParsed, 501 base::Bind(&UploadRangeRequestBase::OnDataParsed,
501 weak_ptr_factory_.GetWeakPtr(), 502 weak_ptr_factory_.GetWeakPtr(),
502 code)); 503 code));
504 } else {
505 // Failed to upload. Run callbacks to notify the error.
506 OnRangeRequestComplete(
507 UploadRangeResponse(code, -1, -1), scoped_ptr<base::Value>());
508 OnProcessURLFetchResultsComplete(false);
503 } 509 }
504 } 510 }
505 511
506 void UploadRangeRequestBase::OnDataParsed(GDataErrorCode code, 512 void UploadRangeRequestBase::OnDataParsed(GDataErrorCode code,
507 scoped_ptr<base::Value> value) { 513 scoped_ptr<base::Value> value) {
508 DCHECK(CalledOnValidThread()); 514 DCHECK(CalledOnValidThread());
515 DCHECK(code == HTTP_CREATED || code == HTTP_SUCCESS);
509 516
510 OnRangeRequestComplete(UploadRangeResponse(code, -1, -1), value.Pass()); 517 OnRangeRequestComplete(UploadRangeResponse(code, -1, -1), value.Pass());
511 OnProcessURLFetchResultsComplete( 518 OnProcessURLFetchResultsComplete(true);
512 code == HTTP_CREATED || code == HTTP_SUCCESS);
513 } 519 }
514 520
515 void UploadRangeRequestBase::RunCallbackOnPrematureFailure( 521 void UploadRangeRequestBase::RunCallbackOnPrematureFailure(
516 GDataErrorCode code) { 522 GDataErrorCode code) {
517 OnRangeRequestComplete( 523 OnRangeRequestComplete(
518 UploadRangeResponse(code, 0, 0), scoped_ptr<base::Value>()); 524 UploadRangeResponse(code, 0, 0), scoped_ptr<base::Value>());
519 } 525 }
520 526
521 //========================== ResumeUploadRequestBase ========================= 527 //========================== ResumeUploadRequestBase =========================
522 528
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 download_action_callback_.Run(code, temp_file); 681 download_action_callback_.Run(code, temp_file);
676 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); 682 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS);
677 } 683 }
678 684
679 void DownloadFileRequestBase::RunCallbackOnPrematureFailure( 685 void DownloadFileRequestBase::RunCallbackOnPrematureFailure(
680 GDataErrorCode code) { 686 GDataErrorCode code) {
681 download_action_callback_.Run(code, base::FilePath()); 687 download_action_callback_.Run(code, base::FilePath());
682 } 688 }
683 689
684 } // namespace google_apis 690 } // namespace google_apis
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/google_apis/drive_api_requests_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698