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