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

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

Issue 12246002: Implement GetUploadStatusOperation on GData WAPI. (Closed) Base URL: http://git.chromium.org/chromium/src.git@b148632_create_base_operation
Patch Set: Rebase Created 7 years, 9 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 | « no previous file | chrome/browser/google_apis/gdata_wapi_operations.h » ('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_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"
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 return URLFetcher::PUT; 470 return URLFetcher::PUT;
471 } 471 }
472 472
473 void UploadRangeOperationBase::ProcessURLFetchResults( 473 void UploadRangeOperationBase::ProcessURLFetchResults(
474 const URLFetcher* source) { 474 const URLFetcher* source) {
475 GDataErrorCode code = GetErrorCode(source); 475 GDataErrorCode code = GetErrorCode(source);
476 net::HttpResponseHeaders* hdrs = source->GetResponseHeaders(); 476 net::HttpResponseHeaders* hdrs = source->GetResponseHeaders();
477 477
478 if (code == HTTP_RESUME_INCOMPLETE) { 478 if (code == HTTP_RESUME_INCOMPLETE) {
479 // Retrieve value of the first "Range" header. 479 // Retrieve value of the first "Range" header.
480 int64 start_position_received = -1; 480 // The Range header is appeared only if there is at least one received
481 int64 end_position_received = -1; 481 // byte. So, initialize the positions by 0 so that the [0,0) will be
482 // returned via the |callback_| for empty data case.
483 int64 start_position_received = 0;
484 int64 end_position_received = 0;
482 std::string range_received; 485 std::string range_received;
483 hdrs->EnumerateHeader(NULL, kUploadResponseRange, &range_received); 486 hdrs->EnumerateHeader(NULL, kUploadResponseRange, &range_received);
484 if (!range_received.empty()) { // Parse the range header. 487 if (!range_received.empty()) { // Parse the range header.
485 std::vector<net::HttpByteRange> ranges; 488 std::vector<net::HttpByteRange> ranges;
486 if (net::HttpUtil::ParseRangeHeader(range_received, &ranges) && 489 if (net::HttpUtil::ParseRangeHeader(range_received, &ranges) &&
487 !ranges.empty() ) { 490 !ranges.empty() ) {
488 // We only care about the first start-end pair in the range. 491 // We only care about the first start-end pair in the range.
489 // 492 //
490 // Range header represents the range inclusively, while we are treating 493 // Range header represents the range inclusively, while we are treating
491 // ranges exclusively (i.e., end_position_received should be one passed 494 // ranges exclusively (i.e., end_position_received should be one passed
492 // the last valid index). So "+ 1" is added. 495 // the last valid index). So "+ 1" is added.
493 start_position_received = ranges[0].first_byte_position(); 496 start_position_received = ranges[0].first_byte_position();
494 end_position_received = ranges[0].last_byte_position() + 1; 497 end_position_received = ranges[0].last_byte_position() + 1;
495 } 498 }
496 } 499 }
500 // The Range header has the received data range, so the start position
501 // should be always 0.
502 DCHECK_EQ(start_position_received, 0);
497 DVLOG(1) << "Got response for [" << drive_file_path_.value() 503 DVLOG(1) << "Got response for [" << drive_file_path_.value()
498 << "]: code=" << code 504 << "]: code=" << code
499 << ", range_hdr=[" << range_received 505 << ", range_hdr=[" << range_received
500 << "], range_parsed=" << start_position_received 506 << "], range_parsed=" << start_position_received
501 << "," << end_position_received; 507 << "," << end_position_received;
502 508
503 OnRangeOperationComplete(UploadRangeResponse(code, 509 OnRangeOperationComplete(UploadRangeResponse(code,
504 start_position_received, 510 start_position_received,
505 end_position_received), 511 end_position_received),
506 scoped_ptr<base::Value>()); 512 scoped_ptr<base::Value>());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 623
618 download_action_callback_.Run(code, temp_file); 624 download_action_callback_.Run(code, temp_file);
619 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); 625 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS);
620 } 626 }
621 627
622 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { 628 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) {
623 download_action_callback_.Run(code, base::FilePath()); 629 download_action_callback_.Run(code, base::FilePath());
624 } 630 }
625 631
626 } // namespace google_apis 632 } // namespace google_apis
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/google_apis/gdata_wapi_operations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698