| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 virtual_path(virtual_path) { | 90 virtual_path(virtual_path) { |
| 91 } | 91 } |
| 92 | 92 |
| 93 ResumeUploadParams::~ResumeUploadParams() { | 93 ResumeUploadParams::~ResumeUploadParams() { |
| 94 } | 94 } |
| 95 | 95 |
| 96 //============================ GetDocumentsOperation =========================== | 96 //============================ GetDocumentsOperation =========================== |
| 97 | 97 |
| 98 GetDocumentsOperation::GetDocumentsOperation( | 98 GetDocumentsOperation::GetDocumentsOperation( |
| 99 OperationRegistry* registry, | 99 OperationRegistry* registry, |
| 100 const GDataWapiUrlGenerator& url_generator, |
| 100 const GURL& url, | 101 const GURL& url, |
| 101 int start_changestamp, | 102 int start_changestamp, |
| 102 const std::string& search_string, | 103 const std::string& search_string, |
| 103 bool shared_with_me, | 104 bool shared_with_me, |
| 104 const std::string& directory_resource_id, | 105 const std::string& directory_resource_id, |
| 105 const GetDataCallback& callback) | 106 const GetDataCallback& callback) |
| 106 : GetDataOperation(registry, callback), | 107 : GetDataOperation(registry, callback), |
| 108 url_generator_(url_generator), |
| 107 override_url_(url), | 109 override_url_(url), |
| 108 start_changestamp_(start_changestamp), | 110 start_changestamp_(start_changestamp), |
| 109 search_string_(search_string), | 111 search_string_(search_string), |
| 110 shared_with_me_(shared_with_me), | 112 shared_with_me_(shared_with_me), |
| 111 directory_resource_id_(directory_resource_id) { | 113 directory_resource_id_(directory_resource_id) { |
| 112 } | 114 } |
| 113 | 115 |
| 114 GetDocumentsOperation::~GetDocumentsOperation() {} | 116 GetDocumentsOperation::~GetDocumentsOperation() {} |
| 115 | 117 |
| 116 GURL GetDocumentsOperation::GetURL() const { | 118 GURL GetDocumentsOperation::GetURL() const { |
| 117 return gdata_wapi_url_util::GenerateDocumentListUrl(override_url_, | 119 return url_generator_.GenerateDocumentListUrl(override_url_, |
| 118 start_changestamp_, | 120 start_changestamp_, |
| 119 search_string_, | 121 search_string_, |
| 120 shared_with_me_, | 122 shared_with_me_, |
| 121 directory_resource_id_); | 123 directory_resource_id_); |
| 122 } | 124 } |
| 123 | 125 |
| 124 //============================ GetDocumentEntryOperation ======================= | 126 //============================ GetDocumentEntryOperation ======================= |
| 125 | 127 |
| 126 GetDocumentEntryOperation::GetDocumentEntryOperation( | 128 GetDocumentEntryOperation::GetDocumentEntryOperation( |
| 127 OperationRegistry* registry, | 129 OperationRegistry* registry, |
| 130 const GDataWapiUrlGenerator& url_generator, |
| 128 const std::string& resource_id, | 131 const std::string& resource_id, |
| 129 const GetDataCallback& callback) | 132 const GetDataCallback& callback) |
| 130 : GetDataOperation(registry, callback), | 133 : GetDataOperation(registry, callback), |
| 134 url_generator_(url_generator), |
| 131 resource_id_(resource_id) { | 135 resource_id_(resource_id) { |
| 132 } | 136 } |
| 133 | 137 |
| 134 GetDocumentEntryOperation::~GetDocumentEntryOperation() {} | 138 GetDocumentEntryOperation::~GetDocumentEntryOperation() {} |
| 135 | 139 |
| 136 GURL GetDocumentEntryOperation::GetURL() const { | 140 GURL GetDocumentEntryOperation::GetURL() const { |
| 137 return gdata_wapi_url_util::GenerateDocumentEntryUrl(resource_id_); | 141 return url_generator_.GenerateDocumentEntryUrl(resource_id_); |
| 138 } | 142 } |
| 139 | 143 |
| 140 //========================= GetAccountMetadataOperation ======================== | 144 //========================= GetAccountMetadataOperation ======================== |
| 141 | 145 |
| 142 GetAccountMetadataOperation::GetAccountMetadataOperation( | 146 GetAccountMetadataOperation::GetAccountMetadataOperation( |
| 143 OperationRegistry* registry, | 147 OperationRegistry* registry, |
| 148 const GDataWapiUrlGenerator& url_generator, |
| 144 const GetDataCallback& callback) | 149 const GetDataCallback& callback) |
| 145 : GetDataOperation(registry, callback) { | 150 : GetDataOperation(registry, callback), |
| 151 url_generator_(url_generator) { |
| 146 } | 152 } |
| 147 | 153 |
| 148 GetAccountMetadataOperation::~GetAccountMetadataOperation() {} | 154 GetAccountMetadataOperation::~GetAccountMetadataOperation() {} |
| 149 | 155 |
| 150 GURL GetAccountMetadataOperation::GetURL() const { | 156 GURL GetAccountMetadataOperation::GetURL() const { |
| 151 return gdata_wapi_url_util::GenerateAccountMetadataUrl(); | 157 return url_generator_.GenerateAccountMetadataUrl(); |
| 152 } | 158 } |
| 153 | 159 |
| 154 //============================ DownloadFileOperation =========================== | 160 //============================ DownloadFileOperation =========================== |
| 155 | 161 |
| 156 DownloadFileOperation::DownloadFileOperation( | 162 DownloadFileOperation::DownloadFileOperation( |
| 157 OperationRegistry* registry, | 163 OperationRegistry* registry, |
| 158 const DownloadActionCallback& download_action_callback, | 164 const DownloadActionCallback& download_action_callback, |
| 159 const GetContentCallback& get_content_callback, | 165 const GetContentCallback& get_content_callback, |
| 160 const GURL& document_url, | 166 const GURL& document_url, |
| 161 const FilePath& virtual_path, | 167 const FilePath& virtual_path, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 DeleteDocumentOperation::GetExtraRequestHeaders() const { | 247 DeleteDocumentOperation::GetExtraRequestHeaders() const { |
| 242 std::vector<std::string> headers; | 248 std::vector<std::string> headers; |
| 243 headers.push_back(kIfMatchAllHeader); | 249 headers.push_back(kIfMatchAllHeader); |
| 244 return headers; | 250 return headers; |
| 245 } | 251 } |
| 246 | 252 |
| 247 //========================== CreateDirectoryOperation ========================== | 253 //========================== CreateDirectoryOperation ========================== |
| 248 | 254 |
| 249 CreateDirectoryOperation::CreateDirectoryOperation( | 255 CreateDirectoryOperation::CreateDirectoryOperation( |
| 250 OperationRegistry* registry, | 256 OperationRegistry* registry, |
| 257 const GDataWapiUrlGenerator& url_generator, |
| 251 const GetDataCallback& callback, | 258 const GetDataCallback& callback, |
| 252 const GURL& parent_content_url, | 259 const GURL& parent_content_url, |
| 253 const FilePath::StringType& directory_name) | 260 const FilePath::StringType& directory_name) |
| 254 : GetDataOperation(registry, callback), | 261 : GetDataOperation(registry, callback), |
| 262 url_generator_(url_generator), |
| 255 parent_content_url_(parent_content_url), | 263 parent_content_url_(parent_content_url), |
| 256 directory_name_(directory_name) { | 264 directory_name_(directory_name) { |
| 257 } | 265 } |
| 258 | 266 |
| 259 CreateDirectoryOperation::~CreateDirectoryOperation() {} | 267 CreateDirectoryOperation::~CreateDirectoryOperation() {} |
| 260 | 268 |
| 261 GURL CreateDirectoryOperation::GetURL() const { | 269 GURL CreateDirectoryOperation::GetURL() const { |
| 262 if (!parent_content_url_.is_empty()) | 270 if (!parent_content_url_.is_empty()) |
| 263 return gdata_wapi_url_util::AddStandardUrlParams(parent_content_url_); | 271 return gdata_wapi_url_util::AddStandardUrlParams(parent_content_url_); |
| 264 | 272 |
| 265 return gdata_wapi_url_util::GenerateDocumentListRootUrl(); | 273 return url_generator_.GenerateDocumentListRootUrl(); |
| 266 } | 274 } |
| 267 | 275 |
| 268 URLFetcher::RequestType | 276 URLFetcher::RequestType |
| 269 CreateDirectoryOperation::GetRequestType() const { | 277 CreateDirectoryOperation::GetRequestType() const { |
| 270 return URLFetcher::POST; | 278 return URLFetcher::POST; |
| 271 } | 279 } |
| 272 | 280 |
| 273 bool CreateDirectoryOperation::GetContentData(std::string* upload_content_type, | 281 bool CreateDirectoryOperation::GetContentData(std::string* upload_content_type, |
| 274 std::string* upload_content) { | 282 std::string* upload_content) { |
| 275 upload_content_type->assign("application/atom+xml"); | 283 upload_content_type->assign("application/atom+xml"); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 292 upload_content->assign(xml_writer.GetWrittenString()); | 300 upload_content->assign(xml_writer.GetWrittenString()); |
| 293 DVLOG(1) << "CreateDirectory data: " << *upload_content_type << ", [" | 301 DVLOG(1) << "CreateDirectory data: " << *upload_content_type << ", [" |
| 294 << *upload_content << "]"; | 302 << *upload_content << "]"; |
| 295 return true; | 303 return true; |
| 296 } | 304 } |
| 297 | 305 |
| 298 //============================ CopyDocumentOperation =========================== | 306 //============================ CopyDocumentOperation =========================== |
| 299 | 307 |
| 300 CopyDocumentOperation::CopyDocumentOperation( | 308 CopyDocumentOperation::CopyDocumentOperation( |
| 301 OperationRegistry* registry, | 309 OperationRegistry* registry, |
| 310 const GDataWapiUrlGenerator& url_generator, |
| 302 const GetDataCallback& callback, | 311 const GetDataCallback& callback, |
| 303 const std::string& resource_id, | 312 const std::string& resource_id, |
| 304 const FilePath::StringType& new_name) | 313 const FilePath::StringType& new_name) |
| 305 : GetDataOperation(registry, callback), | 314 : GetDataOperation(registry, callback), |
| 315 url_generator_(url_generator), |
| 306 resource_id_(resource_id), | 316 resource_id_(resource_id), |
| 307 new_name_(new_name) { | 317 new_name_(new_name) { |
| 308 } | 318 } |
| 309 | 319 |
| 310 CopyDocumentOperation::~CopyDocumentOperation() {} | 320 CopyDocumentOperation::~CopyDocumentOperation() {} |
| 311 | 321 |
| 312 URLFetcher::RequestType CopyDocumentOperation::GetRequestType() const { | 322 URLFetcher::RequestType CopyDocumentOperation::GetRequestType() const { |
| 313 return URLFetcher::POST; | 323 return URLFetcher::POST; |
| 314 } | 324 } |
| 315 | 325 |
| 316 GURL CopyDocumentOperation::GetURL() const { | 326 GURL CopyDocumentOperation::GetURL() const { |
| 317 return gdata_wapi_url_util::GenerateDocumentListRootUrl(); | 327 return url_generator_.GenerateDocumentListRootUrl(); |
| 318 } | 328 } |
| 319 | 329 |
| 320 bool CopyDocumentOperation::GetContentData(std::string* upload_content_type, | 330 bool CopyDocumentOperation::GetContentData(std::string* upload_content_type, |
| 321 std::string* upload_content) { | 331 std::string* upload_content) { |
| 322 upload_content_type->assign("application/atom+xml"); | 332 upload_content_type->assign("application/atom+xml"); |
| 323 XmlWriter xml_writer; | 333 XmlWriter xml_writer; |
| 324 xml_writer.StartWriting(); | 334 xml_writer.StartWriting(); |
| 325 xml_writer.StartElement("entry"); | 335 xml_writer.StartElement("entry"); |
| 326 xml_writer.AddAttribute("xmlns", "http://www.w3.org/2005/Atom"); | 336 xml_writer.AddAttribute("xmlns", "http://www.w3.org/2005/Atom"); |
| 327 | 337 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } | 478 } |
| 469 | 479 |
| 470 GURL AuthorizeAppsOperation::GetURL() const { | 480 GURL AuthorizeAppsOperation::GetURL() const { |
| 471 return document_url_; | 481 return document_url_; |
| 472 } | 482 } |
| 473 | 483 |
| 474 //======================= AddResourceToDirectoryOperation ====================== | 484 //======================= AddResourceToDirectoryOperation ====================== |
| 475 | 485 |
| 476 AddResourceToDirectoryOperation::AddResourceToDirectoryOperation( | 486 AddResourceToDirectoryOperation::AddResourceToDirectoryOperation( |
| 477 OperationRegistry* registry, | 487 OperationRegistry* registry, |
| 488 const GDataWapiUrlGenerator& url_generator, |
| 478 const EntryActionCallback& callback, | 489 const EntryActionCallback& callback, |
| 479 const GURL& parent_content_url, | 490 const GURL& parent_content_url, |
| 480 const GURL& document_url) | 491 const GURL& document_url) |
| 481 : EntryActionOperation(registry, callback, document_url), | 492 : EntryActionOperation(registry, callback, document_url), |
| 493 url_generator_(url_generator), |
| 482 parent_content_url_(parent_content_url) { | 494 parent_content_url_(parent_content_url) { |
| 483 } | 495 } |
| 484 | 496 |
| 485 AddResourceToDirectoryOperation::~AddResourceToDirectoryOperation() {} | 497 AddResourceToDirectoryOperation::~AddResourceToDirectoryOperation() {} |
| 486 | 498 |
| 487 GURL AddResourceToDirectoryOperation::GetURL() const { | 499 GURL AddResourceToDirectoryOperation::GetURL() const { |
| 488 if (!parent_content_url_.is_empty()) | 500 if (!parent_content_url_.is_empty()) |
| 489 return gdata_wapi_url_util::AddStandardUrlParams(parent_content_url_); | 501 return gdata_wapi_url_util::AddStandardUrlParams(parent_content_url_); |
| 490 | 502 |
| 491 return gdata_wapi_url_util::GenerateDocumentListRootUrl(); | 503 return url_generator_.GenerateDocumentListRootUrl(); |
| 492 } | 504 } |
| 493 | 505 |
| 494 URLFetcher::RequestType | 506 URLFetcher::RequestType |
| 495 AddResourceToDirectoryOperation::GetRequestType() const { | 507 AddResourceToDirectoryOperation::GetRequestType() const { |
| 496 return URLFetcher::POST; | 508 return URLFetcher::POST; |
| 497 } | 509 } |
| 498 | 510 |
| 499 bool AddResourceToDirectoryOperation::GetContentData( | 511 bool AddResourceToDirectoryOperation::GetContentData( |
| 500 std::string* upload_content_type, std::string* upload_content) { | 512 std::string* upload_content_type, std::string* upload_content) { |
| 501 upload_content_type->assign("application/atom+xml"); | 513 upload_content_type->assign("application/atom+xml"); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 return true; | 808 return true; |
| 797 } | 809 } |
| 798 | 810 |
| 799 void ResumeUploadOperation::OnURLFetchUploadProgress( | 811 void ResumeUploadOperation::OnURLFetchUploadProgress( |
| 800 const URLFetcher* source, int64 current, int64 total) { | 812 const URLFetcher* source, int64 current, int64 total) { |
| 801 // Adjust the progress values according to the range currently uploaded. | 813 // Adjust the progress values according to the range currently uploaded. |
| 802 NotifyProgress(params_.start_range + current, params_.content_length); | 814 NotifyProgress(params_.start_range + current, params_.content_length); |
| 803 } | 815 } |
| 804 | 816 |
| 805 } // namespace google_apis | 817 } // namespace google_apis |
| OLD | NEW |