| 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/gdata_wapi_operations.h" | 5 #include "chrome/browser/google_apis/gdata_wapi_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_wapi_parser.h" | 10 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 if (!download_action_callback_.is_null()) | 223 if (!download_action_callback_.is_null()) |
| 224 download_action_callback_.Run(code, FilePath()); | 224 download_action_callback_.Run(code, FilePath()); |
| 225 } | 225 } |
| 226 | 226 |
| 227 //=========================== DeleteDocumentOperation ========================== | 227 //=========================== DeleteDocumentOperation ========================== |
| 228 | 228 |
| 229 DeleteDocumentOperation::DeleteDocumentOperation( | 229 DeleteDocumentOperation::DeleteDocumentOperation( |
| 230 OperationRegistry* registry, | 230 OperationRegistry* registry, |
| 231 const EntryActionCallback& callback, | 231 const EntryActionCallback& callback, |
| 232 const GURL& document_url) | 232 const GURL& document_url) |
| 233 : EntryActionOperation(registry, callback, document_url) { | 233 : EntryActionOperation(registry, callback), |
| 234 document_url_(document_url) { |
| 234 } | 235 } |
| 235 | 236 |
| 236 DeleteDocumentOperation::~DeleteDocumentOperation() {} | 237 DeleteDocumentOperation::~DeleteDocumentOperation() {} |
| 237 | 238 |
| 238 GURL DeleteDocumentOperation::GetURL() const { | 239 GURL DeleteDocumentOperation::GetURL() const { |
| 239 return GDataWapiUrlGenerator::AddStandardUrlParams(document_url()); | 240 return GDataWapiUrlGenerator::AddStandardUrlParams(document_url_); |
| 240 } | 241 } |
| 241 | 242 |
| 242 URLFetcher::RequestType DeleteDocumentOperation::GetRequestType() const { | 243 URLFetcher::RequestType DeleteDocumentOperation::GetRequestType() const { |
| 243 return URLFetcher::DELETE_REQUEST; | 244 return URLFetcher::DELETE_REQUEST; |
| 244 } | 245 } |
| 245 | 246 |
| 246 std::vector<std::string> | 247 std::vector<std::string> |
| 247 DeleteDocumentOperation::GetExtraRequestHeaders() const { | 248 DeleteDocumentOperation::GetExtraRequestHeaders() const { |
| 248 std::vector<std::string> headers; | 249 std::vector<std::string> headers; |
| 249 headers.push_back(kIfMatchAllHeader); | 250 headers.push_back(kIfMatchAllHeader); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 return true; | 347 return true; |
| 347 } | 348 } |
| 348 | 349 |
| 349 //=========================== RenameResourceOperation ========================== | 350 //=========================== RenameResourceOperation ========================== |
| 350 | 351 |
| 351 RenameResourceOperation::RenameResourceOperation( | 352 RenameResourceOperation::RenameResourceOperation( |
| 352 OperationRegistry* registry, | 353 OperationRegistry* registry, |
| 353 const EntryActionCallback& callback, | 354 const EntryActionCallback& callback, |
| 354 const GURL& document_url, | 355 const GURL& document_url, |
| 355 const FilePath::StringType& new_name) | 356 const FilePath::StringType& new_name) |
| 356 : EntryActionOperation(registry, callback, document_url), | 357 : EntryActionOperation(registry, callback), |
| 358 document_url_(document_url), |
| 357 new_name_(new_name) { | 359 new_name_(new_name) { |
| 358 } | 360 } |
| 359 | 361 |
| 360 RenameResourceOperation::~RenameResourceOperation() {} | 362 RenameResourceOperation::~RenameResourceOperation() {} |
| 361 | 363 |
| 362 URLFetcher::RequestType RenameResourceOperation::GetRequestType() const { | 364 URLFetcher::RequestType RenameResourceOperation::GetRequestType() const { |
| 363 return URLFetcher::PUT; | 365 return URLFetcher::PUT; |
| 364 } | 366 } |
| 365 | 367 |
| 366 std::vector<std::string> | 368 std::vector<std::string> |
| 367 RenameResourceOperation::GetExtraRequestHeaders() const { | 369 RenameResourceOperation::GetExtraRequestHeaders() const { |
| 368 std::vector<std::string> headers; | 370 std::vector<std::string> headers; |
| 369 headers.push_back(kIfMatchAllHeader); | 371 headers.push_back(kIfMatchAllHeader); |
| 370 return headers; | 372 return headers; |
| 371 } | 373 } |
| 372 | 374 |
| 373 GURL RenameResourceOperation::GetURL() const { | 375 GURL RenameResourceOperation::GetURL() const { |
| 374 return GDataWapiUrlGenerator::AddStandardUrlParams(document_url()); | 376 return GDataWapiUrlGenerator::AddStandardUrlParams(document_url_); |
| 375 } | 377 } |
| 376 | 378 |
| 377 bool RenameResourceOperation::GetContentData(std::string* upload_content_type, | 379 bool RenameResourceOperation::GetContentData(std::string* upload_content_type, |
| 378 std::string* upload_content) { | 380 std::string* upload_content) { |
| 379 upload_content_type->assign("application/atom+xml"); | 381 upload_content_type->assign("application/atom+xml"); |
| 380 XmlWriter xml_writer; | 382 XmlWriter xml_writer; |
| 381 xml_writer.StartWriting(); | 383 xml_writer.StartWriting(); |
| 382 xml_writer.StartElement("entry"); | 384 xml_writer.StartElement("entry"); |
| 383 xml_writer.AddAttribute("xmlns", "http://www.w3.org/2005/Atom"); | 385 xml_writer.AddAttribute("xmlns", "http://www.w3.org/2005/Atom"); |
| 384 | 386 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 } | 493 } |
| 492 | 494 |
| 493 //======================= AddResourceToDirectoryOperation ====================== | 495 //======================= AddResourceToDirectoryOperation ====================== |
| 494 | 496 |
| 495 AddResourceToDirectoryOperation::AddResourceToDirectoryOperation( | 497 AddResourceToDirectoryOperation::AddResourceToDirectoryOperation( |
| 496 OperationRegistry* registry, | 498 OperationRegistry* registry, |
| 497 const GDataWapiUrlGenerator& url_generator, | 499 const GDataWapiUrlGenerator& url_generator, |
| 498 const EntryActionCallback& callback, | 500 const EntryActionCallback& callback, |
| 499 const GURL& parent_content_url, | 501 const GURL& parent_content_url, |
| 500 const GURL& document_url) | 502 const GURL& document_url) |
| 501 : EntryActionOperation(registry, callback, document_url), | 503 : EntryActionOperation(registry, callback), |
| 502 url_generator_(url_generator), | 504 url_generator_(url_generator), |
| 503 parent_content_url_(parent_content_url) { | 505 parent_content_url_(parent_content_url), |
| 506 document_url_(document_url) { |
| 504 } | 507 } |
| 505 | 508 |
| 506 AddResourceToDirectoryOperation::~AddResourceToDirectoryOperation() {} | 509 AddResourceToDirectoryOperation::~AddResourceToDirectoryOperation() {} |
| 507 | 510 |
| 508 GURL AddResourceToDirectoryOperation::GetURL() const { | 511 GURL AddResourceToDirectoryOperation::GetURL() const { |
| 509 if (!parent_content_url_.is_empty()) | 512 if (!parent_content_url_.is_empty()) |
| 510 return GDataWapiUrlGenerator::AddStandardUrlParams(parent_content_url_); | 513 return GDataWapiUrlGenerator::AddStandardUrlParams(parent_content_url_); |
| 511 | 514 |
| 512 return url_generator_.GenerateDocumentListRootUrl(); | 515 return url_generator_.GenerateDocumentListRootUrl(); |
| 513 } | 516 } |
| 514 | 517 |
| 515 URLFetcher::RequestType | 518 URLFetcher::RequestType |
| 516 AddResourceToDirectoryOperation::GetRequestType() const { | 519 AddResourceToDirectoryOperation::GetRequestType() const { |
| 517 return URLFetcher::POST; | 520 return URLFetcher::POST; |
| 518 } | 521 } |
| 519 | 522 |
| 520 bool AddResourceToDirectoryOperation::GetContentData( | 523 bool AddResourceToDirectoryOperation::GetContentData( |
| 521 std::string* upload_content_type, std::string* upload_content) { | 524 std::string* upload_content_type, std::string* upload_content) { |
| 522 upload_content_type->assign("application/atom+xml"); | 525 upload_content_type->assign("application/atom+xml"); |
| 523 XmlWriter xml_writer; | 526 XmlWriter xml_writer; |
| 524 xml_writer.StartWriting(); | 527 xml_writer.StartWriting(); |
| 525 xml_writer.StartElement("entry"); | 528 xml_writer.StartElement("entry"); |
| 526 xml_writer.AddAttribute("xmlns", "http://www.w3.org/2005/Atom"); | 529 xml_writer.AddAttribute("xmlns", "http://www.w3.org/2005/Atom"); |
| 527 | 530 |
| 528 xml_writer.WriteElement("id", document_url().spec()); | 531 xml_writer.WriteElement("id", document_url_.spec()); |
| 529 | 532 |
| 530 xml_writer.EndElement(); // Ends "entry" element. | 533 xml_writer.EndElement(); // Ends "entry" element. |
| 531 xml_writer.StopWriting(); | 534 xml_writer.StopWriting(); |
| 532 upload_content->assign(xml_writer.GetWrittenString()); | 535 upload_content->assign(xml_writer.GetWrittenString()); |
| 533 DVLOG(1) << "AddResourceToDirectoryOperation data: " << *upload_content_type | 536 DVLOG(1) << "AddResourceToDirectoryOperation data: " << *upload_content_type |
| 534 << ", [" << *upload_content << "]"; | 537 << ", [" << *upload_content << "]"; |
| 535 return true; | 538 return true; |
| 536 } | 539 } |
| 537 | 540 |
| 538 //==================== RemoveResourceFromDirectoryOperation ==================== | 541 //==================== RemoveResourceFromDirectoryOperation ==================== |
| 539 | 542 |
| 540 RemoveResourceFromDirectoryOperation::RemoveResourceFromDirectoryOperation( | 543 RemoveResourceFromDirectoryOperation::RemoveResourceFromDirectoryOperation( |
| 541 OperationRegistry* registry, | 544 OperationRegistry* registry, |
| 542 const EntryActionCallback& callback, | 545 const EntryActionCallback& callback, |
| 543 const GURL& parent_content_url, | 546 const GURL& parent_content_url, |
| 544 const GURL& document_url, | 547 const GURL& document_url, |
| 545 const std::string& document_resource_id) | 548 const std::string& document_resource_id) |
| 546 : EntryActionOperation(registry, callback, document_url), | 549 : EntryActionOperation(registry, callback), |
| 547 resource_id_(document_resource_id), | 550 resource_id_(document_resource_id), |
| 548 parent_content_url_(parent_content_url) { | 551 parent_content_url_(parent_content_url), |
| 552 document_url_(document_url) { |
| 549 } | 553 } |
| 550 | 554 |
| 551 RemoveResourceFromDirectoryOperation::~RemoveResourceFromDirectoryOperation() { | 555 RemoveResourceFromDirectoryOperation::~RemoveResourceFromDirectoryOperation() { |
| 552 } | 556 } |
| 553 | 557 |
| 554 GURL RemoveResourceFromDirectoryOperation::GetURL() const { | 558 GURL RemoveResourceFromDirectoryOperation::GetURL() const { |
| 555 std::string escaped_resource_id = net::EscapePath(resource_id_); | 559 std::string escaped_resource_id = net::EscapePath(resource_id_); |
| 556 GURL edit_url(base::StringPrintf("%s/%s", | 560 GURL edit_url(base::StringPrintf("%s/%s", |
| 557 parent_content_url_.spec().c_str(), | 561 parent_content_url_.spec().c_str(), |
| 558 escaped_resource_id.c_str())); | 562 escaped_resource_id.c_str())); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 return true; | 821 return true; |
| 818 } | 822 } |
| 819 | 823 |
| 820 void ResumeUploadOperation::OnURLFetchUploadProgress( | 824 void ResumeUploadOperation::OnURLFetchUploadProgress( |
| 821 const URLFetcher* source, int64 current, int64 total) { | 825 const URLFetcher* source, int64 current, int64 total) { |
| 822 // Adjust the progress values according to the range currently uploaded. | 826 // Adjust the progress values according to the range currently uploaded. |
| 823 NotifyProgress(params_.start_range + current, params_.content_length); | 827 NotifyProgress(params_.start_range + current, params_.content_length); |
| 824 } | 828 } |
| 825 | 829 |
| 826 } // namespace google_apis | 830 } // namespace google_apis |
| OLD | NEW |