Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_GOOGLE_APIS_GDATA_OPERATIONS_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_GDATA_OPERATIONS_H_ |
| 6 #define CHROME_BROWSER_GOOGLE_APIS_GDATA_OPERATIONS_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_GDATA_OPERATIONS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 | 90 |
| 91 // Callback type for DownloadDocument/DownloadFile DocumentServiceInterface | 91 // Callback type for DownloadDocument/DownloadFile DocumentServiceInterface |
| 92 // calls. | 92 // calls. |
| 93 typedef base::Callback<void(GDataErrorCode error, | 93 typedef base::Callback<void(GDataErrorCode error, |
| 94 const GURL& content_url, | 94 const GURL& content_url, |
| 95 const FilePath& temp_file)> DownloadActionCallback; | 95 const FilePath& temp_file)> DownloadActionCallback; |
| 96 | 96 |
| 97 // This class performs the operation for downloading of a given document/file. | 97 // This class performs the operation for downloading of a given document/file. |
| 98 class DownloadFileOperation : public UrlFetchOperationBase { | 98 class DownloadFileOperation : public UrlFetchOperationBase { |
| 99 public: | 99 public: |
| 100 // Downloads a file identified by its |document_url|. | |
| 101 // If |etag| is set, checks if it matches the file before downloading. | |
|
satorux1
2012/10/17 03:14:27
If etag does not match, what happens? Please docum
| |
| 102 // The downloaded file will be stored at |output_file_path| location. | |
| 103 // On partial data is received, invokes |get_content_callbac| if not empty. | |
| 104 // Upon completion, invokes |download_action_callback|. | |
|
satorux1
2012/10/17 03:14:27
Thank you for improving the comment here!
| |
| 105 // | |
| 106 // Registers the download task to |registry| with OperationProgressStatus | |
| 107 // associated with |virtual_path|. | |
| 100 DownloadFileOperation( | 108 DownloadFileOperation( |
| 101 OperationRegistry* registry, | 109 OperationRegistry* registry, |
| 102 const DownloadActionCallback& download_action_callback, | 110 const DownloadActionCallback& download_action_callback, |
| 103 const GetContentCallback& get_content_callback, | 111 const GetContentCallback& get_content_callback, |
| 104 const GURL& document_url, | 112 const GURL& document_url, |
| 105 const FilePath& virtual_path, | 113 const FilePath& virtual_path, |
| 106 const FilePath& output_file_path); | 114 const FilePath& output_file_path, |
| 115 const std::string& etag); | |
| 107 virtual ~DownloadFileOperation(); | 116 virtual ~DownloadFileOperation(); |
| 108 | 117 |
| 109 protected: | 118 protected: |
| 110 // Overridden from UrlFetchOperationBase. | 119 // Overridden from UrlFetchOperationBase. |
| 111 virtual GURL GetURL() const OVERRIDE; | 120 virtual GURL GetURL() const OVERRIDE; |
| 112 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 121 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
| 113 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 122 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
| 123 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | |
| 114 | 124 |
| 115 // Overridden from net::URLFetcherDelegate. | 125 // Overridden from net::URLFetcherDelegate. |
| 116 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, | 126 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
| 117 int64 current, int64 total) OVERRIDE; | 127 int64 current, int64 total) OVERRIDE; |
| 118 virtual bool ShouldSendDownloadData() OVERRIDE; | 128 virtual bool ShouldSendDownloadData() OVERRIDE; |
| 119 virtual void OnURLFetchDownloadData( | 129 virtual void OnURLFetchDownloadData( |
| 120 const net::URLFetcher* source, | 130 const net::URLFetcher* source, |
| 121 scoped_ptr<std::string> download_data) OVERRIDE; | 131 scoped_ptr<std::string> download_data) OVERRIDE; |
| 122 | 132 |
| 123 private: | 133 private: |
| 124 DownloadActionCallback download_action_callback_; | 134 DownloadActionCallback download_action_callback_; |
| 125 GetContentCallback get_content_callback_; | 135 GetContentCallback get_content_callback_; |
| 126 GURL document_url_; | 136 GURL document_url_; |
| 137 std::string etag_; | |
| 127 | 138 |
| 128 DISALLOW_COPY_AND_ASSIGN(DownloadFileOperation); | 139 DISALLOW_COPY_AND_ASSIGN(DownloadFileOperation); |
| 129 }; | 140 }; |
| 130 | 141 |
| 131 //=========================== DeleteDocumentOperation ========================== | 142 //=========================== DeleteDocumentOperation ========================== |
| 132 | 143 |
| 133 // This class performs the operation for deleting a document. | 144 // This class performs the operation for deleting a document. |
| 134 class DeleteDocumentOperation : public EntryActionOperation { | 145 class DeleteDocumentOperation : public EntryActionOperation { |
| 135 public: | 146 public: |
| 147 // Deletes a file identified by its |document_url|. | |
| 148 // If |etag| is set, checks if it matches the file before deletion. | |
|
satorux1
2012/10/17 03:14:27
If etag does not match, what happens? Please docum
| |
| 149 // Upon completion, invokes |callback|. | |
| 150 // | |
| 151 // Registers the download task to |registry|. | |
| 136 DeleteDocumentOperation(OperationRegistry* registry, | 152 DeleteDocumentOperation(OperationRegistry* registry, |
| 137 const EntryActionCallback& callback, | 153 const EntryActionCallback& callback, |
| 138 const GURL& document_url); | 154 const GURL& document_url, |
| 155 const std::string& etag); | |
| 139 virtual ~DeleteDocumentOperation(); | 156 virtual ~DeleteDocumentOperation(); |
| 140 | 157 |
| 141 protected: | 158 protected: |
| 142 // Overridden from UrlFetchOperationBase. | 159 // Overridden from UrlFetchOperationBase. |
| 143 virtual GURL GetURL() const OVERRIDE; | 160 virtual GURL GetURL() const OVERRIDE; |
| 144 | 161 |
| 145 // Overridden from EntryActionOperation. | 162 // Overridden from EntryActionOperation. |
| 146 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 163 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
| 147 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 164 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; |
| 148 | 165 |
| 149 private: | 166 private: |
| 167 std::string etag_; | |
| 168 | |
| 150 DISALLOW_COPY_AND_ASSIGN(DeleteDocumentOperation); | 169 DISALLOW_COPY_AND_ASSIGN(DeleteDocumentOperation); |
| 151 }; | 170 }; |
| 152 | 171 |
| 153 //========================== CreateDirectoryOperation ========================== | 172 //========================== CreateDirectoryOperation ========================== |
| 154 | 173 |
| 155 // This class performs the operation for creating a directory. | 174 // This class performs the operation for creating a directory. |
| 156 class CreateDirectoryOperation : public GetDataOperation { | 175 class CreateDirectoryOperation : public GetDataOperation { |
| 157 public: | 176 public: |
| 158 // Empty |parent_content_url| will create the directory in the root folder. | 177 // Empty |parent_content_url| will create the directory in the root folder. |
| 159 CreateDirectoryOperation(OperationRegistry* registry, | 178 CreateDirectoryOperation(OperationRegistry* registry, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 }; | 339 }; |
| 321 | 340 |
| 322 //=========================== InitiateUploadOperation ========================== | 341 //=========================== InitiateUploadOperation ========================== |
| 323 | 342 |
| 324 // Struct for passing params needed for DriveServiceInterface::InitiateUpload() | 343 // Struct for passing params needed for DriveServiceInterface::InitiateUpload() |
| 325 // calls. | 344 // calls. |
| 326 // | 345 // |
| 327 // When uploading a new file (UPLOAD_NEW_FILE): | 346 // When uploading a new file (UPLOAD_NEW_FILE): |
| 328 // - |title| should be set. | 347 // - |title| should be set. |
| 329 // - |upload_location| should be the upload_url() of the parent directory. | 348 // - |upload_location| should be the upload_url() of the parent directory. |
| 349 // - |etag| should be empty. | |
| 330 // | 350 // |
| 331 // When updating an existing file (UPLOAD_EXISTING_FILE): | 351 // When updating an existing file (UPLOAD_EXISTING_FILE): |
| 332 // - |title| should be empty | 352 // - |title| should be empty. |
| 333 // - |upload_location| should be the upload_url() of the existing file. | 353 // - |upload_location| should be the upload_url() of the existing file. |
| 354 // - |etag| should match the existing file. If it's empty, matching is skipped. | |
|
satorux1
2012/10/17 03:14:27
If etag does not match, what happens? Please docum
| |
| 334 struct InitiateUploadParams { | 355 struct InitiateUploadParams { |
| 335 InitiateUploadParams(UploadMode upload_mode, | 356 InitiateUploadParams(UploadMode upload_mode, |
| 336 const std::string& title, | 357 const std::string& title, |
| 337 const std::string& content_type, | 358 const std::string& content_type, |
| 338 int64 content_length, | 359 int64 content_length, |
| 339 const GURL& upload_location, | 360 const GURL& upload_location, |
| 340 const FilePath& virtual_path); | 361 const FilePath& virtual_path, |
| 362 const std::string& etag); | |
| 341 ~InitiateUploadParams(); | 363 ~InitiateUploadParams(); |
| 342 | 364 |
| 343 UploadMode upload_mode; | 365 UploadMode upload_mode; |
| 344 std::string title; | 366 std::string title; |
| 345 std::string content_type; | 367 std::string content_type; |
| 346 int64 content_length; | 368 int64 content_length; |
| 347 GURL upload_location; | 369 GURL upload_location; |
| 348 FilePath virtual_path; | 370 FilePath virtual_path; |
| 371 std::string etag; | |
| 349 }; | 372 }; |
| 350 | 373 |
| 351 // Callback type for DocumentServiceInterface::InitiateUpload. | 374 // Callback type for DocumentServiceInterface::InitiateUpload. |
| 352 typedef base::Callback<void(GDataErrorCode error, | 375 typedef base::Callback<void(GDataErrorCode error, |
| 353 const GURL& upload_url)> InitiateUploadCallback; | 376 const GURL& upload_url)> InitiateUploadCallback; |
| 354 | 377 |
| 355 // This class performs the operation for initiating the upload of a file. | 378 // This class performs the operation for initiating the upload of a file. |
| 356 class InitiateUploadOperation : public UrlFetchOperationBase { | 379 class InitiateUploadOperation : public UrlFetchOperationBase { |
| 357 public: | 380 public: |
| 358 InitiateUploadOperation(OperationRegistry* registry, | 381 InitiateUploadOperation(OperationRegistry* registry, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 // Struct for passing params needed for DriveServiceInterface::ResumeUpload() | 422 // Struct for passing params needed for DriveServiceInterface::ResumeUpload() |
| 400 // calls. | 423 // calls. |
| 401 struct ResumeUploadParams { | 424 struct ResumeUploadParams { |
| 402 ResumeUploadParams(UploadMode upload_mode, | 425 ResumeUploadParams(UploadMode upload_mode, |
| 403 int64 start_range, | 426 int64 start_range, |
| 404 int64 end_range, | 427 int64 end_range, |
| 405 int64 content_length, | 428 int64 content_length, |
| 406 const std::string& content_type, | 429 const std::string& content_type, |
| 407 scoped_refptr<net::IOBuffer> buf, | 430 scoped_refptr<net::IOBuffer> buf, |
| 408 const GURL& upload_location, | 431 const GURL& upload_location, |
| 409 const FilePath& virtual_path); | 432 const FilePath& virtual_path, |
| 433 const std::string& etag); | |
| 410 ~ResumeUploadParams(); | 434 ~ResumeUploadParams(); |
| 411 | 435 |
| 412 UploadMode upload_mode; // Mode of the upload. | 436 UploadMode upload_mode; // Mode of the upload. |
| 413 int64 start_range; // Start of range of contents currently stored in |buf|. | 437 int64 start_range; // Start of range of contents currently stored in |buf|. |
| 414 int64 end_range; // End of range of contents currently stored in |buf|. | 438 int64 end_range; // End of range of contents currently stored in |buf|. |
| 415 int64 content_length; // File content-Length. | 439 int64 content_length; // File content-Length. |
| 416 std::string content_type; // Content-Type of file. | 440 std::string content_type; // Content-Type of file. |
| 417 scoped_refptr<net::IOBuffer> buf; // Holds current content to be uploaded. | 441 scoped_refptr<net::IOBuffer> buf; // Holds current content to be uploaded. |
| 418 GURL upload_location; // Url of where to upload the file to. | 442 GURL upload_location; // Url of where to upload the file to. |
| 419 // Virtual GData path of the file seen in the UI. Not necessary for | 443 // Virtual GData path of the file seen in the UI. Not necessary for |
| 420 // resuming an upload, but used for adding an entry to OperationRegistry. | 444 // resuming an upload, but used for adding an entry to OperationRegistry. |
| 421 FilePath virtual_path; | 445 FilePath virtual_path; |
| 446 // ETag matches the file to be overwritten. Matching is skipped if it's empty. | |
| 447 std::string etag; | |
| 422 }; | 448 }; |
| 423 | 449 |
| 424 // Callback type for DocumentServiceInterface::ResumeUpload. | 450 // Callback type for DocumentServiceInterface::ResumeUpload. |
| 425 typedef base::Callback<void( | 451 typedef base::Callback<void( |
| 426 const ResumeUploadResponse& response, | 452 const ResumeUploadResponse& response, |
| 427 scoped_ptr<gdata::DocumentEntry> new_entry)> ResumeUploadCallback; | 453 scoped_ptr<gdata::DocumentEntry> new_entry)> ResumeUploadCallback; |
| 428 | 454 |
| 429 // This class performs the operation for resuming the upload of a file. | 455 // This class performs the operation for resuming the upload of a file. |
| 430 class ResumeUploadOperation : public UrlFetchOperationBase { | 456 class ResumeUploadOperation : public UrlFetchOperationBase { |
| 431 public: | 457 public: |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 | 567 |
| 542 // Callback to which the photo data is passed. | 568 // Callback to which the photo data is passed. |
| 543 GetContentCallback callback_; | 569 GetContentCallback callback_; |
| 544 | 570 |
| 545 DISALLOW_COPY_AND_ASSIGN(GetContactPhotoOperation); | 571 DISALLOW_COPY_AND_ASSIGN(GetContactPhotoOperation); |
| 546 }; | 572 }; |
| 547 | 573 |
| 548 } // namespace gdata | 574 } // namespace gdata |
| 549 | 575 |
| 550 #endif // CHROME_BROWSER_GOOGLE_APIS_GDATA_OPERATIONS_H_ | 576 #endif // CHROME_BROWSER_GOOGLE_APIS_GDATA_OPERATIONS_H_ |
| OLD | NEW |