| 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_DRIVE_UPLOADER_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_DRIVE_UPLOADER_H_ |
| 6 #define CHROME_BROWSER_GOOGLE_APIS_DRIVE_UPLOADER_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_DRIVE_UPLOADER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "chrome/browser/google_apis/drive_upload_error.h" | 14 #include "chrome/browser/google_apis/drive_upload_error.h" |
| 15 #include "chrome/browser/google_apis/gdata_errorcode.h" | 15 #include "chrome/browser/google_apis/gdata_errorcode.h" |
| 16 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 16 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
| 17 | 17 |
| 18 class GURL; |
| 19 |
| 20 namespace base { |
| 18 class FilePath; | 21 class FilePath; |
| 19 class GURL; | 22 } |
| 20 | 23 |
| 21 namespace google_apis { | 24 namespace google_apis { |
| 22 class DriveServiceInterface; | 25 class DriveServiceInterface; |
| 23 struct ResumeUploadResponse; | 26 struct ResumeUploadResponse; |
| 24 | 27 |
| 25 // Callback to be invoked once the upload has completed. | 28 // Callback to be invoked once the upload has completed. |
| 26 typedef base::Callback<void(DriveUploadError error, | 29 typedef base::Callback<void(DriveUploadError error, |
| 27 const FilePath& drive_path, | 30 const base::FilePath& drive_path, |
| 28 const FilePath& file_path, | 31 const base::FilePath& file_path, |
| 29 scoped_ptr<ResourceEntry> resource_entry)> | 32 scoped_ptr<ResourceEntry> resource_entry)> |
| 30 UploadCompletionCallback; | 33 UploadCompletionCallback; |
| 31 | 34 |
| 32 class DriveUploaderInterface { | 35 class DriveUploaderInterface { |
| 33 public: | 36 public: |
| 34 virtual ~DriveUploaderInterface() {} | 37 virtual ~DriveUploaderInterface() {} |
| 35 | 38 |
| 36 // Uploads a new file to a directory specified by |upload_location|. | 39 // Uploads a new file to a directory specified by |upload_location|. |
| 37 // Returns the upload_id. | 40 // Returns the upload_id. |
| 38 // | 41 // |
| 39 // upload_location: | 42 // upload_location: |
| 40 // the "resumable-create-media" URL of the destination directory. | 43 // the "resumable-create-media" URL of the destination directory. |
| 41 // | 44 // |
| 42 // drive_file_path: | 45 // drive_file_path: |
| 43 // The destination path like "drive/foo/bar.txt". | 46 // The destination path like "drive/foo/bar.txt". |
| 44 // | 47 // |
| 45 // local_file_path: | 48 // local_file_path: |
| 46 // The path to the local file to be uploaded. | 49 // The path to the local file to be uploaded. |
| 47 // | 50 // |
| 48 // title: | 51 // title: |
| 49 // The title (file name) of the file to be uploaded. | 52 // The title (file name) of the file to be uploaded. |
| 50 // | 53 // |
| 51 // content_type: | 54 // content_type: |
| 52 // The content type of the file to be uploaded. | 55 // The content type of the file to be uploaded. |
| 53 // | 56 // |
| 54 // callback: | 57 // callback: |
| 55 // Called when an upload is done regardless of it was successful or not. | 58 // Called when an upload is done regardless of it was successful or not. |
| 56 // Must not be null. | 59 // Must not be null. |
| 57 virtual void UploadNewFile(const GURL& upload_location, | 60 virtual void UploadNewFile(const GURL& upload_location, |
| 58 const FilePath& drive_file_path, | 61 const base::FilePath& drive_file_path, |
| 59 const FilePath& local_file_path, | 62 const base::FilePath& local_file_path, |
| 60 const std::string& title, | 63 const std::string& title, |
| 61 const std::string& content_type, | 64 const std::string& content_type, |
| 62 const UploadCompletionCallback& callback) = 0; | 65 const UploadCompletionCallback& callback) = 0; |
| 63 | 66 |
| 64 // Uploads an existing file (a file that already exists on Drive). | 67 // Uploads an existing file (a file that already exists on Drive). |
| 65 // | 68 // |
| 66 // See comments at UploadNewFile() about common parameters. | 69 // See comments at UploadNewFile() about common parameters. |
| 67 // | 70 // |
| 68 // etag: | 71 // etag: |
| 69 // Expected ETag for the destination file. If it does not match, the upload | 72 // Expected ETag for the destination file. If it does not match, the upload |
| 70 // fails with UPLOAD_ERROR_CONFLICT. | 73 // fails with UPLOAD_ERROR_CONFLICT. |
| 71 // If |etag| is empty, the test is skipped. | 74 // If |etag| is empty, the test is skipped. |
| 72 virtual void UploadExistingFile(const GURL& upload_location, | 75 virtual void UploadExistingFile(const GURL& upload_location, |
| 73 const FilePath& drive_file_path, | 76 const base::FilePath& drive_file_path, |
| 74 const FilePath& local_file_path, | 77 const base::FilePath& local_file_path, |
| 75 const std::string& content_type, | 78 const std::string& content_type, |
| 76 const std::string& etag, | 79 const std::string& etag, |
| 77 const UploadCompletionCallback& callback) = 0; | 80 const UploadCompletionCallback& callback) = 0; |
| 78 }; | 81 }; |
| 79 | 82 |
| 80 class DriveUploader : public DriveUploaderInterface { | 83 class DriveUploader : public DriveUploaderInterface { |
| 81 public: | 84 public: |
| 82 explicit DriveUploader(DriveServiceInterface* drive_service); | 85 explicit DriveUploader(DriveServiceInterface* drive_service); |
| 83 virtual ~DriveUploader(); | 86 virtual ~DriveUploader(); |
| 84 | 87 |
| 85 // DriveUploaderInterface overrides. | 88 // DriveUploaderInterface overrides. |
| 86 virtual void UploadNewFile(const GURL& upload_location, | 89 virtual void UploadNewFile(const GURL& upload_location, |
| 87 const FilePath& drive_file_path, | 90 const base::FilePath& drive_file_path, |
| 88 const FilePath& local_file_path, | 91 const base::FilePath& local_file_path, |
| 89 const std::string& title, | 92 const std::string& title, |
| 90 const std::string& content_type, | 93 const std::string& content_type, |
| 91 const UploadCompletionCallback& callback) OVERRIDE; | 94 const UploadCompletionCallback& callback) OVERRIDE; |
| 92 virtual void UploadExistingFile( | 95 virtual void UploadExistingFile( |
| 93 const GURL& upload_location, | 96 const GURL& upload_location, |
| 94 const FilePath& drive_file_path, | 97 const base::FilePath& drive_file_path, |
| 95 const FilePath& local_file_path, | 98 const base::FilePath& local_file_path, |
| 96 const std::string& content_type, | 99 const std::string& content_type, |
| 97 const std::string& etag, | 100 const std::string& etag, |
| 98 const UploadCompletionCallback& callback) OVERRIDE; | 101 const UploadCompletionCallback& callback) OVERRIDE; |
| 99 | 102 |
| 100 private: | 103 private: |
| 101 struct UploadFileInfo; | 104 struct UploadFileInfo; |
| 102 | 105 |
| 103 // Starts uploading a file with |upload_file_info|. | 106 // Starts uploading a file with |upload_file_info|. |
| 104 void StartUploadFile(scoped_ptr<UploadFileInfo> upload_file_info); | 107 void StartUploadFile(scoped_ptr<UploadFileInfo> upload_file_info); |
| 105 | 108 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // Note: This should remain the last member so it'll be destroyed and | 149 // Note: This should remain the last member so it'll be destroyed and |
| 147 // invalidate its weak pointers before any other members are destroyed. | 150 // invalidate its weak pointers before any other members are destroyed. |
| 148 base::WeakPtrFactory<DriveUploader> weak_ptr_factory_; | 151 base::WeakPtrFactory<DriveUploader> weak_ptr_factory_; |
| 149 | 152 |
| 150 DISALLOW_COPY_AND_ASSIGN(DriveUploader); | 153 DISALLOW_COPY_AND_ASSIGN(DriveUploader); |
| 151 }; | 154 }; |
| 152 | 155 |
| 153 } // namespace google_apis | 156 } // namespace google_apis |
| 154 | 157 |
| 155 #endif // CHROME_BROWSER_GOOGLE_APIS_DRIVE_UPLOADER_H_ | 158 #endif // CHROME_BROWSER_GOOGLE_APIS_DRIVE_UPLOADER_H_ |
| OLD | NEW |