Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_documents_service.cc

Issue 10829375: Cleanup: separate WAPI and Drive API code in gdata_documents_service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for comments Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h"
6
7 #include <string>
8
9 #include "base/bind.h"
10 #include "base/message_loop_proxy.h"
11 #include "chrome/browser/chromeos/gdata/drive_api_operations.h"
12 #include "chrome/browser/chromeos/gdata/gdata_operation_runner.h"
13 #include "chrome/browser/chromeos/gdata/gdata_operations.h"
14 #include "chrome/browser/chromeos/gdata/gdata_util.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/net/url_util.h"
17 #include "content/public/browser/browser_thread.h"
18
19 using content::BrowserThread;
20
21 namespace gdata {
22
23 namespace {
24
25 const char* GetExportFormatParam(DocumentExportFormat format) {
26 switch (format) {
27 case PNG:
28 return "png";
29 case HTML:
30 return "html";
31 case TXT:
32 return "txt";
33 case DOC:
34 return "doc";
35 case ODT:
36 return "odt";
37 case RTF:
38 return "rtf";
39 case ZIP:
40 return "zip";
41 case JPEG:
42 return "jpeg";
43 case SVG:
44 return "svg";
45 case PPT:
46 return "ppt";
47 case XLS:
48 return "xls";
49 case CSV:
50 return "csv";
51 case ODS:
52 return "ods";
53 case TSV:
54 return "tsv";
55 default:
56 return "pdf";
57 }
58 }
59
60 } // namespace
61
62 DocumentsService::DocumentsService()
63 : profile_(NULL),
64 runner_(NULL) {
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
66 }
67
68 DocumentsService::~DocumentsService() {
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
70 }
71
72 GDataAuthService* DocumentsService::auth_service_for_testing() {
73 return runner_->auth_service();
74 }
75
76 void DocumentsService::Initialize(Profile* profile) {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
78 profile_ = profile;
79 runner_.reset(new GDataOperationRunner(profile));
80 runner_->Initialize();
81 }
82
83 GDataOperationRegistry* DocumentsService::operation_registry() const {
84 return runner_->operation_registry();
85 }
86
87 void DocumentsService::CancelAll() {
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
89 runner_->CancelAll();
90 }
91
92 void DocumentsService::Authenticate(const AuthStatusCallback& callback) {
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
94 runner_->Authenticate(callback);
95 }
96
97 void DocumentsService::GetDocuments(const GURL& url,
98 int start_changestamp,
99 const std::string& search_query,
100 const std::string& directory_resource_id,
101 const GetDataCallback& callback) {
102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
103
104 GetDocumentsOperation* operation =
105 new GetDocumentsOperation(operation_registry(),
106 url,
107 start_changestamp,
108 search_query,
109 directory_resource_id,
110 callback);
111 runner_->StartOperationWithRetry(operation);
112 }
113
114 void DocumentsService::GetFilelist(const GURL& url,
115 const std::string& search_query,
116 const GetDataCallback& callback) {
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
118
119 GetFilelistOperation* operation =
120 new GetFilelistOperation(operation_registry(),
121 url,
122 search_query,
123 callback);
124 runner_->StartOperationWithRetry(operation);
125 }
126
127 void DocumentsService::GetChangelist(const GURL& url,
128 int64 start_changestamp,
129 const GetDataCallback& callback) {
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
131
132 GetChangelistOperation* operation =
133 new GetChangelistOperation(operation_registry(),
134 url,
135 start_changestamp,
136 callback);
137 runner_->StartOperationWithRetry(operation);
138 }
139
140 void DocumentsService::GetDocumentEntry(const std::string& resource_id,
141 const GetDataCallback& callback) {
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
143
144 GetDocumentEntryOperation* operation =
145 new GetDocumentEntryOperation(operation_registry(),
146 resource_id,
147 callback);
148 runner_->StartOperationWithRetry(operation);
149 }
150
151 void DocumentsService::GetFile(const std::string& file_id,
152 const GetDataCallback& callback) {
153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
154
155 GetFileOperation* operation =
156 new GetFileOperation(operation_registry(),
157 file_id,
158 callback);
159 runner_->StartOperationWithRetry(operation);
160 }
161
162 void DocumentsService::GetAccountMetadata(const GetDataCallback& callback) {
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
164
165 GetAccountMetadataOperation* operation =
166 new GetAccountMetadataOperation(operation_registry(), callback);
167 runner_->StartOperationWithRetry(operation);
168 }
169
170 void DocumentsService::GetAboutResource(const GetDataCallback& callback) {
171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
172
173 GetAboutOperation* operation =
174 new GetAboutOperation(operation_registry(), callback);
175 runner_->StartOperationWithRetry(operation);
176 }
177
178 void DocumentsService::GetApplicationList(const GetDataCallback& callback) {
179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
180
181 GetApplistOperation* operation =
182 new GetApplistOperation(operation_registry(), callback);
183 runner_->StartOperationWithRetry(operation);
184 }
185
186 void DocumentsService::DownloadDocument(
187 const FilePath& virtual_path,
188 const FilePath& local_cache_path,
189 const GURL& document_url,
190 DocumentExportFormat format,
191 const DownloadActionCallback& callback) {
192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
193
194 DownloadFile(
195 virtual_path,
196 local_cache_path,
197 chrome_common_net::AppendQueryParameter(document_url,
198 "exportFormat",
199 GetExportFormatParam(format)),
200 callback,
201 GetContentCallback());
202 }
203
204 void DocumentsService::DownloadFile(
205 const FilePath& virtual_path,
206 const FilePath& local_cache_path,
207 const GURL& document_url,
208 const DownloadActionCallback& download_action_callback,
209 const GetContentCallback& get_content_callback) {
210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
211
212 runner_->StartOperationWithRetry(
213 new DownloadFileOperation(operation_registry(),
214 download_action_callback,
215 get_content_callback, document_url,
216 virtual_path, local_cache_path));
217 }
218
219 void DocumentsService::DeleteDocument(const GURL& document_url,
220 const EntryActionCallback& callback) {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
222
223 runner_->StartOperationWithRetry(
224 new DeleteDocumentOperation(operation_registry(), callback,
225 document_url));
226 }
227
228 void DocumentsService::CreateDirectory(
229 const GURL& parent_content_url,
230 const FilePath::StringType& directory_name,
231 const GetDataCallback& callback) {
232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
233
234 runner_->StartOperationWithRetry(
235 new CreateDirectoryOperation(operation_registry(), callback,
236 parent_content_url, directory_name));
237 }
238
239 void DocumentsService::CopyDocument(const std::string& resource_id,
240 const FilePath::StringType& new_name,
241 const GetDataCallback& callback) {
242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
243
244 runner_->StartOperationWithRetry(
245 new CopyDocumentOperation(operation_registry(), callback,
246 resource_id, new_name));
247 }
248
249 void DocumentsService::RenameResource(const GURL& resource_url,
250 const FilePath::StringType& new_name,
251 const EntryActionCallback& callback) {
252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
253
254 runner_->StartOperationWithRetry(
255 new RenameResourceOperation(operation_registry(), callback,
256 resource_url, new_name));
257 }
258
259 void DocumentsService::AddResourceToDirectory(
260 const GURL& parent_content_url,
261 const GURL& resource_url,
262 const EntryActionCallback& callback) {
263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
264
265 runner_->StartOperationWithRetry(
266 new AddResourceToDirectoryOperation(operation_registry(),
267 callback,
268 parent_content_url,
269 resource_url));
270 }
271
272 void DocumentsService::RemoveResourceFromDirectory(
273 const GURL& parent_content_url,
274 const GURL& resource_url,
275 const std::string& resource_id,
276 const EntryActionCallback& callback) {
277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
278
279 runner_->StartOperationWithRetry(
280 new RemoveResourceFromDirectoryOperation(operation_registry(),
281 callback,
282 parent_content_url,
283 resource_url,
284 resource_id));
285 }
286
287 void DocumentsService::InitiateUpload(const InitiateUploadParams& params,
288 const InitiateUploadCallback& callback) {
289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
290
291 if (params.upload_location.is_empty()) {
292 if (!callback.is_null())
293 callback.Run(HTTP_BAD_REQUEST, GURL());
294 return;
295 }
296
297 runner_->StartOperationWithRetry(
298 new InitiateUploadOperation(operation_registry(), callback, params));
299 }
300
301 void DocumentsService::ResumeUpload(const ResumeUploadParams& params,
302 const ResumeUploadCallback& callback) {
303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
304
305 runner_->StartOperationWithRetry(
306 new ResumeUploadOperation(operation_registry(), callback, params));
307 }
308
309
310 void DocumentsService::AuthorizeApp(const GURL& resource_url,
311 const std::string& app_ids,
312 const GetDataCallback& callback) {
313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
314
315 runner_->StartOperationWithRetry(
316 new AuthorizeAppsOperation(operation_registry(), callback,
317 resource_url, app_ids));
318 }
319
320 bool DocumentsService::HasAccessToken() const {
321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
322
323 return runner_->auth_service()->HasAccessToken();
324 }
325
326 bool DocumentsService::HasRefreshToken() const {
327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
328
329 return runner_->auth_service()->HasRefreshToken();
330 }
331
332 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698