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_WAPI_OPERATIONS_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_GDATA_WAPI_OPERATIONS_H_ |
6 #define CHROME_BROWSER_GOOGLE_APIS_GDATA_WAPI_OPERATIONS_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_GDATA_WAPI_OPERATIONS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "chrome/browser/google_apis/base_operations.h" | 11 #include "chrome/browser/google_apis/base_operations.h" |
12 #include "chrome/browser/google_apis/drive_upload_mode.h" | 12 #include "chrome/browser/google_apis/drive_upload_mode.h" |
13 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" | 13 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" |
14 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
15 | 15 |
16 namespace google_apis { | 16 namespace google_apis { |
17 | 17 |
18 class GDataWapiUrlGenerator; | 18 class GDataWapiUrlGenerator; |
19 class DocumentEntry; | 19 class DocumentEntry; |
20 | 20 |
21 //============================ GetDocumentsOperation =========================== | 21 //============================ GetDocumentsOperation =========================== |
22 | 22 |
23 // This class performs the operation for fetching a document list. | 23 // This class performs the operation for fetching a document list. |
24 class GetDocumentsOperation : public GetDataOperation { | 24 class GetDocumentsOperation : public GetDataOperation { |
25 public: | 25 public: |
26 // |start_changestamp| specifies the starting point of change list or 0 if | 26 // override_url: |
27 // all changes are necessary. | 27 // If empty, a hard-coded base URL of the WAPI server is used to fetch |
28 // If |shared_with_me| is true, it searches for the files shared to the user, | 28 // the first page of the feed. This parameter is used for fetching 2nd |
29 // otherwise searches for the files owned by the user. | 29 // page and onward. |
30 // |url| specifies URL for documents feed fetching operation. If empty URL is | 30 // |
31 // passed, the default URL is used and returns the first page of the result. | 31 // start_changestamp: |
32 // When non-first page result is requested, |url| should be specified. | 32 // This parameter specifies the starting point of a delta feed or 0 if a |
33 // full feed is necessary. | |
34 // | |
35 // search_string: | |
36 // If non-empty, fetches a list of documents that match the search | |
37 // string. | |
38 // | |
39 // shared_with_me: | |
40 // If true, fetches a list of documents shared to the user, otherwise | |
41 // fetches a list of documents owned by the user. | |
42 // | |
43 // directory_resource_id: | |
44 // If non-empty, fetches a list of documents in a particular directory. | |
33 GetDocumentsOperation(OperationRegistry* registry, | 45 GetDocumentsOperation(OperationRegistry* registry, |
34 const GDataWapiUrlGenerator& url_generator, | 46 const GDataWapiUrlGenerator& url_generator, |
35 const GURL& url, | 47 const GURL& override_url, |
36 int start_changestamp, | 48 int start_changestamp, |
37 const std::string& search_string, | 49 const std::string& search_string, |
38 bool shared_with_me, | 50 bool shared_with_me, |
39 const std::string& directory_resource_id, | 51 const std::string& directory_resource_id, |
40 const GetDataCallback& callback); | 52 const GetDataCallback& callback); |
41 virtual ~GetDocumentsOperation(); | 53 virtual ~GetDocumentsOperation(); |
42 | 54 |
43 protected: | 55 protected: |
44 // Overridden from GetDataOperation. | 56 // UrlFetchOperationBase overrides. |
45 virtual GURL GetURL() const OVERRIDE; | 57 virtual GURL GetURL() const OVERRIDE; |
46 | 58 |
47 private: | 59 private: |
48 GDataWapiUrlGenerator url_generator_; | 60 const GDataWapiUrlGenerator url_generator_; |
49 GURL override_url_; | 61 const GURL override_url_; |
50 int start_changestamp_; | 62 const int start_changestamp_; |
51 std::string search_string_; | 63 const std::string search_string_; |
52 bool shared_with_me_; | 64 const bool shared_with_me_; |
53 std::string directory_resource_id_; | 65 const std::string directory_resource_id_; |
54 | 66 |
55 DISALLOW_COPY_AND_ASSIGN(GetDocumentsOperation); | 67 DISALLOW_COPY_AND_ASSIGN(GetDocumentsOperation); |
56 }; | 68 }; |
57 | 69 |
58 //========================= GetDocumentEntryOperation ========================== | 70 //========================= GetDocumentEntryOperation ========================== |
59 | 71 |
60 // This class performs the operation for fetching a single document entry. | 72 // This class performs the operation for fetching a single document entry. |
61 class GetDocumentEntryOperation : public GetDataOperation { | 73 class GetDocumentEntryOperation : public GetDataOperation { |
62 public: | 74 public: |
63 GetDocumentEntryOperation(OperationRegistry* registry, | 75 GetDocumentEntryOperation(OperationRegistry* registry, |
64 const GDataWapiUrlGenerator& url_generator, | 76 const GDataWapiUrlGenerator& url_generator, |
65 const std::string& resource_id, | 77 const std::string& resource_id, |
66 const GetDataCallback& callback); | 78 const GetDataCallback& callback); |
67 virtual ~GetDocumentEntryOperation(); | 79 virtual ~GetDocumentEntryOperation(); |
68 | 80 |
69 protected: | 81 protected: |
70 // Overridden from GetGdataOperation. | 82 // UrlFetchOperationBase overrides. |
71 virtual GURL GetURL() const OVERRIDE; | 83 virtual GURL GetURL() const OVERRIDE; |
72 | 84 |
73 private: | 85 private: |
74 GDataWapiUrlGenerator url_generator_; | 86 const GDataWapiUrlGenerator url_generator_; |
75 // Resource id of the requested entry. | 87 // Resource id of the requested entry. |
76 std::string resource_id_; | 88 const std::string resource_id_; |
77 | 89 |
78 DISALLOW_COPY_AND_ASSIGN(GetDocumentEntryOperation); | 90 DISALLOW_COPY_AND_ASSIGN(GetDocumentEntryOperation); |
79 }; | 91 }; |
80 | 92 |
81 //========================= GetAccountMetadataOperation ======================== | 93 //========================= GetAccountMetadataOperation ======================== |
82 | 94 |
83 // This class performs the operation for fetching account metadata. | 95 // This class performs the operation for fetching account metadata. |
84 class GetAccountMetadataOperation : public GetDataOperation { | 96 class GetAccountMetadataOperation : public GetDataOperation { |
85 public: | 97 public: |
86 GetAccountMetadataOperation(OperationRegistry* registry, | 98 GetAccountMetadataOperation(OperationRegistry* registry, |
87 const GDataWapiUrlGenerator& url_generator, | 99 const GDataWapiUrlGenerator& url_generator, |
88 const GetDataCallback& callback); | 100 const GetDataCallback& callback); |
89 virtual ~GetAccountMetadataOperation(); | 101 virtual ~GetAccountMetadataOperation(); |
90 | 102 |
91 protected: | 103 protected: |
92 // Overridden from GetDataOperation. | 104 // UrlFetchOperationBase overrides. |
93 virtual GURL GetURL() const OVERRIDE; | 105 virtual GURL GetURL() const OVERRIDE; |
94 | 106 |
95 private: | 107 private: |
96 GDataWapiUrlGenerator url_generator_; | 108 const GDataWapiUrlGenerator url_generator_; |
97 DISALLOW_COPY_AND_ASSIGN(GetAccountMetadataOperation); | 109 DISALLOW_COPY_AND_ASSIGN(GetAccountMetadataOperation); |
98 }; | 110 }; |
99 | 111 |
100 //============================ DownloadFileOperation =========================== | 112 //============================ DownloadFileOperation =========================== |
101 | 113 |
102 // Callback type for DownloadDocument/DownloadFile DocumentServiceInterface | 114 // Callback type for DownloadDocument/DownloadFile DocumentServiceInterface |
103 // calls. | 115 // calls. |
104 typedef base::Callback<void(GDataErrorCode error, | 116 typedef base::Callback<void(GDataErrorCode error, |
105 const FilePath& temp_file)> DownloadActionCallback; | 117 const FilePath& temp_file)> DownloadActionCallback; |
106 | 118 |
107 // This class performs the operation for downloading of a given document/file. | 119 // This class performs the operation for downloading of a given document/file. |
108 class DownloadFileOperation : public UrlFetchOperationBase { | 120 class DownloadFileOperation : public UrlFetchOperationBase { |
109 public: | 121 public: |
122 // download_action_callback: | |
123 // This callback is called when the download is complete. | |
124 // | |
125 // get_content_callback: | |
126 // This callback is called when some part of the content is | |
127 // read. Used to read the download content progressively. | |
128 // | |
129 // content_url: | |
130 // Specifies the target file to download. | |
131 // | |
132 // drive_file_path: | |
133 // Specifies the drive path of the target file. Shown in UI. | |
134 // TODO(satorux): Remove the drive file path hack. crbug.com/163296 | |
135 // | |
136 // output_file_path: | |
137 // Specifies the file path to save the downloaded file. | |
138 // | |
110 DownloadFileOperation( | 139 DownloadFileOperation( |
111 OperationRegistry* registry, | 140 OperationRegistry* registry, |
112 const DownloadActionCallback& download_action_callback, | 141 const DownloadActionCallback& download_action_callback, |
113 const GetContentCallback& get_content_callback, | 142 const GetContentCallback& get_content_callback, |
114 const GURL& document_url, | 143 const GURL& content_url, |
115 const FilePath& virtual_path, | 144 const FilePath& drive_file_path, |
116 const FilePath& output_file_path); | 145 const FilePath& output_file_path); |
117 virtual ~DownloadFileOperation(); | 146 virtual ~DownloadFileOperation(); |
118 | 147 |
119 protected: | 148 protected: |
120 // Overridden from UrlFetchOperationBase. | 149 // UrlFetchOperationBase overrides. |
121 virtual GURL GetURL() const OVERRIDE; | 150 virtual GURL GetURL() const OVERRIDE; |
122 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 151 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
123 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 152 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
124 | 153 |
125 // Overridden from net::URLFetcherDelegate. | 154 // net::URLFetcherDelegate overrides. |
126 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, | 155 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
127 int64 current, int64 total) OVERRIDE; | 156 int64 current, int64 total) OVERRIDE; |
128 virtual bool ShouldSendDownloadData() OVERRIDE; | 157 virtual bool ShouldSendDownloadData() OVERRIDE; |
129 virtual void OnURLFetchDownloadData( | 158 virtual void OnURLFetchDownloadData( |
130 const net::URLFetcher* source, | 159 const net::URLFetcher* source, |
131 scoped_ptr<std::string> download_data) OVERRIDE; | 160 scoped_ptr<std::string> download_data) OVERRIDE; |
132 | 161 |
133 private: | 162 private: |
134 DownloadActionCallback download_action_callback_; | 163 const DownloadActionCallback download_action_callback_; |
135 GetContentCallback get_content_callback_; | 164 const GetContentCallback get_content_callback_; |
136 GURL document_url_; | 165 const GURL content_url_; |
137 | 166 |
138 DISALLOW_COPY_AND_ASSIGN(DownloadFileOperation); | 167 DISALLOW_COPY_AND_ASSIGN(DownloadFileOperation); |
139 }; | 168 }; |
140 | 169 |
141 //=========================== DeleteDocumentOperation ========================== | 170 //=========================== DeleteDocumentOperation ========================== |
142 | 171 |
143 // This class performs the operation for deleting a document. | 172 // This class performs the operation for deleting a document. |
144 class DeleteDocumentOperation : public EntryActionOperation { | 173 class DeleteDocumentOperation : public EntryActionOperation { |
145 public: | 174 public: |
146 DeleteDocumentOperation(OperationRegistry* registry, | 175 DeleteDocumentOperation(OperationRegistry* registry, |
147 const EntryActionCallback& callback, | 176 const EntryActionCallback& callback, |
148 const GURL& document_url); | 177 const GURL& edit_url); |
149 virtual ~DeleteDocumentOperation(); | 178 virtual ~DeleteDocumentOperation(); |
150 | 179 |
151 protected: | 180 protected: |
152 // Overridden from UrlFetchOperationBase. | 181 // UrlFetchOperationBase overrides. |
153 virtual GURL GetURL() const OVERRIDE; | 182 virtual GURL GetURL() const OVERRIDE; |
154 | |
155 // Overridden from EntryActionOperation. | |
156 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 183 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
157 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 184 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; |
158 | 185 |
159 private: | 186 private: |
160 GURL document_url_; | 187 const GURL edit_url_; |
161 | 188 |
162 DISALLOW_COPY_AND_ASSIGN(DeleteDocumentOperation); | 189 DISALLOW_COPY_AND_ASSIGN(DeleteDocumentOperation); |
163 }; | 190 }; |
164 | 191 |
165 //========================== CreateDirectoryOperation ========================== | 192 //========================== CreateDirectoryOperation ========================== |
166 | 193 |
167 // This class performs the operation for creating a directory. | 194 // This class performs the operation for creating a directory. |
168 class CreateDirectoryOperation : public GetDataOperation { | 195 class CreateDirectoryOperation : public GetDataOperation { |
169 public: | 196 public: |
170 // Empty |parent_content_url| will create the directory in the root folder. | 197 // A new directory will be created under a directory specified by |
198 // |parent_content_url|. If this parameter is empty, a new directory will | |
199 // be created in the root directory. | |
171 CreateDirectoryOperation(OperationRegistry* registry, | 200 CreateDirectoryOperation(OperationRegistry* registry, |
172 const GDataWapiUrlGenerator& url_generator, | 201 const GDataWapiUrlGenerator& url_generator, |
173 const GetDataCallback& callback, | 202 const GetDataCallback& callback, |
174 const GURL& parent_content_url, | 203 const GURL& parent_content_url, |
175 const FilePath::StringType& directory_name); | 204 const FilePath::StringType& directory_name); |
176 virtual ~CreateDirectoryOperation(); | 205 virtual ~CreateDirectoryOperation(); |
177 | 206 |
178 protected: | 207 protected: |
179 // Overridden from UrlFetchOperationBase. | 208 // UrlFetchOperationBase overrides. |
180 virtual GURL GetURL() const OVERRIDE; | 209 virtual GURL GetURL() const OVERRIDE; |
181 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 210 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
182 | |
183 // Overridden from UrlFetchOperationBase. | |
184 virtual bool GetContentData(std::string* upload_content_type, | 211 virtual bool GetContentData(std::string* upload_content_type, |
185 std::string* upload_content) OVERRIDE; | 212 std::string* upload_content) OVERRIDE; |
186 | 213 |
187 private: | 214 private: |
188 GDataWapiUrlGenerator url_generator_; | 215 const GDataWapiUrlGenerator url_generator_; |
189 GURL parent_content_url_; | 216 const GURL parent_content_url_; |
190 FilePath::StringType directory_name_; | 217 const FilePath::StringType directory_name_; |
191 | 218 |
192 DISALLOW_COPY_AND_ASSIGN(CreateDirectoryOperation); | 219 DISALLOW_COPY_AND_ASSIGN(CreateDirectoryOperation); |
193 }; | 220 }; |
194 | 221 |
195 //============================ CopyDocumentOperation =========================== | 222 //============================ CopyDocumentOperation =========================== |
196 | 223 |
197 // This class performs the operation for making a copy of a document. | 224 // This class performs the operation for making a copy of a hosted document. |
225 // Note that this function cannot be used to copy regular files, as it's not | |
226 // supported by WAPI. | |
198 class CopyDocumentOperation : public GetDataOperation { | 227 class CopyDocumentOperation : public GetDataOperation { |
199 public: | 228 public: |
200 CopyDocumentOperation(OperationRegistry* registry, | 229 CopyDocumentOperation(OperationRegistry* registry, |
201 const GDataWapiUrlGenerator& url_generator, | 230 const GDataWapiUrlGenerator& url_generator, |
202 const GetDataCallback& callback, | 231 const GetDataCallback& callback, |
203 const std::string& resource_id, | 232 const std::string& resource_id, |
204 const FilePath::StringType& new_name); | 233 const FilePath::StringType& new_name); |
205 virtual ~CopyDocumentOperation(); | 234 virtual ~CopyDocumentOperation(); |
206 | 235 |
207 protected: | 236 protected: |
208 // Overridden from UrlFetchOperationBase. | 237 // UrlFetchOperationBase overrides. |
209 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 238 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
210 | |
211 // Overridden from UrlFetchOperationBase. | |
212 virtual GURL GetURL() const OVERRIDE; | 239 virtual GURL GetURL() const OVERRIDE; |
213 virtual bool GetContentData(std::string* upload_content_type, | 240 virtual bool GetContentData(std::string* upload_content_type, |
214 std::string* upload_content) OVERRIDE; | 241 std::string* upload_content) OVERRIDE; |
215 | 242 |
216 private: | 243 private: |
217 GDataWapiUrlGenerator url_generator_; | 244 const GDataWapiUrlGenerator url_generator_; |
218 std::string resource_id_; | 245 const std::string resource_id_; |
219 FilePath::StringType new_name_; | 246 const FilePath::StringType new_name_; |
220 | 247 |
221 DISALLOW_COPY_AND_ASSIGN(CopyDocumentOperation); | 248 DISALLOW_COPY_AND_ASSIGN(CopyDocumentOperation); |
222 }; | 249 }; |
223 | 250 |
224 //=========================== RenameResourceOperation ========================== | 251 //=========================== RenameResourceOperation ========================== |
225 | 252 |
226 // This class performs the operation for renaming a document/file/directory. | 253 // This class performs the operation for renaming a document/file/directory. |
227 class RenameResourceOperation : public EntryActionOperation { | 254 class RenameResourceOperation : public EntryActionOperation { |
228 public: | 255 public: |
229 RenameResourceOperation(OperationRegistry* registry, | 256 RenameResourceOperation(OperationRegistry* registry, |
230 const EntryActionCallback& callback, | 257 const EntryActionCallback& callback, |
231 const GURL& document_url, | 258 const GURL& edit_url, |
232 const FilePath::StringType& new_name); | 259 const FilePath::StringType& new_name); |
233 virtual ~RenameResourceOperation(); | 260 virtual ~RenameResourceOperation(); |
234 | 261 |
235 protected: | 262 protected: |
236 // Overridden from EntryActionOperation. | 263 // UrlFetchOperationBase overrides. |
237 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 264 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
238 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 265 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; |
239 | |
240 // Overridden from UrlFetchOperationBase. | |
241 virtual GURL GetURL() const OVERRIDE; | 266 virtual GURL GetURL() const OVERRIDE; |
242 virtual bool GetContentData(std::string* upload_content_type, | 267 virtual bool GetContentData(std::string* upload_content_type, |
243 std::string* upload_content) OVERRIDE; | 268 std::string* upload_content) OVERRIDE; |
244 | 269 |
245 private: | 270 private: |
246 GURL document_url_; | 271 const GURL edit_url_; |
247 FilePath::StringType new_name_; | 272 const FilePath::StringType new_name_; |
248 | 273 |
249 DISALLOW_COPY_AND_ASSIGN(RenameResourceOperation); | 274 DISALLOW_COPY_AND_ASSIGN(RenameResourceOperation); |
250 }; | 275 }; |
251 | 276 |
252 //=========================== AuthorizeAppOperation ========================== | 277 //=========================== AuthorizeAppOperation ========================== |
253 | 278 |
254 // This class performs the operation for authorizing an application specified | 279 // This class performs the operation for authorizing an application specified |
255 // by |app_id| to access a document specified by |document_url| for . | 280 // by |app_id| to access a document specified by |edit_url| for . |
256 class AuthorizeAppOperation : public GetDataOperation { | 281 class AuthorizeAppOperation : public GetDataOperation { |
257 public: | 282 public: |
258 AuthorizeAppOperation(OperationRegistry* registry, | 283 AuthorizeAppOperation(OperationRegistry* registry, |
259 const GetDataCallback& callback, | 284 const GetDataCallback& callback, |
260 const GURL& document_url, | 285 const GURL& edit_url, |
261 const std::string& app_id); | 286 const std::string& app_id); |
262 virtual ~AuthorizeAppOperation(); | 287 virtual ~AuthorizeAppOperation(); |
263 | 288 |
264 protected: | 289 protected: |
265 // Overridden from GetDataOperation. | 290 // UrlFetchOperationBase overrides. |
266 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 291 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
267 | |
268 // Overridden from UrlFetchOperationBase. | |
269 virtual bool GetContentData(std::string* upload_content_type, | 292 virtual bool GetContentData(std::string* upload_content_type, |
270 std::string* upload_content) OVERRIDE; | 293 std::string* upload_content) OVERRIDE; |
271 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 294 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; |
272 | |
273 // Overridden from GetDataOperation. | |
274 virtual GURL GetURL() const OVERRIDE; | 295 virtual GURL GetURL() const OVERRIDE; |
275 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 296 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
276 | 297 |
277 // Must override GetDataOperation's ParseResponse because the response is XML | 298 // Must override GetDataOperation's ParseResponse because the response is XML |
278 // not JSON. | 299 // not JSON. |
279 virtual void ParseResponse(GDataErrorCode fetch_error_code, | 300 virtual void ParseResponse(GDataErrorCode fetch_error_code, |
280 const std::string& data) OVERRIDE; | 301 const std::string& data) OVERRIDE; |
281 | 302 |
282 private: | 303 private: |
283 std::string app_id_; | 304 const std::string app_id_; |
284 GURL document_url_; | 305 const GURL edit_url_; |
285 | 306 |
286 DISALLOW_COPY_AND_ASSIGN(AuthorizeAppOperation); | 307 DISALLOW_COPY_AND_ASSIGN(AuthorizeAppOperation); |
287 }; | 308 }; |
288 | 309 |
289 //======================= AddResourceToDirectoryOperation ====================== | 310 //======================= AddResourceToDirectoryOperation ====================== |
290 | 311 |
291 // This class performs the operation for adding a document/file/directory | 312 // This class performs the operation for adding a document/file/directory |
292 // to a directory. | 313 // to a directory. |
293 class AddResourceToDirectoryOperation : public EntryActionOperation { | 314 class AddResourceToDirectoryOperation : public EntryActionOperation { |
294 public: | 315 public: |
295 AddResourceToDirectoryOperation(OperationRegistry* registry, | 316 AddResourceToDirectoryOperation(OperationRegistry* registry, |
296 const GDataWapiUrlGenerator& url_generator, | 317 const GDataWapiUrlGenerator& url_generator, |
297 const EntryActionCallback& callback, | 318 const EntryActionCallback& callback, |
298 const GURL& parent_content_url, | 319 const GURL& parent_content_url, |
299 const GURL& document_url); | 320 const GURL& edit_url); |
300 virtual ~AddResourceToDirectoryOperation(); | 321 virtual ~AddResourceToDirectoryOperation(); |
301 | 322 |
302 protected: | 323 protected: |
303 // Overridden from UrlFetchOperationBase. | 324 // UrlFetchOperationBase overrides. |
304 virtual GURL GetURL() const OVERRIDE; | 325 virtual GURL GetURL() const OVERRIDE; |
305 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 326 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
306 virtual bool GetContentData(std::string* upload_content_type, | 327 virtual bool GetContentData(std::string* upload_content_type, |
307 std::string* upload_content) OVERRIDE; | 328 std::string* upload_content) OVERRIDE; |
308 | 329 |
309 private: | 330 private: |
310 GDataWapiUrlGenerator url_generator_; | 331 const GDataWapiUrlGenerator url_generator_; |
311 GURL parent_content_url_; | 332 const GURL parent_content_url_; |
312 GURL document_url_; | 333 const GURL edit_url_; |
313 | 334 |
314 DISALLOW_COPY_AND_ASSIGN(AddResourceToDirectoryOperation); | 335 DISALLOW_COPY_AND_ASSIGN(AddResourceToDirectoryOperation); |
315 }; | 336 }; |
316 | 337 |
317 //==================== RemoveResourceFromDirectoryOperation ==================== | 338 //==================== RemoveResourceFromDirectoryOperation ==================== |
318 | 339 |
319 // This class performs the operation for adding a document/file/directory | 340 // This class performs the operation for adding a document/file/directory |
320 // from a directory. | 341 // from a directory. |
321 class RemoveResourceFromDirectoryOperation : public EntryActionOperation { | 342 class RemoveResourceFromDirectoryOperation : public EntryActionOperation { |
322 public: | 343 public: |
323 RemoveResourceFromDirectoryOperation(OperationRegistry* registry, | 344 RemoveResourceFromDirectoryOperation(OperationRegistry* registry, |
324 const EntryActionCallback& callback, | 345 const EntryActionCallback& callback, |
325 const GURL& parent_content_url, | 346 const GURL& parent_content_url, |
326 const std::string& resource_id); | 347 const std::string& resource_id); |
327 virtual ~RemoveResourceFromDirectoryOperation(); | 348 virtual ~RemoveResourceFromDirectoryOperation(); |
328 | 349 |
329 protected: | 350 protected: |
330 // Overridden from UrlFetchOperationBase. | 351 // UrlFetchOperationBase overrides. |
331 virtual GURL GetURL() const OVERRIDE; | 352 virtual GURL GetURL() const OVERRIDE; |
332 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 353 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
333 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 354 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; |
334 | 355 |
335 private: | 356 private: |
336 std::string resource_id_; | 357 const std::string resource_id_; |
337 GURL parent_content_url_; | 358 const GURL parent_content_url_; |
338 | 359 |
339 DISALLOW_COPY_AND_ASSIGN(RemoveResourceFromDirectoryOperation); | 360 DISALLOW_COPY_AND_ASSIGN(RemoveResourceFromDirectoryOperation); |
340 }; | 361 }; |
341 | 362 |
342 //=========================== InitiateUploadOperation ========================== | 363 //=========================== InitiateUploadOperation ========================== |
343 | 364 |
344 // Struct for passing params needed for DriveServiceInterface::InitiateUpload() | 365 // Struct for passing params needed for DriveServiceInterface::InitiateUpload() |
345 // calls. | 366 // calls. |
346 // | 367 // |
347 // When uploading a new file (UPLOAD_NEW_FILE): | 368 // When uploading a new file (UPLOAD_NEW_FILE): |
348 // - |title| should be set. | 369 // - |title| should be set. |
349 // - |upload_location| should be the upload_url() of the parent directory. | 370 // - |upload_location| should be the upload_url() of the parent directory. |
371 // (resumable-create-media URL) | |
350 // | 372 // |
351 // When updating an existing file (UPLOAD_EXISTING_FILE): | 373 // When updating an existing file (UPLOAD_EXISTING_FILE): |
352 // - |title| should be empty | 374 // - |title| should be empty |
353 // - |upload_location| should be the upload_url() of the existing file. | 375 // - |upload_location| should be the upload_url() of the existing file. |
376 // (resumable-edit-media URL) | |
354 struct InitiateUploadParams { | 377 struct InitiateUploadParams { |
355 InitiateUploadParams(UploadMode upload_mode, | 378 InitiateUploadParams(UploadMode upload_mode, |
356 const std::string& title, | 379 const std::string& title, |
357 const std::string& content_type, | 380 const std::string& content_type, |
358 int64 content_length, | 381 int64 content_length, |
359 const GURL& upload_location, | 382 const GURL& upload_location, |
360 const FilePath& virtual_path); | 383 const FilePath& drive_file_path); |
361 ~InitiateUploadParams(); | 384 ~InitiateUploadParams(); |
362 | 385 |
363 UploadMode upload_mode; | 386 const UploadMode upload_mode; |
364 std::string title; | 387 const std::string title; |
365 std::string content_type; | 388 const std::string content_type; |
366 int64 content_length; | 389 const int64 content_length; |
367 GURL upload_location; | 390 const GURL upload_location; |
368 FilePath virtual_path; | 391 const FilePath drive_file_path; |
369 }; | 392 }; |
370 | 393 |
371 // Callback type for DocumentServiceInterface::InitiateUpload. | 394 // Callback type for DocumentServiceInterface::InitiateUpload. |
372 typedef base::Callback<void(GDataErrorCode error, | 395 typedef base::Callback<void(GDataErrorCode error, |
373 const GURL& upload_url)> InitiateUploadCallback; | 396 const GURL& upload_url)> InitiateUploadCallback; |
374 | 397 |
375 // This class performs the operation for initiating the upload of a file. | 398 // This class performs the operation for initiating the upload of a file. |
399 // |callback| will be called with the obtained upload URL. The URL will be | |
400 // used with ResumeUploadOperation to upload the content to the server. | |
401 // | |
402 // Here's the flow of uploading: | |
403 // 1) Get the upload URL with InitiateUploadOperation. | |
404 // 2) Upload the first 512KB (see kUploadChunkSize in drive_uploader.cc) | |
405 // of the target file to the upload URL | |
406 // 3) If there is more data to upload, go to 2). | |
407 // | |
376 class InitiateUploadOperation : public UrlFetchOperationBase { | 408 class InitiateUploadOperation : public UrlFetchOperationBase { |
377 public: | 409 public: |
410 // |callback| will be called with the upload URL, where upload data is | |
411 // uploaded to with ResumeUploadOperation. | |
378 InitiateUploadOperation(OperationRegistry* registry, | 412 InitiateUploadOperation(OperationRegistry* registry, |
379 const InitiateUploadCallback& callback, | 413 const InitiateUploadCallback& callback, |
380 const InitiateUploadParams& params); | 414 const InitiateUploadParams& params); |
381 virtual ~InitiateUploadOperation(); | 415 virtual ~InitiateUploadOperation(); |
382 | 416 |
383 protected: | 417 protected: |
384 // Overridden from UrlFetchOperationBase. | 418 // UrlFetchOperationBase overrides. |
385 virtual GURL GetURL() const OVERRIDE; | 419 virtual GURL GetURL() const OVERRIDE; |
386 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 420 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
387 virtual void NotifySuccessToOperationRegistry() OVERRIDE; | 421 virtual void NotifySuccessToOperationRegistry() OVERRIDE; |
388 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 422 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
389 | |
390 // Overridden from UrlFetchOperationBase. | |
391 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 423 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
392 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 424 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; |
393 virtual bool GetContentData(std::string* upload_content_type, | 425 virtual bool GetContentData(std::string* upload_content_type, |
394 std::string* upload_content) OVERRIDE; | 426 std::string* upload_content) OVERRIDE; |
395 | 427 |
396 private: | 428 private: |
397 InitiateUploadCallback callback_; | 429 const InitiateUploadCallback callback_; |
398 InitiateUploadParams params_; | 430 const InitiateUploadParams params_; |
399 GURL initiate_upload_url_; | 431 const GURL initiate_upload_url_; |
400 | 432 |
401 DISALLOW_COPY_AND_ASSIGN(InitiateUploadOperation); | 433 DISALLOW_COPY_AND_ASSIGN(InitiateUploadOperation); |
402 }; | 434 }; |
403 | 435 |
404 //============================ ResumeUploadOperation =========================== | 436 //============================ ResumeUploadOperation =========================== |
405 | 437 |
406 // Struct for response to ResumeUpload. | 438 // Struct for response to ResumeUpload. |
439 // TODO(satorux): Should return the next upload URL. crbug.com/163555 | |
407 struct ResumeUploadResponse { | 440 struct ResumeUploadResponse { |
408 ResumeUploadResponse(); | 441 ResumeUploadResponse(); |
409 ResumeUploadResponse(GDataErrorCode code, | 442 ResumeUploadResponse(GDataErrorCode code, |
410 int64 start_range_received, | 443 int64 start_range_received, |
411 int64 end_range_received); | 444 int64 end_range_received); |
412 ~ResumeUploadResponse(); | 445 ~ResumeUploadResponse(); |
413 | 446 |
414 GDataErrorCode code; | 447 const GDataErrorCode code; |
415 int64 start_range_received; | 448 const int64 start_range_received; |
416 int64 end_range_received; | 449 const int64 end_range_received; // inclusive. See below. |
417 FilePath virtual_path; | 450 const FilePath drive_file_path; |
418 }; | 451 }; |
419 | 452 |
420 // Struct for passing params needed for DriveServiceInterface::ResumeUpload() | 453 // Struct for passing params needed for DriveServiceInterface::ResumeUpload() |
421 // calls. | 454 // calls. |
422 struct ResumeUploadParams { | 455 struct ResumeUploadParams { |
423 ResumeUploadParams(UploadMode upload_mode, | 456 ResumeUploadParams(UploadMode upload_mode, |
424 int64 start_range, | 457 int64 start_range, |
425 int64 end_range, | 458 int64 end_range, |
426 int64 content_length, | 459 int64 content_length, |
427 const std::string& content_type, | 460 const std::string& content_type, |
428 scoped_refptr<net::IOBuffer> buf, | 461 scoped_refptr<net::IOBuffer> buf, |
429 const GURL& upload_location, | 462 const GURL& upload_location, |
430 const FilePath& virtual_path); | 463 const FilePath& drive_file_path); |
431 ~ResumeUploadParams(); | 464 ~ResumeUploadParams(); |
432 | 465 |
433 UploadMode upload_mode; // Mode of the upload. | 466 const UploadMode upload_mode; // Mode of the upload. |
434 int64 start_range; // Start of range of contents currently stored in |buf|. | 467 // Start of range of contents currently stored in |buf|. |
435 int64 end_range; // End of range of contents currently stored in |buf|. | 468 const int64 start_range; |
436 int64 content_length; // File content-Length. | 469 // End of range of contents currently stored in |buf|. This is inclusive. |
437 std::string content_type; // Content-Type of file. | 470 // For instance, if you are to upload the first 500 bytes of date, |
438 scoped_refptr<net::IOBuffer> buf; // Holds current content to be uploaded. | 471 // |start_range| is 0 and |end_range| is 499. |
439 GURL upload_location; // Url of where to upload the file to. | 472 const int64 end_range; |
440 // Virtual GData path of the file seen in the UI. Not necessary for | 473 const int64 content_length; // File content-Length. |
474 const std::string content_type; // Content-Type of file. | |
475 // Holds current content to be uploaded. | |
476 const scoped_refptr<net::IOBuffer> buf; | |
477 const GURL upload_location; // Url of where to upload the file to. | |
478 // Drive file path of the file seen in the UI. Not necessary for | |
441 // resuming an upload, but used for adding an entry to OperationRegistry. | 479 // resuming an upload, but used for adding an entry to OperationRegistry. |
442 FilePath virtual_path; | 480 // TODO(satorux): Remove the drive file path hack. crbug.com/163296 |
481 const FilePath drive_file_path; | |
443 }; | 482 }; |
444 | 483 |
445 // Callback type for DocumentServiceInterface::ResumeUpload. | 484 // Callback type for DocumentServiceInterface::ResumeUpload. |
446 typedef base::Callback<void( | 485 typedef base::Callback<void( |
447 const ResumeUploadResponse& response, | 486 const ResumeUploadResponse& response, |
448 scoped_ptr<google_apis::DocumentEntry> new_entry)> ResumeUploadCallback; | 487 scoped_ptr<google_apis::DocumentEntry> new_entry)> ResumeUploadCallback; |
449 | 488 |
450 // This class performs the operation for resuming the upload of a file. | 489 // This class performs the operation for resuming the upload of a file. |
490 // More specifically, this operation uploads a chunk of data carried in |buf| | |
491 // of ResumeUploadResponse. | |
451 class ResumeUploadOperation : public UrlFetchOperationBase { | 492 class ResumeUploadOperation : public UrlFetchOperationBase { |
452 public: | 493 public: |
494 // |callback| will be called on completion of the operation. | |
495 // | |
496 // If there is more data to upload, |code| in ResumeUploadParams is set to | |
497 // HTTP_RESUME_INCOMPLETE, and |new_entry| parameter is NULL. | |
498 // | |
499 // If upload is complete, |code| is set to HTTP_CREATED for a file file, or | |
kinaba
2012/11/30 09:57:26
a file file => a new file
satorux1
2012/11/30 10:09:10
Done.
| |
500 // HTTP_SUCCES for an existing file. |new_entry| contains the document | |
501 // entry of the newly uploaded file. | |
453 ResumeUploadOperation(OperationRegistry* registry, | 502 ResumeUploadOperation(OperationRegistry* registry, |
454 const ResumeUploadCallback& callback, | 503 const ResumeUploadCallback& callback, |
455 const ResumeUploadParams& params); | 504 const ResumeUploadParams& params); |
456 virtual ~ResumeUploadOperation(); | 505 virtual ~ResumeUploadOperation(); |
457 | 506 |
458 protected: | 507 protected: |
459 // Overridden from UrlFetchOperationBase. | 508 // UrlFetchOperationBase overrides. |
460 virtual GURL GetURL() const OVERRIDE; | 509 virtual GURL GetURL() const OVERRIDE; |
461 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; | 510 virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE; |
462 virtual void NotifyStartToOperationRegistry() OVERRIDE; | 511 virtual void NotifyStartToOperationRegistry() OVERRIDE; |
463 virtual void NotifySuccessToOperationRegistry() OVERRIDE; | 512 virtual void NotifySuccessToOperationRegistry() OVERRIDE; |
464 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; | 513 virtual void RunCallbackOnPrematureFailure(GDataErrorCode code) OVERRIDE; |
465 | |
466 // Overridden from UrlFetchOperationBase. | |
467 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; | 514 virtual net::URLFetcher::RequestType GetRequestType() const OVERRIDE; |
468 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; | 515 virtual std::vector<std::string> GetExtraRequestHeaders() const OVERRIDE; |
469 virtual bool GetContentData(std::string* upload_content_type, | 516 virtual bool GetContentData(std::string* upload_content_type, |
470 std::string* upload_content) OVERRIDE; | 517 std::string* upload_content) OVERRIDE; |
471 | 518 |
472 // Overridden from content::UrlFetcherDelegate | 519 // content::UrlFetcherDelegate overrides. |
473 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, | 520 virtual void OnURLFetchUploadProgress(const net::URLFetcher* source, |
474 int64 current, int64 total) OVERRIDE; | 521 int64 current, int64 total) OVERRIDE; |
475 | 522 |
476 private: | 523 private: |
477 ResumeUploadCallback callback_; | 524 const ResumeUploadCallback callback_; |
478 ResumeUploadParams params_; | 525 const ResumeUploadParams params_; |
479 bool last_chunk_completed_; | 526 bool last_chunk_completed_; |
480 | 527 |
481 DISALLOW_COPY_AND_ASSIGN(ResumeUploadOperation); | 528 DISALLOW_COPY_AND_ASSIGN(ResumeUploadOperation); |
482 }; | 529 }; |
483 | 530 |
484 } // namespace google_apis | 531 } // namespace google_apis |
485 | 532 |
486 #endif // CHROME_BROWSER_GOOGLE_APIS_GDATA_WAPI_OPERATIONS_H_ | 533 #endif // CHROME_BROWSER_GOOGLE_APIS_GDATA_WAPI_OPERATIONS_H_ |
OLD | NEW |