| 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" |
| 11 #include "chrome/browser/google_apis/gdata_wapi_url_util.h" | 11 #include "chrome/browser/google_apis/gdata_wapi_url_util.h" |
| 12 #include "chrome/browser/google_apis/time_util.h" | 12 #include "chrome/browser/google_apis/time_util.h" |
| 13 #include "chrome/common/net/url_util.h" | 13 #include "chrome/common/net/url_util.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "net/base/escape.h" | 15 #include "net/base/escape.h" |
| 16 #include "net/http/http_response_headers.h" | 16 #include "net/http/http_response_headers.h" |
| 17 #include "net/http/http_util.h" | 17 #include "net/http/http_util.h" |
| 18 #include "third_party/libxml/chromium/libxml_utils.h" | 18 #include "third_party/libxml/chromium/libxml_utils.h" |
| 19 | 19 |
| 20 using net::URLFetcher; | 20 using net::URLFetcher; |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // etag matching header. | 24 // etag matching header. |
| 25 const char kIfMatchAllHeader[] = "If-Match: *"; | 25 const char kIfMatchAllHeader[] = "If-Match: *"; |
| 26 const char kIfMatchHeaderFormat[] = "If-Match: %s"; | 26 const char kIfMatchHeaderFormat[] = "If-Match: %s"; |
| 27 | 27 |
| 28 // Root document list url. | |
| 29 const char kDocumentListRootURL[] = | |
| 30 "https://docs.google.com/feeds/default/private/full"; | |
| 31 | |
| 32 // URL requesting single document entry whose resource id is specified by "%s". | |
| 33 const char kGetDocumentEntryURLFormat[] = | |
| 34 "https://docs.google.com/feeds/default/private/full/%s"; | |
| 35 | |
| 36 // Metadata feed with things like user quota. | |
| 37 const char kAccountMetadataURL[] = | |
| 38 "https://docs.google.com/feeds/metadata/default"; | |
| 39 | |
| 40 const char kUploadContentRange[] = "Content-Range: bytes "; | 28 const char kUploadContentRange[] = "Content-Range: bytes "; |
| 41 const char kUploadContentType[] = "X-Upload-Content-Type: "; | 29 const char kUploadContentType[] = "X-Upload-Content-Type: "; |
| 42 const char kUploadContentLength[] = "X-Upload-Content-Length: "; | 30 const char kUploadContentLength[] = "X-Upload-Content-Length: "; |
| 43 | 31 |
| 44 const char kFeedField[] = "feed"; | 32 const char kFeedField[] = "feed"; |
| 45 | 33 |
| 46 // Templates for file uploading. | 34 // Templates for file uploading. |
| 47 const char kUploadParamConvertKey[] = "convert"; | 35 const char kUploadParamConvertKey[] = "convert"; |
| 48 const char kUploadParamConvertValue[] = "false"; | 36 const char kUploadParamConvertValue[] = "false"; |
| 49 const char kUploadResponseLocation[] = "location"; | 37 const char kUploadResponseLocation[] = "location"; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 OperationRegistry* registry, | 127 OperationRegistry* registry, |
| 140 const std::string& resource_id, | 128 const std::string& resource_id, |
| 141 const GetDataCallback& callback) | 129 const GetDataCallback& callback) |
| 142 : GetDataOperation(registry, callback), | 130 : GetDataOperation(registry, callback), |
| 143 resource_id_(resource_id) { | 131 resource_id_(resource_id) { |
| 144 } | 132 } |
| 145 | 133 |
| 146 GetDocumentEntryOperation::~GetDocumentEntryOperation() {} | 134 GetDocumentEntryOperation::~GetDocumentEntryOperation() {} |
| 147 | 135 |
| 148 GURL GetDocumentEntryOperation::GetURL() const { | 136 GURL GetDocumentEntryOperation::GetURL() const { |
| 149 GURL result = GURL(base::StringPrintf(kGetDocumentEntryURLFormat, | 137 return gdata_wapi_url_util::GenerateDocumentEntryUrl(resource_id_); |
| 150 net::EscapePath(resource_id_).c_str())); | |
| 151 return gdata_wapi_url_util::AddStandardUrlParams(result); | |
| 152 } | 138 } |
| 153 | 139 |
| 154 //========================= GetAccountMetadataOperation ======================== | 140 //========================= GetAccountMetadataOperation ======================== |
| 155 | 141 |
| 156 GetAccountMetadataOperation::GetAccountMetadataOperation( | 142 GetAccountMetadataOperation::GetAccountMetadataOperation( |
| 157 OperationRegistry* registry, | 143 OperationRegistry* registry, |
| 158 const GetDataCallback& callback) | 144 const GetDataCallback& callback) |
| 159 : GetDataOperation(registry, callback) { | 145 : GetDataOperation(registry, callback) { |
| 160 } | 146 } |
| 161 | 147 |
| 162 GetAccountMetadataOperation::~GetAccountMetadataOperation() {} | 148 GetAccountMetadataOperation::~GetAccountMetadataOperation() {} |
| 163 | 149 |
| 164 GURL GetAccountMetadataOperation::GetURL() const { | 150 GURL GetAccountMetadataOperation::GetURL() const { |
| 165 return gdata_wapi_url_util::AddMetadataUrlParams(GURL(kAccountMetadataURL)); | 151 return gdata_wapi_url_util::GenerateAccountMetadataUrl(); |
| 166 } | 152 } |
| 167 | 153 |
| 168 //============================ DownloadFileOperation =========================== | 154 //============================ DownloadFileOperation =========================== |
| 169 | 155 |
| 170 DownloadFileOperation::DownloadFileOperation( | 156 DownloadFileOperation::DownloadFileOperation( |
| 171 OperationRegistry* registry, | 157 OperationRegistry* registry, |
| 172 const DownloadActionCallback& download_action_callback, | 158 const DownloadActionCallback& download_action_callback, |
| 173 const GetContentCallback& get_content_callback, | 159 const GetContentCallback& get_content_callback, |
| 174 const GURL& document_url, | 160 const GURL& document_url, |
| 175 const FilePath& virtual_path, | 161 const FilePath& virtual_path, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 parent_content_url_(parent_content_url), | 255 parent_content_url_(parent_content_url), |
| 270 directory_name_(directory_name) { | 256 directory_name_(directory_name) { |
| 271 } | 257 } |
| 272 | 258 |
| 273 CreateDirectoryOperation::~CreateDirectoryOperation() {} | 259 CreateDirectoryOperation::~CreateDirectoryOperation() {} |
| 274 | 260 |
| 275 GURL CreateDirectoryOperation::GetURL() const { | 261 GURL CreateDirectoryOperation::GetURL() const { |
| 276 if (!parent_content_url_.is_empty()) | 262 if (!parent_content_url_.is_empty()) |
| 277 return gdata_wapi_url_util::AddStandardUrlParams(parent_content_url_); | 263 return gdata_wapi_url_util::AddStandardUrlParams(parent_content_url_); |
| 278 | 264 |
| 279 return gdata_wapi_url_util::AddStandardUrlParams(GURL(kDocumentListRootURL)); | 265 return gdata_wapi_url_util::GenerateDocumentListRootUrl(); |
| 280 } | 266 } |
| 281 | 267 |
| 282 URLFetcher::RequestType | 268 URLFetcher::RequestType |
| 283 CreateDirectoryOperation::GetRequestType() const { | 269 CreateDirectoryOperation::GetRequestType() const { |
| 284 return URLFetcher::POST; | 270 return URLFetcher::POST; |
| 285 } | 271 } |
| 286 | 272 |
| 287 bool CreateDirectoryOperation::GetContentData(std::string* upload_content_type, | 273 bool CreateDirectoryOperation::GetContentData(std::string* upload_content_type, |
| 288 std::string* upload_content) { | 274 std::string* upload_content) { |
| 289 upload_content_type->assign("application/atom+xml"); | 275 upload_content_type->assign("application/atom+xml"); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 new_name_(new_name) { | 307 new_name_(new_name) { |
| 322 } | 308 } |
| 323 | 309 |
| 324 CopyDocumentOperation::~CopyDocumentOperation() {} | 310 CopyDocumentOperation::~CopyDocumentOperation() {} |
| 325 | 311 |
| 326 URLFetcher::RequestType CopyDocumentOperation::GetRequestType() const { | 312 URLFetcher::RequestType CopyDocumentOperation::GetRequestType() const { |
| 327 return URLFetcher::POST; | 313 return URLFetcher::POST; |
| 328 } | 314 } |
| 329 | 315 |
| 330 GURL CopyDocumentOperation::GetURL() const { | 316 GURL CopyDocumentOperation::GetURL() const { |
| 331 return gdata_wapi_url_util::AddStandardUrlParams(GURL(kDocumentListRootURL)); | 317 return gdata_wapi_url_util::GenerateDocumentListRootUrl(); |
| 332 } | 318 } |
| 333 | 319 |
| 334 bool CopyDocumentOperation::GetContentData(std::string* upload_content_type, | 320 bool CopyDocumentOperation::GetContentData(std::string* upload_content_type, |
| 335 std::string* upload_content) { | 321 std::string* upload_content) { |
| 336 upload_content_type->assign("application/atom+xml"); | 322 upload_content_type->assign("application/atom+xml"); |
| 337 XmlWriter xml_writer; | 323 XmlWriter xml_writer; |
| 338 xml_writer.StartWriting(); | 324 xml_writer.StartWriting(); |
| 339 xml_writer.StartElement("entry"); | 325 xml_writer.StartElement("entry"); |
| 340 xml_writer.AddAttribute("xmlns", "http://www.w3.org/2005/Atom"); | 326 xml_writer.AddAttribute("xmlns", "http://www.w3.org/2005/Atom"); |
| 341 | 327 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 : EntryActionOperation(registry, callback, document_url), | 481 : EntryActionOperation(registry, callback, document_url), |
| 496 parent_content_url_(parent_content_url) { | 482 parent_content_url_(parent_content_url) { |
| 497 } | 483 } |
| 498 | 484 |
| 499 AddResourceToDirectoryOperation::~AddResourceToDirectoryOperation() {} | 485 AddResourceToDirectoryOperation::~AddResourceToDirectoryOperation() {} |
| 500 | 486 |
| 501 GURL AddResourceToDirectoryOperation::GetURL() const { | 487 GURL AddResourceToDirectoryOperation::GetURL() const { |
| 502 if (!parent_content_url_.is_empty()) | 488 if (!parent_content_url_.is_empty()) |
| 503 return gdata_wapi_url_util::AddStandardUrlParams(parent_content_url_); | 489 return gdata_wapi_url_util::AddStandardUrlParams(parent_content_url_); |
| 504 | 490 |
| 505 return gdata_wapi_url_util::AddStandardUrlParams(GURL(kDocumentListRootURL)); | 491 return gdata_wapi_url_util::GenerateDocumentListRootUrl(); |
| 506 } | 492 } |
| 507 | 493 |
| 508 URLFetcher::RequestType | 494 URLFetcher::RequestType |
| 509 AddResourceToDirectoryOperation::GetRequestType() const { | 495 AddResourceToDirectoryOperation::GetRequestType() const { |
| 510 return URLFetcher::POST; | 496 return URLFetcher::POST; |
| 511 } | 497 } |
| 512 | 498 |
| 513 bool AddResourceToDirectoryOperation::GetContentData( | 499 bool AddResourceToDirectoryOperation::GetContentData( |
| 514 std::string* upload_content_type, std::string* upload_content) { | 500 std::string* upload_content_type, std::string* upload_content) { |
| 515 upload_content_type->assign("application/atom+xml"); | 501 upload_content_type->assign("application/atom+xml"); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 return true; | 796 return true; |
| 811 } | 797 } |
| 812 | 798 |
| 813 void ResumeUploadOperation::OnURLFetchUploadProgress( | 799 void ResumeUploadOperation::OnURLFetchUploadProgress( |
| 814 const URLFetcher* source, int64 current, int64 total) { | 800 const URLFetcher* source, int64 current, int64 total) { |
| 815 // Adjust the progress values according to the range currently uploaded. | 801 // Adjust the progress values according to the range currently uploaded. |
| 816 NotifyProgress(params_.start_range + current, params_.content_length); | 802 NotifyProgress(params_.start_range + current, params_.content_length); |
| 817 } | 803 } |
| 818 | 804 |
| 819 } // namespace google_apis | 805 } // namespace google_apis |
| OLD | NEW |