| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 GetDocumentsOperation::~GetDocumentsOperation() {} | 124 GetDocumentsOperation::~GetDocumentsOperation() {} |
| 125 | 125 |
| 126 GURL GetDocumentsOperation::GetURL() const { | 126 GURL GetDocumentsOperation::GetURL() const { |
| 127 return url_generator_.GenerateDocumentListUrl(override_url_, | 127 return url_generator_.GenerateDocumentListUrl(override_url_, |
| 128 start_changestamp_, | 128 start_changestamp_, |
| 129 search_string_, | 129 search_string_, |
| 130 shared_with_me_, | 130 shared_with_me_, |
| 131 directory_resource_id_); | 131 directory_resource_id_); |
| 132 } | 132 } |
| 133 | 133 |
| 134 //============================ GetDocumentEntryOperation ======================= | 134 //============================ GetResourceEntryOperation ======================= |
| 135 | 135 |
| 136 GetDocumentEntryOperation::GetDocumentEntryOperation( | 136 GetResourceEntryOperation::GetResourceEntryOperation( |
| 137 OperationRegistry* registry, | 137 OperationRegistry* registry, |
| 138 net::URLRequestContextGetter* url_request_context_getter, | 138 net::URLRequestContextGetter* url_request_context_getter, |
| 139 const GDataWapiUrlGenerator& url_generator, | 139 const GDataWapiUrlGenerator& url_generator, |
| 140 const std::string& resource_id, | 140 const std::string& resource_id, |
| 141 const GetDataCallback& callback) | 141 const GetDataCallback& callback) |
| 142 : GetDataOperation(registry, url_request_context_getter, callback), | 142 : GetDataOperation(registry, url_request_context_getter, callback), |
| 143 url_generator_(url_generator), | 143 url_generator_(url_generator), |
| 144 resource_id_(resource_id) { | 144 resource_id_(resource_id) { |
| 145 DCHECK(!callback.is_null()); | 145 DCHECK(!callback.is_null()); |
| 146 } | 146 } |
| 147 | 147 |
| 148 GetDocumentEntryOperation::~GetDocumentEntryOperation() {} | 148 GetResourceEntryOperation::~GetResourceEntryOperation() {} |
| 149 | 149 |
| 150 GURL GetDocumentEntryOperation::GetURL() const { | 150 GURL GetResourceEntryOperation::GetURL() const { |
| 151 return url_generator_.GenerateDocumentEntryUrl(resource_id_); | 151 return url_generator_.GenerateDocumentEntryUrl(resource_id_); |
| 152 } | 152 } |
| 153 | 153 |
| 154 //========================= GetAccountMetadataOperation ======================== | 154 //========================= GetAccountMetadataOperation ======================== |
| 155 | 155 |
| 156 GetAccountMetadataOperation::GetAccountMetadataOperation( | 156 GetAccountMetadataOperation::GetAccountMetadataOperation( |
| 157 OperationRegistry* registry, | 157 OperationRegistry* registry, |
| 158 net::URLRequestContextGetter* url_request_context_getter, | 158 net::URLRequestContextGetter* url_request_context_getter, |
| 159 const GDataWapiUrlGenerator& url_generator, | 159 const GDataWapiUrlGenerator& url_generator, |
| 160 const GetDataCallback& callback) | 160 const GetDataCallback& callback) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 232 } |
| 233 | 233 |
| 234 download_action_callback_.Run(code, temp_file); | 234 download_action_callback_.Run(code, temp_file); |
| 235 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); | 235 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { | 238 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { |
| 239 download_action_callback_.Run(code, FilePath()); | 239 download_action_callback_.Run(code, FilePath()); |
| 240 } | 240 } |
| 241 | 241 |
| 242 //=========================== DeleteDocumentOperation ========================== | 242 //=========================== DeleteResourceOperation ========================== |
| 243 | 243 |
| 244 DeleteDocumentOperation::DeleteDocumentOperation( | 244 DeleteResourceOperation::DeleteResourceOperation( |
| 245 OperationRegistry* registry, | 245 OperationRegistry* registry, |
| 246 net::URLRequestContextGetter* url_request_context_getter, | 246 net::URLRequestContextGetter* url_request_context_getter, |
| 247 const EntryActionCallback& callback, | 247 const EntryActionCallback& callback, |
| 248 const GURL& edit_url) | 248 const GURL& edit_url) |
| 249 : EntryActionOperation(registry, url_request_context_getter, callback), | 249 : EntryActionOperation(registry, url_request_context_getter, callback), |
| 250 edit_url_(edit_url) { | 250 edit_url_(edit_url) { |
| 251 DCHECK(!callback.is_null()); | 251 DCHECK(!callback.is_null()); |
| 252 } | 252 } |
| 253 | 253 |
| 254 DeleteDocumentOperation::~DeleteDocumentOperation() {} | 254 DeleteResourceOperation::~DeleteResourceOperation() {} |
| 255 | 255 |
| 256 GURL DeleteDocumentOperation::GetURL() const { | 256 GURL DeleteResourceOperation::GetURL() const { |
| 257 return GDataWapiUrlGenerator::AddStandardUrlParams(edit_url_); | 257 return GDataWapiUrlGenerator::AddStandardUrlParams(edit_url_); |
| 258 } | 258 } |
| 259 | 259 |
| 260 URLFetcher::RequestType DeleteDocumentOperation::GetRequestType() const { | 260 URLFetcher::RequestType DeleteResourceOperation::GetRequestType() const { |
| 261 return URLFetcher::DELETE_REQUEST; | 261 return URLFetcher::DELETE_REQUEST; |
| 262 } | 262 } |
| 263 | 263 |
| 264 std::vector<std::string> | 264 std::vector<std::string> |
| 265 DeleteDocumentOperation::GetExtraRequestHeaders() const { | 265 DeleteResourceOperation::GetExtraRequestHeaders() const { |
| 266 std::vector<std::string> headers; | 266 std::vector<std::string> headers; |
| 267 headers.push_back(kIfMatchAllHeader); | 267 headers.push_back(kIfMatchAllHeader); |
| 268 return headers; | 268 return headers; |
| 269 } | 269 } |
| 270 | 270 |
| 271 //========================== CreateDirectoryOperation ========================== | 271 //========================== CreateDirectoryOperation ========================== |
| 272 | 272 |
| 273 CreateDirectoryOperation::CreateDirectoryOperation( | 273 CreateDirectoryOperation::CreateDirectoryOperation( |
| 274 OperationRegistry* registry, | 274 OperationRegistry* registry, |
| 275 net::URLRequestContextGetter* url_request_context_getter, | 275 net::URLRequestContextGetter* url_request_context_getter, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 xml_writer.WriteElement("title", FilePath(directory_name_).AsUTF8Unsafe()); | 316 xml_writer.WriteElement("title", FilePath(directory_name_).AsUTF8Unsafe()); |
| 317 | 317 |
| 318 xml_writer.EndElement(); // Ends "entry" element. | 318 xml_writer.EndElement(); // Ends "entry" element. |
| 319 xml_writer.StopWriting(); | 319 xml_writer.StopWriting(); |
| 320 upload_content->assign(xml_writer.GetWrittenString()); | 320 upload_content->assign(xml_writer.GetWrittenString()); |
| 321 DVLOG(1) << "CreateDirectory data: " << *upload_content_type << ", [" | 321 DVLOG(1) << "CreateDirectory data: " << *upload_content_type << ", [" |
| 322 << *upload_content << "]"; | 322 << *upload_content << "]"; |
| 323 return true; | 323 return true; |
| 324 } | 324 } |
| 325 | 325 |
| 326 //============================ CopyDocumentOperation =========================== | 326 //============================ CopyHostedDocumentOperation ===================== |
| 327 | 327 |
| 328 CopyDocumentOperation::CopyDocumentOperation( | 328 CopyHostedDocumentOperation::CopyHostedDocumentOperation( |
| 329 OperationRegistry* registry, | 329 OperationRegistry* registry, |
| 330 net::URLRequestContextGetter* url_request_context_getter, | 330 net::URLRequestContextGetter* url_request_context_getter, |
| 331 const GDataWapiUrlGenerator& url_generator, | 331 const GDataWapiUrlGenerator& url_generator, |
| 332 const GetDataCallback& callback, | 332 const GetDataCallback& callback, |
| 333 const std::string& resource_id, | 333 const std::string& resource_id, |
| 334 const FilePath::StringType& new_name) | 334 const FilePath::StringType& new_name) |
| 335 : GetDataOperation(registry, url_request_context_getter, callback), | 335 : GetDataOperation(registry, url_request_context_getter, callback), |
| 336 url_generator_(url_generator), | 336 url_generator_(url_generator), |
| 337 resource_id_(resource_id), | 337 resource_id_(resource_id), |
| 338 new_name_(new_name) { | 338 new_name_(new_name) { |
| 339 DCHECK(!callback.is_null()); | 339 DCHECK(!callback.is_null()); |
| 340 } | 340 } |
| 341 | 341 |
| 342 CopyDocumentOperation::~CopyDocumentOperation() {} | 342 CopyHostedDocumentOperation::~CopyHostedDocumentOperation() {} |
| 343 | 343 |
| 344 URLFetcher::RequestType CopyDocumentOperation::GetRequestType() const { | 344 URLFetcher::RequestType CopyHostedDocumentOperation::GetRequestType() const { |
| 345 return URLFetcher::POST; | 345 return URLFetcher::POST; |
| 346 } | 346 } |
| 347 | 347 |
| 348 GURL CopyDocumentOperation::GetURL() const { | 348 GURL CopyHostedDocumentOperation::GetURL() const { |
| 349 return url_generator_.GenerateDocumentListRootUrl(); | 349 return url_generator_.GenerateDocumentListRootUrl(); |
| 350 } | 350 } |
| 351 | 351 |
| 352 bool CopyDocumentOperation::GetContentData(std::string* upload_content_type, | 352 bool CopyHostedDocumentOperation::GetContentData( |
| 353 std::string* upload_content) { | 353 std::string* upload_content_type, |
| 354 std::string* upload_content) { |
| 354 upload_content_type->assign("application/atom+xml"); | 355 upload_content_type->assign("application/atom+xml"); |
| 355 XmlWriter xml_writer; | 356 XmlWriter xml_writer; |
| 356 xml_writer.StartWriting(); | 357 xml_writer.StartWriting(); |
| 357 xml_writer.StartElement("entry"); | 358 xml_writer.StartElement("entry"); |
| 358 xml_writer.AddAttribute("xmlns", "http://www.w3.org/2005/Atom"); | 359 xml_writer.AddAttribute("xmlns", "http://www.w3.org/2005/Atom"); |
| 359 | 360 |
| 360 xml_writer.WriteElement("id", resource_id_); | 361 xml_writer.WriteElement("id", resource_id_); |
| 361 xml_writer.WriteElement("title", FilePath(new_name_).AsUTF8Unsafe()); | 362 xml_writer.WriteElement("title", FilePath(new_name_).AsUTF8Unsafe()); |
| 362 | 363 |
| 363 xml_writer.EndElement(); // Ends "entry" element. | 364 xml_writer.EndElement(); // Ends "entry" element. |
| 364 xml_writer.StopWriting(); | 365 xml_writer.StopWriting(); |
| 365 upload_content->assign(xml_writer.GetWrittenString()); | 366 upload_content->assign(xml_writer.GetWrittenString()); |
| 366 DVLOG(1) << "CopyDocumentOperation data: " << *upload_content_type << ", [" | 367 DVLOG(1) << "CopyHostedDocumentOperation data: " << *upload_content_type |
| 367 << *upload_content << "]"; | 368 << ", [" << *upload_content << "]"; |
| 368 return true; | 369 return true; |
| 369 } | 370 } |
| 370 | 371 |
| 371 //=========================== RenameResourceOperation ========================== | 372 //=========================== RenameResourceOperation ========================== |
| 372 | 373 |
| 373 RenameResourceOperation::RenameResourceOperation( | 374 RenameResourceOperation::RenameResourceOperation( |
| 374 OperationRegistry* registry, | 375 OperationRegistry* registry, |
| 375 net::URLRequestContextGetter* url_request_context_getter, | 376 net::URLRequestContextGetter* url_request_context_getter, |
| 376 const EntryActionCallback& callback, | 377 const EntryActionCallback& callback, |
| 377 const GURL& edit_url, | 378 const GURL& edit_url, |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 return true; | 850 return true; |
| 850 } | 851 } |
| 851 | 852 |
| 852 void ResumeUploadOperation::OnURLFetchUploadProgress( | 853 void ResumeUploadOperation::OnURLFetchUploadProgress( |
| 853 const URLFetcher* source, int64 current, int64 total) { | 854 const URLFetcher* source, int64 current, int64 total) { |
| 854 // Adjust the progress values according to the range currently uploaded. | 855 // Adjust the progress values according to the range currently uploaded. |
| 855 NotifyProgress(params_.start_range + current, params_.content_length); | 856 NotifyProgress(params_.start_range + current, params_.content_length); |
| 856 } | 857 } |
| 857 | 858 |
| 858 } // namespace google_apis | 859 } // namespace google_apis |
| OLD | NEW |