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

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

Issue 11143014: Add request header on gdata operation for testing ETag match. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: +comment Created 8 years, 2 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/gdata_operations.h" 5 #include "chrome/browser/google_apis/gdata_operations.h"
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/google_apis/gdata_util.h" 10 #include "chrome/browser/google_apis/gdata_util.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 171
172 ResumeUploadResponse::~ResumeUploadResponse() { 172 ResumeUploadResponse::~ResumeUploadResponse() {
173 } 173 }
174 174
175 InitiateUploadParams::InitiateUploadParams( 175 InitiateUploadParams::InitiateUploadParams(
176 UploadMode upload_mode, 176 UploadMode upload_mode,
177 const std::string& title, 177 const std::string& title,
178 const std::string& content_type, 178 const std::string& content_type,
179 int64 content_length, 179 int64 content_length,
180 const GURL& upload_location, 180 const GURL& upload_location,
181 const FilePath& virtual_path) 181 const FilePath& virtual_path,
182 const std::string& etag)
182 : upload_mode(upload_mode), 183 : upload_mode(upload_mode),
183 title(title), 184 title(title),
184 content_type(content_type), 185 content_type(content_type),
185 content_length(content_length), 186 content_length(content_length),
186 upload_location(upload_location), 187 upload_location(upload_location),
187 virtual_path(virtual_path) { 188 virtual_path(virtual_path),
189 etag(etag) {
190 DCHECK(upload_mode == UPLOAD_NEW_FILE || upload_mode == UPLOAD_EXISTING_FILE);
191 DCHECK(upload_mode != UPLOAD_NEW_FILE || (!title.empty() && etag.empty()));
192 DCHECK(upload_mode != UPLOAD_EXISTING_FILE || title.empty());
188 } 193 }
189 194
190 InitiateUploadParams::~InitiateUploadParams() { 195 InitiateUploadParams::~InitiateUploadParams() {
191 } 196 }
192 197
193 ResumeUploadParams::ResumeUploadParams( 198 ResumeUploadParams::ResumeUploadParams(
194 UploadMode upload_mode, 199 UploadMode upload_mode,
195 int64 start_range, 200 int64 start_range,
196 int64 end_range, 201 int64 end_range,
197 int64 content_length, 202 int64 content_length,
198 const std::string& content_type, 203 const std::string& content_type,
199 scoped_refptr<net::IOBuffer> buf, 204 scoped_refptr<net::IOBuffer> buf,
200 const GURL& upload_location, 205 const GURL& upload_location,
201 const FilePath& virtual_path) : upload_mode(upload_mode), 206 const FilePath& virtual_path,
202 start_range(start_range), 207 const std::string& etag)
203 end_range(end_range), 208 : upload_mode(upload_mode),
204 content_length(content_length), 209 start_range(start_range),
205 content_type(content_type), 210 end_range(end_range),
206 buf(buf), 211 content_length(content_length),
207 upload_location(upload_location), 212 content_type(content_type),
208 virtual_path(virtual_path) { 213 buf(buf),
214 upload_location(upload_location),
215 virtual_path(virtual_path),
216 etag(etag) {
209 } 217 }
210 218
211 ResumeUploadParams::~ResumeUploadParams() { 219 ResumeUploadParams::~ResumeUploadParams() {
212 } 220 }
213 221
214 //============================ GetDocumentsOperation =========================== 222 //============================ GetDocumentsOperation ===========================
215 223
216 GetDocumentsOperation::GetDocumentsOperation( 224 GetDocumentsOperation::GetDocumentsOperation(
217 OperationRegistry* registry, 225 OperationRegistry* registry,
218 const GURL& url, 226 const GURL& url,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 293 }
286 294
287 //============================ DownloadFileOperation =========================== 295 //============================ DownloadFileOperation ===========================
288 296
289 DownloadFileOperation::DownloadFileOperation( 297 DownloadFileOperation::DownloadFileOperation(
290 OperationRegistry* registry, 298 OperationRegistry* registry,
291 const DownloadActionCallback& download_action_callback, 299 const DownloadActionCallback& download_action_callback,
292 const GetContentCallback& get_content_callback, 300 const GetContentCallback& get_content_callback,
293 const GURL& document_url, 301 const GURL& document_url,
294 const FilePath& virtual_path, 302 const FilePath& virtual_path,
295 const FilePath& output_file_path) 303 const FilePath& output_file_path,
304 const std::string& etag)
296 : UrlFetchOperationBase(registry, 305 : UrlFetchOperationBase(registry,
297 OPERATION_DOWNLOAD, 306 OPERATION_DOWNLOAD,
298 virtual_path), 307 virtual_path),
299 download_action_callback_(download_action_callback), 308 download_action_callback_(download_action_callback),
300 get_content_callback_(get_content_callback), 309 get_content_callback_(get_content_callback),
301 document_url_(document_url) { 310 document_url_(document_url),
311 etag_(etag) {
302 // Make sure we download the content into a temp file. 312 // Make sure we download the content into a temp file.
303 if (output_file_path.empty()) 313 if (output_file_path.empty())
304 save_temp_file_ = true; 314 save_temp_file_ = true;
305 else 315 else
306 output_file_path_ = output_file_path; 316 output_file_path_ = output_file_path;
307 } 317 }
308 318
309 DownloadFileOperation::~DownloadFileOperation() {} 319 DownloadFileOperation::~DownloadFileOperation() {}
310 320
311 // Overridden from UrlFetchOperationBase. 321 // Overridden from UrlFetchOperationBase.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 if (!download_action_callback_.is_null()) 354 if (!download_action_callback_.is_null())
345 download_action_callback_.Run(code, document_url_, temp_file); 355 download_action_callback_.Run(code, document_url_, temp_file);
346 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); 356 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS);
347 } 357 }
348 358
349 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { 359 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) {
350 if (!download_action_callback_.is_null()) 360 if (!download_action_callback_.is_null())
351 download_action_callback_.Run(code, document_url_, FilePath()); 361 download_action_callback_.Run(code, document_url_, FilePath());
352 } 362 }
353 363
364 std::vector<std::string> DownloadFileOperation::GetExtraRequestHeaders() const {
365 std::vector<std::string> headers;
366 if (!etag_.empty())
367 headers.push_back(base::StringPrintf(kIfMatchHeaderFormat, etag_.c_str()));
368 return headers;
369 }
370
354 //=========================== DeleteDocumentOperation ========================== 371 //=========================== DeleteDocumentOperation ==========================
355 372
356 DeleteDocumentOperation::DeleteDocumentOperation( 373 DeleteDocumentOperation::DeleteDocumentOperation(
357 OperationRegistry* registry, 374 OperationRegistry* registry,
358 const EntryActionCallback& callback, 375 const EntryActionCallback& callback,
359 const GURL& document_url) 376 const GURL& document_url,
360 : EntryActionOperation(registry, callback, document_url) { 377 const std::string& etag)
378 : EntryActionOperation(registry, callback, document_url),
379 etag_(etag) {
361 } 380 }
362 381
363 DeleteDocumentOperation::~DeleteDocumentOperation() {} 382 DeleteDocumentOperation::~DeleteDocumentOperation() {}
364 383
365 GURL DeleteDocumentOperation::GetURL() const { 384 GURL DeleteDocumentOperation::GetURL() const {
366 return AddStandardUrlParams(document_url()); 385 return AddStandardUrlParams(document_url());
367 } 386 }
368 387
369 URLFetcher::RequestType DeleteDocumentOperation::GetRequestType() const { 388 URLFetcher::RequestType DeleteDocumentOperation::GetRequestType() const {
370 return URLFetcher::DELETE_REQUEST; 389 return URLFetcher::DELETE_REQUEST;
371 } 390 }
372 391
373 std::vector<std::string> 392 std::vector<std::string>
374 DeleteDocumentOperation::GetExtraRequestHeaders() const { 393 DeleteDocumentOperation::GetExtraRequestHeaders() const {
375 std::vector<std::string> headers; 394 std::vector<std::string> headers;
376 headers.push_back(kIfMatchAllHeader); 395 if (etag_.empty())
396 headers.push_back(kIfMatchAllHeader);
397 else
398 headers.push_back(base::StringPrintf(kIfMatchHeaderFormat, etag_.c_str()));
377 return headers; 399 return headers;
378 } 400 }
379 401
380 //========================== CreateDirectoryOperation ========================== 402 //========================== CreateDirectoryOperation ==========================
381 403
382 CreateDirectoryOperation::CreateDirectoryOperation( 404 CreateDirectoryOperation::CreateDirectoryOperation(
383 OperationRegistry* registry, 405 OperationRegistry* registry,
384 const GetDataCallback& callback, 406 const GetDataCallback& callback,
385 const GURL& parent_content_url, 407 const GURL& parent_content_url,
386 const FilePath::StringType& directory_name) 408 const FilePath::StringType& directory_name)
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 768
747 std::vector<std::string> 769 std::vector<std::string>
748 InitiateUploadOperation::GetExtraRequestHeaders() const { 770 InitiateUploadOperation::GetExtraRequestHeaders() const {
749 std::vector<std::string> headers; 771 std::vector<std::string> headers;
750 if (!params_.content_type.empty()) 772 if (!params_.content_type.empty())
751 headers.push_back(kUploadContentType + params_.content_type); 773 headers.push_back(kUploadContentType + params_.content_type);
752 774
753 headers.push_back( 775 headers.push_back(
754 kUploadContentLength + base::Int64ToString(params_.content_length)); 776 kUploadContentLength + base::Int64ToString(params_.content_length));
755 777
756 if (params_.upload_mode == UPLOAD_EXISTING_FILE) 778 if (params_.upload_mode == UPLOAD_EXISTING_FILE) {
757 headers.push_back("If-Match: *"); 779 if (params_.etag.empty()) {
780 headers.push_back(kIfMatchAllHeader);
781 } else {
782 headers.push_back(
783 base::StringPrintf(kIfMatchHeaderFormat, params_.etag.c_str()));
784 }
785 }
758 786
759 return headers; 787 return headers;
760 } 788 }
761 789
762 bool InitiateUploadOperation::GetContentData(std::string* upload_content_type, 790 bool InitiateUploadOperation::GetContentData(std::string* upload_content_type,
763 std::string* upload_content) { 791 std::string* upload_content) {
764 if (params_.upload_mode == UPLOAD_EXISTING_FILE) { 792 if (params_.upload_mode == UPLOAD_EXISTING_FILE) {
765 // When uploading an existing file, the body is empty as we don't modify 793 // When uploading an existing file, the body is empty as we don't modify
766 // the metadata. 794 // the metadata.
767 *upload_content = ""; 795 *upload_content = "";
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 scoped_ptr<DocumentEntry> entry; 916 scoped_ptr<DocumentEntry> entry;
889 if (!callback_.is_null()) 917 if (!callback_.is_null())
890 callback_.Run(ResumeUploadResponse(code, 0, 0), entry.Pass()); 918 callback_.Run(ResumeUploadResponse(code, 0, 0), entry.Pass());
891 } 919 }
892 920
893 URLFetcher::RequestType ResumeUploadOperation::GetRequestType() const { 921 URLFetcher::RequestType ResumeUploadOperation::GetRequestType() const {
894 return URLFetcher::PUT; 922 return URLFetcher::PUT;
895 } 923 }
896 924
897 std::vector<std::string> ResumeUploadOperation::GetExtraRequestHeaders() const { 925 std::vector<std::string> ResumeUploadOperation::GetExtraRequestHeaders() const {
926 std::vector<std::string> headers;
927
928 if (params_.etag.empty()) {
929 headers.push_back(kIfMatchAllHeader);
930 } else {
931 headers.push_back(
932 base::StringPrintf(kIfMatchHeaderFormat, params_.etag.c_str()));
933 }
934
898 if (params_.content_length == 0) { 935 if (params_.content_length == 0) {
899 // For uploading an empty document, just PUT an empty content. 936 // For uploading an empty document, just PUT an empty content.
900 DCHECK_EQ(params_.start_range, 0); 937 DCHECK_EQ(params_.start_range, 0);
901 DCHECK_EQ(params_.end_range, -1); 938 DCHECK_EQ(params_.end_range, -1);
902 return std::vector<std::string>(); 939 return headers;
903 } 940 }
904 941
905 // The header looks like 942 // The header looks like
906 // Content-Range: bytes <start_range>-<end_range>/<content_length> 943 // Content-Range: bytes <start_range>-<end_range>/<content_length>
907 // for example: 944 // for example:
908 // Content-Range: bytes 7864320-8388607/13851821 945 // Content-Range: bytes 7864320-8388607/13851821
909 // Use * for unknown/streaming content length. 946 // Use * for unknown/streaming content length.
910 DCHECK_GE(params_.start_range, 0); 947 DCHECK_GE(params_.start_range, 0);
911 DCHECK_GE(params_.end_range, 0); 948 DCHECK_GE(params_.end_range, 0);
912 DCHECK_GE(params_.content_length, -1); 949 DCHECK_GE(params_.content_length, -1);
913 950
914 std::vector<std::string> headers;
915 headers.push_back( 951 headers.push_back(
916 std::string(kUploadContentRange) + 952 std::string(kUploadContentRange) +
917 base::Int64ToString(params_.start_range) + "-" + 953 base::Int64ToString(params_.start_range) + "-" +
918 base::Int64ToString(params_.end_range) + "/" + 954 base::Int64ToString(params_.end_range) + "/" +
919 (params_.content_length == -1 ? "*" : 955 (params_.content_length == -1 ? "*" :
920 base::Int64ToString(params_.content_length))); 956 base::Int64ToString(params_.content_length)));
921 return headers; 957 return headers;
922 } 958 }
923 959
924 bool ResumeUploadOperation::GetContentData(std::string* upload_content_type, 960 bool ResumeUploadOperation::GetContentData(std::string* upload_content_type,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); 1044 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS);
1009 } 1045 }
1010 1046
1011 void GetContactPhotoOperation::RunCallbackOnPrematureFailure( 1047 void GetContactPhotoOperation::RunCallbackOnPrematureFailure(
1012 GDataErrorCode code) { 1048 GDataErrorCode code) {
1013 scoped_ptr<std::string> data(new std::string); 1049 scoped_ptr<std::string> data(new std::string);
1014 callback_.Run(code, data.Pass()); 1050 callback_.Run(code, data.Pass());
1015 } 1051 }
1016 1052
1017 } // namespace gdata 1053 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698