| 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_API_OPERATIONS_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_DRIVE_API_OPERATIONS_H_ |
| 6 #define CHROME_BROWSER_GOOGLE_APIS_DRIVE_API_OPERATIONS_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_DRIVE_API_OPERATIONS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "chrome/browser/google_apis/base_operations.h" | 11 #include "chrome/browser/google_apis/base_requests.h" |
| 12 #include "chrome/browser/google_apis/drive_api_url_generator.h" | 12 #include "chrome/browser/google_apis/drive_api_url_generator.h" |
| 13 #include "chrome/browser/google_apis/drive_service_interface.h" | 13 #include "chrome/browser/google_apis/drive_service_interface.h" |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 class URLRequestContextGetter; | 16 class URLRequestContextGetter; |
| 17 } // namespace net | 17 } // namespace net |
| 18 | 18 |
| 19 namespace google_apis { | 19 namespace google_apis { |
| 20 | 20 |
| 21 class FileResource; | 21 class FileResource; |
| 22 | 22 |
| 23 // Callback used for operations that the server returns FileResource data | 23 // Callback used for operations that the server returns FileResource data |
| 24 // formatted into JSON value. | 24 // formatted into JSON value. |
| 25 typedef base::Callback<void(GDataErrorCode error, | 25 typedef base::Callback<void(GDataErrorCode error, |
| 26 scoped_ptr<FileResource> entry)> | 26 scoped_ptr<FileResource> entry)> |
| 27 FileResourceCallback; | 27 FileResourceCallback; |
| 28 | 28 |
| 29 | 29 |
| 30 //============================== GetAboutOperation ============================= | 30 //============================== GetAboutOperation ============================= |
| 31 | 31 |
| 32 // This class performs the operation for fetching About data. | 32 // This class performs the operation for fetching About data. |
| 33 class GetAboutOperation : public GetDataOperation { | 33 class GetAboutOperation : public GetDataRequest { |
| 34 public: | 34 public: |
| 35 GetAboutOperation(OperationRunner* runner, | 35 GetAboutOperation(OperationRunner* runner, |
| 36 net::URLRequestContextGetter* url_request_context_getter, | 36 net::URLRequestContextGetter* url_request_context_getter, |
| 37 const DriveApiUrlGenerator& url_generator, | 37 const DriveApiUrlGenerator& url_generator, |
| 38 const GetAboutResourceCallback& callback); | 38 const GetAboutResourceCallback& callback); |
| 39 virtual ~GetAboutOperation(); | 39 virtual ~GetAboutOperation(); |
| 40 | 40 |
| 41 protected: | 41 protected: |
| 42 // Overridden from GetDataOperation. | 42 // Overridden from GetDataRequest. |
| 43 virtual GURL GetURL() const OVERRIDE; | 43 virtual GURL GetURL() const OVERRIDE; |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 const DriveApiUrlGenerator url_generator_; | 46 const DriveApiUrlGenerator url_generator_; |
| 47 | 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(GetAboutOperation); | 48 DISALLOW_COPY_AND_ASSIGN(GetAboutOperation); |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 //============================= GetApplistOperation ============================ | 51 //============================= GetApplistOperation ============================ |
| 52 | 52 |
| 53 // This class performs the operation for fetching Applist. | 53 // This class performs the operation for fetching Applist. |
| 54 class GetApplistOperation : public GetDataOperation { | 54 class GetApplistOperation : public GetDataRequest { |
| 55 public: | 55 public: |
| 56 GetApplistOperation(OperationRunner* runner, | 56 GetApplistOperation(OperationRunner* runner, |
| 57 net::URLRequestContextGetter* url_request_context_getter, | 57 net::URLRequestContextGetter* url_request_context_getter, |
| 58 const DriveApiUrlGenerator& url_generator, | 58 const DriveApiUrlGenerator& url_generator, |
| 59 const GetDataCallback& callback); | 59 const GetDataCallback& callback); |
| 60 virtual ~GetApplistOperation(); | 60 virtual ~GetApplistOperation(); |
| 61 | 61 |
| 62 protected: | 62 protected: |
| 63 // Overridden from GetDataOperation. | 63 // Overridden from GetDataRequest. |
| 64 virtual GURL GetURL() const OVERRIDE; | 64 virtual GURL GetURL() const OVERRIDE; |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 const DriveApiUrlGenerator url_generator_; | 67 const DriveApiUrlGenerator url_generator_; |
| 68 | 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(GetApplistOperation); | 69 DISALLOW_COPY_AND_ASSIGN(GetApplistOperation); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 //============================ GetChangelistOperation ========================== | 72 //============================ GetChangelistOperation ========================== |
| 73 | 73 |
| 74 // This class performs the operation for fetching changelist. | 74 // This class performs the operation for fetching changelist. |
| 75 // The result may contain only first part of the result. The remaining result | 75 // The result may contain only first part of the result. The remaining result |
| 76 // should be able to be fetched by ContinueGetFileListOperation defined below. | 76 // should be able to be fetched by ContinueGetFileListOperation defined below. |
| 77 class GetChangelistOperation : public GetDataOperation { | 77 class GetChangelistOperation : public GetDataRequest { |
| 78 public: | 78 public: |
| 79 // |include_deleted| specifies if the response should contain the changes | 79 // |include_deleted| specifies if the response should contain the changes |
| 80 // for deleted entries or not. | 80 // for deleted entries or not. |
| 81 // |start_changestamp| specifies the starting point of change list or 0 if | 81 // |start_changestamp| specifies the starting point of change list or 0 if |
| 82 // all changes are necessary. | 82 // all changes are necessary. |
| 83 // |max_results| specifies the max of the number of files resource in the | 83 // |max_results| specifies the max of the number of files resource in the |
| 84 // response. | 84 // response. |
| 85 GetChangelistOperation( | 85 GetChangelistOperation( |
| 86 OperationRunner* runner, | 86 OperationRunner* runner, |
| 87 net::URLRequestContextGetter* url_request_context_getter, | 87 net::URLRequestContextGetter* url_request_context_getter, |
| 88 const DriveApiUrlGenerator& url_generator, | 88 const DriveApiUrlGenerator& url_generator, |
| 89 bool include_deleted, | 89 bool include_deleted, |
| 90 int64 start_changestamp, | 90 int64 start_changestamp, |
| 91 int max_results, | 91 int max_results, |
| 92 const GetDataCallback& callback); | 92 const GetDataCallback& callback); |
| 93 virtual ~GetChangelistOperation(); | 93 virtual ~GetChangelistOperation(); |
| 94 | 94 |
| 95 protected: | 95 protected: |
| 96 // Overridden from GetDataOperation. | 96 // Overridden from GetDataRequest. |
| 97 virtual GURL GetURL() const OVERRIDE; | 97 virtual GURL GetURL() const OVERRIDE; |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 const DriveApiUrlGenerator url_generator_; | 100 const DriveApiUrlGenerator url_generator_; |
| 101 const bool include_deleted_; | 101 const bool include_deleted_; |
| 102 const int64 start_changestamp_; | 102 const int64 start_changestamp_; |
| 103 const int max_results_; | 103 const int max_results_; |
| 104 | 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(GetChangelistOperation); | 105 DISALLOW_COPY_AND_ASSIGN(GetChangelistOperation); |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 //============================= GetFilelistOperation =========================== | 108 //============================= GetFilelistOperation =========================== |
| 109 | 109 |
| 110 // This class performs the operation for fetching Filelist. | 110 // This class performs the operation for fetching Filelist. |
| 111 // The result may contain only first part of the result. The remaining result | 111 // The result may contain only first part of the result. The remaining result |
| 112 // should be able to be fetched by ContinueGetFileListOperation defined below. | 112 // should be able to be fetched by ContinueGetFileListOperation defined below. |
| 113 class GetFilelistOperation : public GetDataOperation { | 113 class GetFilelistOperation : public GetDataRequest { |
| 114 public: | 114 public: |
| 115 GetFilelistOperation( | 115 GetFilelistOperation( |
| 116 OperationRunner* runner, | 116 OperationRunner* runner, |
| 117 net::URLRequestContextGetter* url_request_context_getter, | 117 net::URLRequestContextGetter* url_request_context_getter, |
| 118 const DriveApiUrlGenerator& url_generator, | 118 const DriveApiUrlGenerator& url_generator, |
| 119 const std::string& search_string, | 119 const std::string& search_string, |
| 120 int max_results, | 120 int max_results, |
| 121 const GetDataCallback& callback); | 121 const GetDataCallback& callback); |
| 122 virtual ~GetFilelistOperation(); | 122 virtual ~GetFilelistOperation(); |
| 123 | 123 |
| 124 protected: | 124 protected: |
| 125 // Overridden from GetDataOperation. | 125 // Overridden from GetDataRequest. |
| 126 virtual GURL GetURL() const OVERRIDE; | 126 virtual GURL GetURL() const OVERRIDE; |
| 127 | 127 |
| 128 private: | 128 private: |
| 129 const DriveApiUrlGenerator url_generator_; | 129 const DriveApiUrlGenerator url_generator_; |
| 130 const std::string search_string_; | 130 const std::string search_string_; |
| 131 const int max_results_; | 131 const int max_results_; |
| 132 | 132 |
| 133 DISALLOW_COPY_AND_ASSIGN(GetFilelistOperation); | 133 DISALLOW_COPY_AND_ASSIGN(GetFilelistOperation); |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 //=============================== GetFileOperation ============================= | 136 //=============================== GetFileOperation ============================= |
| 137 | 137 |
| 138 // This class performs the operation for fetching a file. | 138 // This class performs the operation for fetching a file. |
| 139 class GetFileOperation : public GetDataOperation { | 139 class GetFileOperation : public GetDataRequest { |
| 140 public: | 140 public: |
| 141 GetFileOperation(OperationRunner* runner, | 141 GetFileOperation(OperationRunner* runner, |
| 142 net::URLRequestContextGetter* url_request_context_getter, | 142 net::URLRequestContextGetter* url_request_context_getter, |
| 143 const DriveApiUrlGenerator& url_generator, | 143 const DriveApiUrlGenerator& url_generator, |
| 144 const std::string& file_id, | 144 const std::string& file_id, |
| 145 const FileResourceCallback& callback); | 145 const FileResourceCallback& callback); |
| 146 virtual ~GetFileOperation(); | 146 virtual ~GetFileOperation(); |
| 147 | 147 |
| 148 protected: | 148 protected: |
| 149 // Overridden from GetDataOperation. | 149 // Overridden from GetDataRequest. |
| 150 virtual GURL GetURL() const OVERRIDE; | 150 virtual GURL GetURL() const OVERRIDE; |
| 151 | 151 |
| 152 private: | 152 private: |
| 153 const DriveApiUrlGenerator url_generator_; | 153 const DriveApiUrlGenerator url_generator_; |
| 154 std::string file_id_; | 154 std::string file_id_; |
| 155 | 155 |
| 156 DISALLOW_COPY_AND_ASSIGN(GetFileOperation); | 156 DISALLOW_COPY_AND_ASSIGN(GetFileOperation); |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 // This namespace is introduced to avoid class name confliction between | 159 // This namespace is introduced to avoid class name confliction between |
| 160 // the operations for Drive API v2 and GData WAPI for transition. | 160 // the operations for Drive API v2 and GData WAPI for transition. |
| 161 // And, when the migration is done and GData WAPI's code is cleaned up, | 161 // And, when the migration is done and GData WAPI's code is cleaned up, |
| 162 // classes inside this namespace should be moved to the google_apis namespace. | 162 // classes inside this namespace should be moved to the google_apis namespace. |
| 163 // TODO(hidehiko): Move all the operations defined in this file into drive | 163 // TODO(hidehiko): Move all the operations defined in this file into drive |
| 164 // namespace. crbug.com/180808 | 164 // namespace. crbug.com/180808 |
| 165 namespace drive { | 165 namespace drive { |
| 166 | 166 |
| 167 //======================= ContinueGetFileListOperation ========================= | 167 //======================= ContinueGetFileListOperation ========================= |
| 168 | 168 |
| 169 // This class performs the operation to fetch remaining Filelist result. | 169 // This class performs the operation to fetch remaining Filelist result. |
| 170 class ContinueGetFileListOperation : public GetDataOperation { | 170 class ContinueGetFileListOperation : public GetDataRequest { |
| 171 public: | 171 public: |
| 172 ContinueGetFileListOperation( | 172 ContinueGetFileListOperation( |
| 173 OperationRunner* runner, | 173 OperationRunner* runner, |
| 174 net::URLRequestContextGetter* url_request_context_getter, | 174 net::URLRequestContextGetter* url_request_context_getter, |
| 175 const GURL& url, | 175 const GURL& url, |
| 176 const GetDataCallback& callback); | 176 const GetDataCallback& callback); |
| 177 virtual ~ContinueGetFileListOperation(); | 177 virtual ~ContinueGetFileListOperation(); |
| 178 | 178 |
| 179 protected: | 179 protected: |
| 180 virtual GURL GetURL() const OVERRIDE; | 180 virtual GURL GetURL() const OVERRIDE; |
| 181 | 181 |
| 182 private: | 182 private: |
| 183 const GURL url_; | 183 const GURL url_; |
| 184 | 184 |
| 185 DISALLOW_COPY_AND_ASSIGN(ContinueGetFileListOperation); | 185 DISALLOW_COPY_AND_ASSIGN(ContinueGetFileListOperation); |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 //========================== CreateDirectoryOperation ========================== | 188 //========================== CreateDirectoryOperation ========================== |
| 189 | 189 |
| 190 // This class performs the operation for creating a directory. | 190 // This class performs the operation for creating a directory. |
| 191 class CreateDirectoryOperation : public GetDataOperation { | 191 class CreateDirectoryOperation : public GetDataRequest { |
| 192 public: | 192 public: |
| 193 CreateDirectoryOperation( | 193 CreateDirectoryOperation( |
| 194 OperationRunner* runner, | 194 OperationRunner* runner, |
| 195 net::URLRequestContextGetter* url_request_context_getter, | 195 net::URLRequestContextGetter* url_request_context_getter, |
| 196 const DriveApiUrlGenerator& url_generator, | 196 const DriveApiUrlGenerator& url_generator, |
| 197 const std::string& parent_resource_id, | 197 const std::string& parent_resource_id, |
| 198 const std::string& directory_name, | 198 const std::string& directory_name, |
| 199 const FileResourceCallback& callback); | 199 const FileResourceCallback& callback); |
| 200 virtual ~CreateDirectoryOperation(); | 200 virtual ~CreateDirectoryOperation(); |
| 201 | 201 |
| 202 protected: | 202 protected: |
| 203 // Overridden from GetDataOperation. | 203 // Overridden from GetDataRequest. |
| 204 virtual GURL GetURL() const OVERRIDE; | 204 virtual GURL GetURL() const OVERRIDE; |
| 205 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 205 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
| 206 virtual bool GetContentData(std::string* upload_content_type, | 206 virtual bool GetContentData(std::string* upload_content_type, |
| 207 std::string* upload_content) OVERRIDE; | 207 std::string* upload_content) OVERRIDE; |
| 208 | 208 |
| 209 private: | 209 private: |
| 210 const DriveApiUrlGenerator url_generator_; | 210 const DriveApiUrlGenerator url_generator_; |
| 211 const std::string parent_resource_id_; | 211 const std::string parent_resource_id_; |
| 212 const std::string directory_name_; | 212 const std::string directory_name_; |
| 213 | 213 |
| 214 DISALLOW_COPY_AND_ASSIGN(CreateDirectoryOperation); | 214 DISALLOW_COPY_AND_ASSIGN(CreateDirectoryOperation); |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 //=========================== RenameResourceOperation ========================== | 217 //=========================== RenameResourceOperation ========================== |
| 218 | 218 |
| 219 // This class performs the operation for renaming a document/file/directory. | 219 // This class performs the operation for renaming a document/file/directory. |
| 220 class RenameResourceOperation : public EntryActionOperation { | 220 class RenameResourceOperation : public EntryActionRequest { |
| 221 public: | 221 public: |
| 222 // |callback| must not be null. | 222 // |callback| must not be null. |
| 223 RenameResourceOperation( | 223 RenameResourceOperation( |
| 224 OperationRunner* runner, | 224 OperationRunner* runner, |
| 225 net::URLRequestContextGetter* url_request_context_getter, | 225 net::URLRequestContextGetter* url_request_context_getter, |
| 226 const DriveApiUrlGenerator& url_generator, | 226 const DriveApiUrlGenerator& url_generator, |
| 227 const std::string& resource_id, | 227 const std::string& resource_id, |
| 228 const std::string& new_name, | 228 const std::string& new_name, |
| 229 const EntryActionCallback& callback); | 229 const EntryActionCallback& callback); |
| 230 virtual ~RenameResourceOperation(); | 230 virtual ~RenameResourceOperation(); |
| 231 | 231 |
| 232 protected: | 232 protected: |
| 233 // UrlFetchOperationBase overrides. | 233 // UrlFetchRequestBase overrides. |
| 234 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 234 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
| 235 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 235 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; |
| 236 virtual GURL GetURL() const OVERRIDE; | 236 virtual GURL GetURL() const OVERRIDE; |
| 237 virtual bool GetContentData(std::string* upload_content_type, | 237 virtual bool GetContentData(std::string* upload_content_type, |
| 238 std::string* upload_content) OVERRIDE; | 238 std::string* upload_content) OVERRIDE; |
| 239 | 239 |
| 240 private: | 240 private: |
| 241 const DriveApiUrlGenerator url_generator_; | 241 const DriveApiUrlGenerator url_generator_; |
| 242 | 242 |
| 243 const std::string resource_id_; | 243 const std::string resource_id_; |
| 244 const std::string new_name_; | 244 const std::string new_name_; |
| 245 | 245 |
| 246 DISALLOW_COPY_AND_ASSIGN(RenameResourceOperation); | 246 DISALLOW_COPY_AND_ASSIGN(RenameResourceOperation); |
| 247 }; | 247 }; |
| 248 | 248 |
| 249 //=========================== TouchResourceOperation =========================== | 249 //=========================== TouchResourceOperation =========================== |
| 250 | 250 |
| 251 // This class performs the operation to touch a document/file/directory. | 251 // This class performs the operation to touch a document/file/directory. |
| 252 // This uses "files.patch" of Drive API v2 rather than "files.touch". See also: | 252 // This uses "files.patch" of Drive API v2 rather than "files.touch". See also: |
| 253 // https://developers.google.com/drive/v2/reference/files/patch, and | 253 // https://developers.google.com/drive/v2/reference/files/patch, and |
| 254 // https://developers.google.com/drive/v2/reference/files/touch | 254 // https://developers.google.com/drive/v2/reference/files/touch |
| 255 class TouchResourceOperation : public GetDataOperation { | 255 class TouchResourceOperation : public GetDataRequest { |
| 256 public: | 256 public: |
| 257 // |callback| must not be null. | 257 // |callback| must not be null. |
| 258 TouchResourceOperation( | 258 TouchResourceOperation( |
| 259 OperationRunner* runner, | 259 OperationRunner* runner, |
| 260 net::URLRequestContextGetter* url_request_context_getter, | 260 net::URLRequestContextGetter* url_request_context_getter, |
| 261 const DriveApiUrlGenerator& url_generator, | 261 const DriveApiUrlGenerator& url_generator, |
| 262 const std::string& resource_id, | 262 const std::string& resource_id, |
| 263 const base::Time& modified_date, | 263 const base::Time& modified_date, |
| 264 const base::Time& last_viewed_by_me_date, | 264 const base::Time& last_viewed_by_me_date, |
| 265 const FileResourceCallback& callback); | 265 const FileResourceCallback& callback); |
| 266 virtual ~TouchResourceOperation(); | 266 virtual ~TouchResourceOperation(); |
| 267 | 267 |
| 268 protected: | 268 protected: |
| 269 // UrlFetchOperationBase overrides. | 269 // UrlFetchRequestBase overrides. |
| 270 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 270 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
| 271 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 271 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; |
| 272 virtual GURL GetURL() const OVERRIDE; | 272 virtual GURL GetURL() const OVERRIDE; |
| 273 virtual bool GetContentData(std::string* upload_content_type, | 273 virtual bool GetContentData(std::string* upload_content_type, |
| 274 std::string* upload_content) OVERRIDE; | 274 std::string* upload_content) OVERRIDE; |
| 275 | 275 |
| 276 private: | 276 private: |
| 277 const DriveApiUrlGenerator url_generator_; | 277 const DriveApiUrlGenerator url_generator_; |
| 278 | 278 |
| 279 const std::string resource_id_; | 279 const std::string resource_id_; |
| 280 const base::Time modified_date_; | 280 const base::Time modified_date_; |
| 281 const base::Time last_viewed_by_me_date_; | 281 const base::Time last_viewed_by_me_date_; |
| 282 | 282 |
| 283 DISALLOW_COPY_AND_ASSIGN(TouchResourceOperation); | 283 DISALLOW_COPY_AND_ASSIGN(TouchResourceOperation); |
| 284 }; | 284 }; |
| 285 | 285 |
| 286 //=========================== CopyResourceOperation ============================ | 286 //=========================== CopyResourceOperation ============================ |
| 287 | 287 |
| 288 // This class performs the operation for copying a resource. | 288 // This class performs the operation for copying a resource. |
| 289 // | 289 // |
| 290 // Copies the resource with |resource_id| into a directory with | 290 // Copies the resource with |resource_id| into a directory with |
| 291 // |parent_resource_id|. The new resource will be named as |new_name|. | 291 // |parent_resource_id|. The new resource will be named as |new_name|. |
| 292 // |parent_resource_id| can be empty. In the case, the copy will be created | 292 // |parent_resource_id| can be empty. In the case, the copy will be created |
| 293 // directly under the default root directory (this is the default behavior | 293 // directly under the default root directory (this is the default behavior |
| 294 // of Drive API v2's copy operation). | 294 // of Drive API v2's copy operation). |
| 295 // | 295 // |
| 296 // This operation corresponds to "Files: copy" operation on Drive API v2. See | 296 // This operation corresponds to "Files: copy" operation on Drive API v2. See |
| 297 // also: https://developers.google.com/drive/v2/reference/files/copy | 297 // also: https://developers.google.com/drive/v2/reference/files/copy |
| 298 class CopyResourceOperation : public GetDataOperation { | 298 class CopyResourceOperation : public GetDataRequest { |
| 299 public: | 299 public: |
| 300 // Upon completion, |callback| will be called. |callback| must not be null. | 300 // Upon completion, |callback| will be called. |callback| must not be null. |
| 301 CopyResourceOperation( | 301 CopyResourceOperation( |
| 302 OperationRunner* runner, | 302 OperationRunner* runner, |
| 303 net::URLRequestContextGetter* url_request_context_getter, | 303 net::URLRequestContextGetter* url_request_context_getter, |
| 304 const DriveApiUrlGenerator& url_generator, | 304 const DriveApiUrlGenerator& url_generator, |
| 305 const std::string& resource_id, | 305 const std::string& resource_id, |
| 306 const std::string& parent_resource_id, | 306 const std::string& parent_resource_id, |
| 307 const std::string& new_name, | 307 const std::string& new_name, |
| 308 const FileResourceCallback& callback); | 308 const FileResourceCallback& callback); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 327 // This class performs the operation for trashing a resource. | 327 // This class performs the operation for trashing a resource. |
| 328 // | 328 // |
| 329 // According to the document: | 329 // According to the document: |
| 330 // https://developers.google.com/drive/v2/reference/files/trash | 330 // https://developers.google.com/drive/v2/reference/files/trash |
| 331 // the file resource will be returned from the server, which is not in the | 331 // the file resource will be returned from the server, which is not in the |
| 332 // response from WAPI server. For the transition, we simply ignore the result, | 332 // response from WAPI server. For the transition, we simply ignore the result, |
| 333 // because now we do not handle resources in trash. | 333 // because now we do not handle resources in trash. |
| 334 // Note for the naming: the name "trash" comes from the server's operation | 334 // Note for the naming: the name "trash" comes from the server's operation |
| 335 // name. In order to be consistent with the server, we chose "trash" here, | 335 // name. In order to be consistent with the server, we chose "trash" here, |
| 336 // although we are preferring the term "remove" in drive/google_api code. | 336 // although we are preferring the term "remove" in drive/google_api code. |
| 337 // TODO(hidehiko): Replace the base class to GetDataOperation. | 337 // TODO(hidehiko): Replace the base class to GetDataRequest. |
| 338 class TrashResourceOperation : public EntryActionOperation { | 338 class TrashResourceOperation : public EntryActionRequest { |
| 339 public: | 339 public: |
| 340 // |callback| must not be null. | 340 // |callback| must not be null. |
| 341 TrashResourceOperation( | 341 TrashResourceOperation( |
| 342 OperationRunner* runner, | 342 OperationRunner* runner, |
| 343 net::URLRequestContextGetter* url_request_context_getter, | 343 net::URLRequestContextGetter* url_request_context_getter, |
| 344 const DriveApiUrlGenerator& url_generator, | 344 const DriveApiUrlGenerator& url_generator, |
| 345 const std::string& resource_id, | 345 const std::string& resource_id, |
| 346 const EntryActionCallback& callback); | 346 const EntryActionCallback& callback); |
| 347 virtual ~TrashResourceOperation(); | 347 virtual ~TrashResourceOperation(); |
| 348 | 348 |
| 349 protected: | 349 protected: |
| 350 // UrlFetchOperationBase overrides. | 350 // UrlFetchRequestBase overrides. |
| 351 virtual GURL GetURL() const OVERRIDE; | 351 virtual GURL GetURL() const OVERRIDE; |
| 352 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 352 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
| 353 | 353 |
| 354 private: | 354 private: |
| 355 const DriveApiUrlGenerator url_generator_; | 355 const DriveApiUrlGenerator url_generator_; |
| 356 const std::string resource_id_; | 356 const std::string resource_id_; |
| 357 | 357 |
| 358 DISALLOW_COPY_AND_ASSIGN(TrashResourceOperation); | 358 DISALLOW_COPY_AND_ASSIGN(TrashResourceOperation); |
| 359 }; | 359 }; |
| 360 | 360 |
| 361 //========================== InsertResourceOperation =========================== | 361 //========================== InsertResourceOperation =========================== |
| 362 | 362 |
| 363 // This class performs the operation for inserting a resource to a directory. | 363 // This class performs the operation for inserting a resource to a directory. |
| 364 // Note that this is the operation of "Children: insert" of the Drive API v2. | 364 // Note that this is the operation of "Children: insert" of the Drive API v2. |
| 365 // https://developers.google.com/drive/v2/reference/children/insert. | 365 // https://developers.google.com/drive/v2/reference/children/insert. |
| 366 class InsertResourceOperation : public EntryActionOperation { | 366 class InsertResourceOperation : public EntryActionRequest { |
| 367 public: | 367 public: |
| 368 // |callback| must not be null. | 368 // |callback| must not be null. |
| 369 InsertResourceOperation( | 369 InsertResourceOperation( |
| 370 OperationRunner* runner, | 370 OperationRunner* runner, |
| 371 net::URLRequestContextGetter* url_request_context_getter, | 371 net::URLRequestContextGetter* url_request_context_getter, |
| 372 const DriveApiUrlGenerator& url_generator, | 372 const DriveApiUrlGenerator& url_generator, |
| 373 const std::string& parent_resource_id, | 373 const std::string& parent_resource_id, |
| 374 const std::string& resource_id, | 374 const std::string& resource_id, |
| 375 const EntryActionCallback& callback); | 375 const EntryActionCallback& callback); |
| 376 virtual ~InsertResourceOperation(); | 376 virtual ~InsertResourceOperation(); |
| 377 | 377 |
| 378 protected: | 378 protected: |
| 379 // UrlFetchOperationBase overrides. | 379 // UrlFetchRequestBase overrides. |
| 380 virtual GURL GetURL() const OVERRIDE; | 380 virtual GURL GetURL() const OVERRIDE; |
| 381 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 381 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
| 382 virtual bool GetContentData(std::string* upload_content_type, | 382 virtual bool GetContentData(std::string* upload_content_type, |
| 383 std::string* upload_content) OVERRIDE; | 383 std::string* upload_content) OVERRIDE; |
| 384 | 384 |
| 385 private: | 385 private: |
| 386 const DriveApiUrlGenerator url_generator_; | 386 const DriveApiUrlGenerator url_generator_; |
| 387 const std::string parent_resource_id_; | 387 const std::string parent_resource_id_; |
| 388 const std::string resource_id_; | 388 const std::string resource_id_; |
| 389 | 389 |
| 390 DISALLOW_COPY_AND_ASSIGN(InsertResourceOperation); | 390 DISALLOW_COPY_AND_ASSIGN(InsertResourceOperation); |
| 391 }; | 391 }; |
| 392 | 392 |
| 393 //========================== DeleteResourceOperation =========================== | 393 //========================== DeleteResourceOperation =========================== |
| 394 | 394 |
| 395 // This class performs the operation for removing a resource from a directory. | 395 // This class performs the operation for removing a resource from a directory. |
| 396 // Note that we use "delete" for the name of this class, which comes from the | 396 // Note that we use "delete" for the name of this class, which comes from the |
| 397 // operation name of the Drive API v2, although we prefer "remove" for that | 397 // operation name of the Drive API v2, although we prefer "remove" for that |
| 398 // sense in "drive/google_api" | 398 // sense in "drive/google_api" |
| 399 // Also note that this is the operation of "Children: delete" of the Drive API | 399 // Also note that this is the operation of "Children: delete" of the Drive API |
| 400 // v2. https://developers.google.com/drive/v2/reference/children/delete | 400 // v2. https://developers.google.com/drive/v2/reference/children/delete |
| 401 class DeleteResourceOperation : public EntryActionOperation { | 401 class DeleteResourceOperation : public EntryActionRequest { |
| 402 public: | 402 public: |
| 403 // |callback| must not be null. | 403 // |callback| must not be null. |
| 404 DeleteResourceOperation( | 404 DeleteResourceOperation( |
| 405 OperationRunner* runner, | 405 OperationRunner* runner, |
| 406 net::URLRequestContextGetter* url_request_context_getter, | 406 net::URLRequestContextGetter* url_request_context_getter, |
| 407 const DriveApiUrlGenerator& url_generator, | 407 const DriveApiUrlGenerator& url_generator, |
| 408 const std::string& parent_resource_id, | 408 const std::string& parent_resource_id, |
| 409 const std::string& resource_id, | 409 const std::string& resource_id, |
| 410 const EntryActionCallback& callback); | 410 const EntryActionCallback& callback); |
| 411 virtual ~DeleteResourceOperation(); | 411 virtual ~DeleteResourceOperation(); |
| 412 | 412 |
| 413 protected: | 413 protected: |
| 414 // UrlFetchOperationBase overrides. | 414 // UrlFetchRequestBase overrides. |
| 415 virtual GURL GetURL() const OVERRIDE; | 415 virtual GURL GetURL() const OVERRIDE; |
| 416 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 416 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
| 417 | 417 |
| 418 private: | 418 private: |
| 419 const DriveApiUrlGenerator url_generator_; | 419 const DriveApiUrlGenerator url_generator_; |
| 420 const std::string parent_resource_id_; | 420 const std::string parent_resource_id_; |
| 421 const std::string resource_id_; | 421 const std::string resource_id_; |
| 422 | 422 |
| 423 DISALLOW_COPY_AND_ASSIGN(DeleteResourceOperation); | 423 DISALLOW_COPY_AND_ASSIGN(DeleteResourceOperation); |
| 424 }; | 424 }; |
| 425 | 425 |
| 426 //======================= InitiateUploadNewFileOperation ======================= | 426 //======================= InitiateUploadNewFileOperation ======================= |
| 427 | 427 |
| 428 // This class performs the operation for initiating the upload of a new file. | 428 // This class performs the operation for initiating the upload of a new file. |
| 429 class InitiateUploadNewFileOperation : public InitiateUploadOperationBase { | 429 class InitiateUploadNewFileOperation : public InitiateUploadRequestBase { |
| 430 public: | 430 public: |
| 431 // |parent_resource_id| should be the resource id of the parent directory. | 431 // |parent_resource_id| should be the resource id of the parent directory. |
| 432 // |title| should be set. | 432 // |title| should be set. |
| 433 // See also the comments of InitiateUploadOperationBase for more details | 433 // See also the comments of InitiateUploadRequestBase for more details |
| 434 // about the other parameters. | 434 // about the other parameters. |
| 435 InitiateUploadNewFileOperation( | 435 InitiateUploadNewFileOperation( |
| 436 OperationRunner* runner, | 436 OperationRunner* runner, |
| 437 net::URLRequestContextGetter* url_request_context_getter, | 437 net::URLRequestContextGetter* url_request_context_getter, |
| 438 const DriveApiUrlGenerator& url_generator, | 438 const DriveApiUrlGenerator& url_generator, |
| 439 const base::FilePath& drive_file_path, | 439 const base::FilePath& drive_file_path, |
| 440 const std::string& content_type, | 440 const std::string& content_type, |
| 441 int64 content_length, | 441 int64 content_length, |
| 442 const std::string& parent_resource_id, | 442 const std::string& parent_resource_id, |
| 443 const std::string& title, | 443 const std::string& title, |
| 444 const InitiateUploadCallback& callback); | 444 const InitiateUploadCallback& callback); |
| 445 virtual ~InitiateUploadNewFileOperation(); | 445 virtual ~InitiateUploadNewFileOperation(); |
| 446 | 446 |
| 447 protected: | 447 protected: |
| 448 // UrlFetchOperationBase overrides. | 448 // UrlFetchRequestBase overrides. |
| 449 virtual GURL GetURL() const OVERRIDE; | 449 virtual GURL GetURL() const OVERRIDE; |
| 450 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 450 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
| 451 virtual bool GetContentData(std::string* upload_content_type, | 451 virtual bool GetContentData(std::string* upload_content_type, |
| 452 std::string* upload_content) OVERRIDE; | 452 std::string* upload_content) OVERRIDE; |
| 453 | 453 |
| 454 private: | 454 private: |
| 455 const DriveApiUrlGenerator url_generator_; | 455 const DriveApiUrlGenerator url_generator_; |
| 456 const std::string parent_resource_id_; | 456 const std::string parent_resource_id_; |
| 457 const std::string title_; | 457 const std::string title_; |
| 458 | 458 |
| 459 DISALLOW_COPY_AND_ASSIGN(InitiateUploadNewFileOperation); | 459 DISALLOW_COPY_AND_ASSIGN(InitiateUploadNewFileOperation); |
| 460 }; | 460 }; |
| 461 | 461 |
| 462 //==================== InitiateUploadExistingFileOperation ===================== | 462 //==================== InitiateUploadExistingFileOperation ===================== |
| 463 | 463 |
| 464 // This class performs the operation for initiating the upload of an existing | 464 // This class performs the operation for initiating the upload of an existing |
| 465 // file. | 465 // file. |
| 466 class InitiateUploadExistingFileOperation | 466 class InitiateUploadExistingFileOperation |
| 467 : public InitiateUploadOperationBase { | 467 : public InitiateUploadRequestBase { |
| 468 public: | 468 public: |
| 469 // |upload_url| should be the upload_url() of the file | 469 // |upload_url| should be the upload_url() of the file |
| 470 // (resumable-create-media URL) | 470 // (resumable-create-media URL) |
| 471 // |etag| should be set if it is available to detect the upload confliction. | 471 // |etag| should be set if it is available to detect the upload confliction. |
| 472 // See also the comments of InitiateUploadOperationBase for more details | 472 // See also the comments of InitiateUploadRequestBase for more details |
| 473 // about the other parameters. | 473 // about the other parameters. |
| 474 InitiateUploadExistingFileOperation( | 474 InitiateUploadExistingFileOperation( |
| 475 OperationRunner* runner, | 475 OperationRunner* runner, |
| 476 net::URLRequestContextGetter* url_request_context_getter, | 476 net::URLRequestContextGetter* url_request_context_getter, |
| 477 const DriveApiUrlGenerator& url_generator, | 477 const DriveApiUrlGenerator& url_generator, |
| 478 const base::FilePath& drive_file_path, | 478 const base::FilePath& drive_file_path, |
| 479 const std::string& content_type, | 479 const std::string& content_type, |
| 480 int64 content_length, | 480 int64 content_length, |
| 481 const std::string& resource_id, | 481 const std::string& resource_id, |
| 482 const std::string& etag, | 482 const std::string& etag, |
| 483 const InitiateUploadCallback& callback); | 483 const InitiateUploadCallback& callback); |
| 484 virtual ~InitiateUploadExistingFileOperation(); | 484 virtual ~InitiateUploadExistingFileOperation(); |
| 485 | 485 |
| 486 protected: | 486 protected: |
| 487 // UrlFetchOperationBase overrides. | 487 // UrlFetchRequestBase overrides. |
| 488 virtual GURL GetURL() const OVERRIDE; | 488 virtual GURL GetURL() const OVERRIDE; |
| 489 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 489 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
| 490 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 490 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; |
| 491 | 491 |
| 492 private: | 492 private: |
| 493 const DriveApiUrlGenerator url_generator_; | 493 const DriveApiUrlGenerator url_generator_; |
| 494 const std::string resource_id_; | 494 const std::string resource_id_; |
| 495 const std::string etag_; | 495 const std::string etag_; |
| 496 | 496 |
| 497 DISALLOW_COPY_AND_ASSIGN(InitiateUploadExistingFileOperation); | 497 DISALLOW_COPY_AND_ASSIGN(InitiateUploadExistingFileOperation); |
| 498 }; | 498 }; |
| 499 | 499 |
| 500 // Callback used for ResumeUpload() and GetUploadStatus(). | 500 // Callback used for ResumeUpload() and GetUploadStatus(). |
| 501 typedef base::Callback<void( | 501 typedef base::Callback<void( |
| 502 const UploadRangeResponse& response, | 502 const UploadRangeResponse& response, |
| 503 scoped_ptr<FileResource> new_resource)> UploadRangeCallback; | 503 scoped_ptr<FileResource> new_resource)> UploadRangeCallback; |
| 504 | 504 |
| 505 //============================ ResumeUploadOperation =========================== | 505 //============================ ResumeUploadOperation =========================== |
| 506 | 506 |
| 507 // Performs the operation for resuming the upload of a file. | 507 // Performs the operation for resuming the upload of a file. |
| 508 class ResumeUploadOperation : public ResumeUploadOperationBase { | 508 class ResumeUploadOperation : public ResumeUploadRequestBase { |
| 509 public: | 509 public: |
| 510 // See also ResumeUploadOperationBase's comment for parameters meaning. | 510 // See also ResumeUploadRequestBase's comment for parameters meaning. |
| 511 // |callback| must not be null. |progress_callback| may be null. | 511 // |callback| must not be null. |progress_callback| may be null. |
| 512 ResumeUploadOperation( | 512 ResumeUploadOperation( |
| 513 OperationRunner* runner, | 513 OperationRunner* runner, |
| 514 net::URLRequestContextGetter* url_request_context_getter, | 514 net::URLRequestContextGetter* url_request_context_getter, |
| 515 const base::FilePath& drive_file_path, | 515 const base::FilePath& drive_file_path, |
| 516 const GURL& upload_location, | 516 const GURL& upload_location, |
| 517 int64 start_position, | 517 int64 start_position, |
| 518 int64 end_position, | 518 int64 end_position, |
| 519 int64 content_length, | 519 int64 content_length, |
| 520 const std::string& content_type, | 520 const std::string& content_type, |
| 521 const base::FilePath& local_file_path, | 521 const base::FilePath& local_file_path, |
| 522 const UploadRangeCallback& callback, | 522 const UploadRangeCallback& callback, |
| 523 const ProgressCallback& progress_callback); | 523 const ProgressCallback& progress_callback); |
| 524 virtual ~ResumeUploadOperation(); | 524 virtual ~ResumeUploadOperation(); |
| 525 | 525 |
| 526 protected: | 526 protected: |
| 527 // UploadRangeOperationBase overrides. | 527 // UploadRangeRequestBase overrides. |
| 528 virtual void OnRangeOperationComplete( | 528 virtual void OnRangeRequestComplete( |
| 529 const UploadRangeResponse& response, | 529 const UploadRangeResponse& response, |
| 530 scoped_ptr<base::Value> value) OVERRIDE; | 530 scoped_ptr<base::Value> value) OVERRIDE; |
| 531 // content::UrlFetcherDelegate overrides. | 531 // content::UrlFetcherDelegate overrides. |
| 532 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, | 532 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, |
| 533 int64 current, int64 total) OVERRIDE; | 533 int64 current, int64 total) OVERRIDE; |
| 534 | 534 |
| 535 private: | 535 private: |
| 536 const UploadRangeCallback callback_; | 536 const UploadRangeCallback callback_; |
| 537 const ProgressCallback progress_callback_; | 537 const ProgressCallback progress_callback_; |
| 538 | 538 |
| 539 DISALLOW_COPY_AND_ASSIGN(ResumeUploadOperation); | 539 DISALLOW_COPY_AND_ASSIGN(ResumeUploadOperation); |
| 540 }; | 540 }; |
| 541 | 541 |
| 542 //========================== GetUploadStatusOperation ========================== | 542 //========================== GetUploadStatusOperation ========================== |
| 543 | 543 |
| 544 // Performs the operation to request the current upload status of a file. | 544 // Performs the operation to request the current upload status of a file. |
| 545 class GetUploadStatusOperation : public GetUploadStatusOperationBase { | 545 class GetUploadStatusOperation : public GetUploadStatusRequestBase { |
| 546 public: | 546 public: |
| 547 // See also GetUploadStatusOperationBase's comment for parameters meaning. | 547 // See also GetUploadStatusRequestBase's comment for parameters meaning. |
| 548 // |callback| must not be null. | 548 // |callback| must not be null. |
| 549 GetUploadStatusOperation( | 549 GetUploadStatusOperation( |
| 550 OperationRunner* runner, | 550 OperationRunner* runner, |
| 551 net::URLRequestContextGetter* url_request_context_getter, | 551 net::URLRequestContextGetter* url_request_context_getter, |
| 552 const base::FilePath& drive_file_path, | 552 const base::FilePath& drive_file_path, |
| 553 const GURL& upload_url, | 553 const GURL& upload_url, |
| 554 int64 content_length, | 554 int64 content_length, |
| 555 const UploadRangeCallback& callback); | 555 const UploadRangeCallback& callback); |
| 556 virtual ~GetUploadStatusOperation(); | 556 virtual ~GetUploadStatusOperation(); |
| 557 | 557 |
| 558 protected: | 558 protected: |
| 559 // UploadRangeOperationBase overrides. | 559 // UploadRangeRequestBase overrides. |
| 560 virtual void OnRangeOperationComplete( | 560 virtual void OnRangeRequestComplete( |
| 561 const UploadRangeResponse& response, | 561 const UploadRangeResponse& response, |
| 562 scoped_ptr<base::Value> value) OVERRIDE; | 562 scoped_ptr<base::Value> value) OVERRIDE; |
| 563 | 563 |
| 564 private: | 564 private: |
| 565 const UploadRangeCallback callback_; | 565 const UploadRangeCallback callback_; |
| 566 | 566 |
| 567 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusOperation); | 567 DISALLOW_COPY_AND_ASSIGN(GetUploadStatusOperation); |
| 568 }; | 568 }; |
| 569 | 569 |
| 570 | 570 |
| 571 } // namespace drive | 571 } // namespace drive |
| 572 } // namespace google_apis | 572 } // namespace google_apis |
| 573 | 573 |
| 574 #endif // CHROME_BROWSER_GOOGLE_APIS_DRIVE_API_OPERATIONS_H_ | 574 #endif // CHROME_BROWSER_GOOGLE_APIS_DRIVE_API_OPERATIONS_H_ |
| OLD | NEW |