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

Side by Side Diff: chrome/browser/chromeos/drive/gdata_wapi_service.cc

Issue 11106007: drive: Rename 'gdata' namespace to 'drive' in chrome/browser/chromeos/drive (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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
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 #include "chrome/browser/chromeos/drive/gdata_wapi_service.h" 5 #include "chrome/browser/chromeos/drive/gdata_wapi_service.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
12 #include "chrome/browser/google_apis/auth_service.h" 12 #include "chrome/browser/google_apis/auth_service.h"
13 #include "chrome/browser/google_apis/drive_api_operations.h" 13 #include "chrome/browser/google_apis/drive_api_operations.h"
14 #include "chrome/browser/google_apis/gdata_operations.h" 14 #include "chrome/browser/google_apis/gdata_operations.h"
15 #include "chrome/browser/google_apis/gdata_util.h" 15 #include "chrome/browser/google_apis/gdata_util.h"
16 #include "chrome/browser/google_apis/operation_runner.h" 16 #include "chrome/browser/google_apis/operation_runner.h"
17 #include "chrome/common/net/url_util.h" 17 #include "chrome/common/net/url_util.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 19
20 using content::BrowserThread; 20 using content::BrowserThread;
21 21
22 namespace gdata { 22 namespace drive {
23 23
24 namespace { 24 namespace {
25 25
26 const char* GetExportFormatParam(DocumentExportFormat format) { 26 const char* GetExportFormatParam(DocumentExportFormat format) {
27 switch (format) { 27 switch (format) {
28 case PNG: 28 case PNG:
29 return "png"; 29 return "png";
30 case HTML: 30 case HTML:
31 return "html"; 31 return "html";
32 case TXT: 32 case TXT:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 } 72 }
73 73
74 GDataWapiService::~GDataWapiService() { 74 GDataWapiService::~GDataWapiService() {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
76 if (runner_.get()) { 76 if (runner_.get()) {
77 runner_->operation_registry()->RemoveObserver(this); 77 runner_->operation_registry()->RemoveObserver(this);
78 runner_->auth_service()->RemoveObserver(this); 78 runner_->auth_service()->RemoveObserver(this);
79 } 79 }
80 } 80 }
81 81
82 AuthService* GDataWapiService::auth_service_for_testing() { 82 gdata::AuthService* GDataWapiService::auth_service_for_testing() {
83 return runner_->auth_service(); 83 return runner_->auth_service();
84 } 84 }
85 85
86 void GDataWapiService::Initialize(Profile* profile) { 86 void GDataWapiService::Initialize(Profile* profile) {
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
88 88
89 std::vector<std::string> scopes; 89 std::vector<std::string> scopes;
90 scopes.push_back(kDocsListScope); 90 scopes.push_back(kDocsListScope);
91 scopes.push_back(kSpreadsheetsScope); 91 scopes.push_back(kSpreadsheetsScope);
92 scopes.push_back(kUserContentScope); 92 scopes.push_back(kUserContentScope);
93 // Drive App scope is required for even WAPI v3 apps access. 93 // Drive App scope is required for even WAPI v3 apps access.
94 scopes.push_back(kDriveAppsScope); 94 scopes.push_back(kDriveAppsScope);
95 runner_.reset(new OperationRunner(profile, scopes)); 95 runner_.reset(new gdata::OperationRunner(profile, scopes));
96 runner_->Initialize(); 96 runner_->Initialize();
97 97
98 runner_->auth_service()->AddObserver(this); 98 runner_->auth_service()->AddObserver(this);
99 runner_->operation_registry()->AddObserver(this); 99 runner_->operation_registry()->AddObserver(this);
100 } 100 }
101 101
102 void GDataWapiService::AddObserver(DriveServiceObserver* observer) { 102 void GDataWapiService::AddObserver(DriveServiceObserver* observer) {
103 observers_.AddObserver(observer); 103 observers_.AddObserver(observer);
104 } 104 }
105 105
(...skipping 10 matching lines...) Expand all
116 void GDataWapiService::CancelAll() { 116 void GDataWapiService::CancelAll() {
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
118 runner_->CancelAll(); 118 runner_->CancelAll();
119 } 119 }
120 120
121 bool GDataWapiService::CancelForFilePath(const FilePath& file_path) { 121 bool GDataWapiService::CancelForFilePath(const FilePath& file_path) {
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
123 return operation_registry()->CancelForFilePath(file_path); 123 return operation_registry()->CancelForFilePath(file_path);
124 } 124 }
125 125
126 OperationProgressStatusList GDataWapiService::GetProgressStatusList() const { 126 gdata::OperationProgressStatusList GDataWapiService::GetProgressStatusList()
127 const {
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
128 return operation_registry()->GetProgressStatusList(); 129 return operation_registry()->GetProgressStatusList();
129 } 130 }
130 131
131 void GDataWapiService::Authenticate(const AuthStatusCallback& callback) { 132 void GDataWapiService::Authenticate(const gdata::AuthStatusCallback& callback) {
132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
133 runner_->Authenticate(callback); 134 runner_->Authenticate(callback);
134 } 135 }
135 136
136 void GDataWapiService::GetDocuments(const GURL& url, 137 void GDataWapiService::GetDocuments(const GURL& url,
137 int64 start_changestamp, 138 int64 start_changestamp,
138 const std::string& search_query, 139 const std::string& search_query,
139 const std::string& directory_resource_id, 140 const std::string& directory_resource_id,
140 const GetDataCallback& callback) { 141 const gdata::GetDataCallback& callback) {
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
142 143
143 // Drive V2 API defines changestamp in int64, while DocumentsList API uses 144 // Drive V2 API defines changestamp in int64, while DocumentsList API uses
144 // int32. This narrowing should not cause any trouble. 145 // int32. This narrowing should not cause any trouble.
145 GetDocumentsOperation* operation = 146 gdata::GetDocumentsOperation* operation =
146 new GetDocumentsOperation(operation_registry(), 147 new gdata::GetDocumentsOperation(operation_registry(),
satorux1 2012/10/12 05:32:56 fixed the indent, and elsewhere in the file.
147 url, 148 url,
148 static_cast<int>(start_changestamp), 149 static_cast<int>(start_changestamp),
149 search_query, 150 search_query,
150 directory_resource_id, 151 directory_resource_id,
151 callback); 152 callback);
152 runner_->StartOperationWithRetry(operation); 153 runner_->StartOperationWithRetry(operation);
153 } 154 }
154 155
155 void GDataWapiService::GetDocumentEntry(const std::string& resource_id, 156 void GDataWapiService::GetDocumentEntry(
156 const GetDataCallback& callback) { 157 const std::string& resource_id,
158 const gdata::GetDataCallback& callback) {
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
158 160
159 GetDocumentEntryOperation* operation = 161 gdata::GetDocumentEntryOperation* operation =
160 new GetDocumentEntryOperation(operation_registry(), 162 new gdata::GetDocumentEntryOperation(operation_registry(),
161 resource_id, 163 resource_id,
162 callback); 164 callback);
163 runner_->StartOperationWithRetry(operation); 165 runner_->StartOperationWithRetry(operation);
164 } 166 }
165 167
166 void GDataWapiService::GetAccountMetadata(const GetDataCallback& callback) { 168 void GDataWapiService::GetAccountMetadata(
169 const gdata::GetDataCallback& callback) {
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
168 171
169 GetAccountMetadataOperation* operation = 172 gdata::GetAccountMetadataOperation* operation =
170 new GetAccountMetadataOperation(operation_registry(), callback); 173 new gdata::GetAccountMetadataOperation(operation_registry(), callback);
171 runner_->StartOperationWithRetry(operation); 174 runner_->StartOperationWithRetry(operation);
172 } 175 }
173 176
174 void GDataWapiService::GetApplicationInfo(const GetDataCallback& callback) { 177 void GDataWapiService::GetApplicationInfo(
178 const gdata::GetDataCallback& callback) {
175 // For WAPI, AccountMetadata includes Drive application information. 179 // For WAPI, AccountMetadata includes Drive application information.
176 GetAccountMetadata(callback); 180 GetAccountMetadata(callback);
177 } 181 }
178 182
179 void GDataWapiService::DownloadDocument( 183 void GDataWapiService::DownloadDocument(
180 const FilePath& virtual_path, 184 const FilePath& virtual_path,
181 const FilePath& local_cache_path, 185 const FilePath& local_cache_path,
182 const GURL& document_url, 186 const GURL& document_url,
183 DocumentExportFormat format, 187 DocumentExportFormat format,
184 const DownloadActionCallback& callback) { 188 const gdata::DownloadActionCallback& callback) {
185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
186 190
187 DownloadFile( 191 DownloadFile(
188 virtual_path, 192 virtual_path,
189 local_cache_path, 193 local_cache_path,
190 chrome_common_net::AppendQueryParameter(document_url, 194 chrome_common_net::AppendQueryParameter(document_url,
191 "exportFormat", 195 "exportFormat",
192 GetExportFormatParam(format)), 196 GetExportFormatParam(format)),
193 callback, 197 callback,
194 GetContentCallback()); 198 gdata::GetContentCallback());
195 } 199 }
196 200
197 void GDataWapiService::DownloadFile( 201 void GDataWapiService::DownloadFile(
198 const FilePath& virtual_path, 202 const FilePath& virtual_path,
199 const FilePath& local_cache_path, 203 const FilePath& local_cache_path,
200 const GURL& document_url, 204 const GURL& document_url,
201 const DownloadActionCallback& download_action_callback, 205 const gdata::DownloadActionCallback& download_action_callback,
202 const GetContentCallback& get_content_callback) { 206 const gdata::GetContentCallback& get_content_callback) {
203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
204 208
205 runner_->StartOperationWithRetry( 209 runner_->StartOperationWithRetry(
206 new DownloadFileOperation(operation_registry(), 210 new gdata::DownloadFileOperation(operation_registry(),
207 download_action_callback, 211 download_action_callback,
208 get_content_callback, document_url, 212 get_content_callback, document_url,
209 virtual_path, local_cache_path)); 213 virtual_path, local_cache_path));
210 } 214 }
211 215
212 void GDataWapiService::DeleteDocument(const GURL& document_url, 216 void GDataWapiService::DeleteDocument(
213 const EntryActionCallback& callback) { 217 const GURL& document_url,
218 const gdata::EntryActionCallback& callback) {
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
215 220
216 runner_->StartOperationWithRetry( 221 runner_->StartOperationWithRetry(
217 new DeleteDocumentOperation(operation_registry(), callback, 222 new gdata::DeleteDocumentOperation(operation_registry(), callback,
218 document_url)); 223 document_url));
219 } 224 }
220 225
221 void GDataWapiService::CreateDirectory( 226 void GDataWapiService::CreateDirectory(
222 const GURL& parent_content_url, 227 const GURL& parent_content_url,
223 const FilePath::StringType& directory_name, 228 const FilePath::StringType& directory_name,
224 const GetDataCallback& callback) { 229 const gdata::GetDataCallback& callback) {
225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
226 231
227 runner_->StartOperationWithRetry( 232 runner_->StartOperationWithRetry(
228 new CreateDirectoryOperation(operation_registry(), callback, 233 new gdata::CreateDirectoryOperation(operation_registry(), callback,
229 parent_content_url, directory_name)); 234 parent_content_url, directory_name));
230 } 235 }
231 236
232 void GDataWapiService::CopyDocument(const std::string& resource_id, 237 void GDataWapiService::CopyDocument(const std::string& resource_id,
233 const FilePath::StringType& new_name, 238 const FilePath::StringType& new_name,
234 const GetDataCallback& callback) { 239 const gdata::GetDataCallback& callback) {
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
236 241
237 runner_->StartOperationWithRetry( 242 runner_->StartOperationWithRetry(
238 new CopyDocumentOperation(operation_registry(), callback, 243 new gdata::CopyDocumentOperation(operation_registry(), callback,
239 resource_id, new_name)); 244 resource_id, new_name));
240 } 245 }
241 246
242 void GDataWapiService::RenameResource(const GURL& resource_url, 247 void GDataWapiService::RenameResource(
243 const FilePath::StringType& new_name, 248 const GURL& resource_url,
244 const EntryActionCallback& callback) { 249 const FilePath::StringType& new_name,
250 const gdata::EntryActionCallback& callback) {
245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
246 252
247 runner_->StartOperationWithRetry( 253 runner_->StartOperationWithRetry(
248 new RenameResourceOperation(operation_registry(), callback, 254 new gdata::RenameResourceOperation(operation_registry(), callback,
249 resource_url, new_name)); 255 resource_url, new_name));
250 } 256 }
251 257
252 void GDataWapiService::AddResourceToDirectory( 258 void GDataWapiService::AddResourceToDirectory(
253 const GURL& parent_content_url, 259 const GURL& parent_content_url,
254 const GURL& resource_url, 260 const GURL& resource_url,
255 const EntryActionCallback& callback) { 261 const gdata::EntryActionCallback& callback) {
256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
257 263
258 runner_->StartOperationWithRetry( 264 runner_->StartOperationWithRetry(
259 new AddResourceToDirectoryOperation(operation_registry(), 265 new gdata::AddResourceToDirectoryOperation(operation_registry(),
260 callback, 266 callback,
261 parent_content_url, 267 parent_content_url,
262 resource_url)); 268 resource_url));
263 } 269 }
264 270
265 void GDataWapiService::RemoveResourceFromDirectory( 271 void GDataWapiService::RemoveResourceFromDirectory(
266 const GURL& parent_content_url, 272 const GURL& parent_content_url,
267 const GURL& resource_url, 273 const GURL& resource_url,
268 const std::string& resource_id, 274 const std::string& resource_id,
269 const EntryActionCallback& callback) { 275 const gdata::EntryActionCallback& callback) {
270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
271 277
272 runner_->StartOperationWithRetry( 278 runner_->StartOperationWithRetry(
273 new RemoveResourceFromDirectoryOperation(operation_registry(), 279 new gdata::RemoveResourceFromDirectoryOperation(operation_registry(),
274 callback, 280 callback,
275 parent_content_url, 281 parent_content_url,
276 resource_url, 282 resource_url,
277 resource_id)); 283 resource_id));
278 } 284 }
279 285
280 void GDataWapiService::InitiateUpload(const InitiateUploadParams& params, 286 void GDataWapiService::InitiateUpload(
281 const InitiateUploadCallback& callback) { 287 const gdata::InitiateUploadParams& params,
288 const gdata::InitiateUploadCallback& callback) {
282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
283 290
284 if (params.upload_location.is_empty()) { 291 if (params.upload_location.is_empty()) {
285 if (!callback.is_null()) 292 if (!callback.is_null())
286 callback.Run(HTTP_BAD_REQUEST, GURL()); 293 callback.Run(gdata::HTTP_BAD_REQUEST, GURL());
287 return; 294 return;
288 } 295 }
289 296
290 runner_->StartOperationWithRetry( 297 runner_->StartOperationWithRetry(
291 new InitiateUploadOperation(operation_registry(), callback, params)); 298 new gdata::InitiateUploadOperation(
299 operation_registry(), callback, params));
292 } 300 }
293 301
294 void GDataWapiService::ResumeUpload(const ResumeUploadParams& params, 302 void GDataWapiService::ResumeUpload(
295 const ResumeUploadCallback& callback) { 303 const gdata::ResumeUploadParams& params,
304 const gdata::ResumeUploadCallback& callback) {
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
297 306
298 runner_->StartOperationWithRetry( 307 runner_->StartOperationWithRetry(
299 new ResumeUploadOperation(operation_registry(), callback, params)); 308 new gdata::ResumeUploadOperation(
309 operation_registry(), callback, params));
300 } 310 }
301 311
302 void GDataWapiService::AuthorizeApp(const GURL& resource_url, 312 void GDataWapiService::AuthorizeApp(const GURL& resource_url,
303 const std::string& app_ids, 313 const std::string& app_ids,
304 const GetDataCallback& callback) { 314 const gdata::GetDataCallback& callback) {
305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
306 316
307 runner_->StartOperationWithRetry( 317 runner_->StartOperationWithRetry(
308 new AuthorizeAppsOperation(operation_registry(), callback, 318 new gdata::AuthorizeAppsOperation(operation_registry(), callback,
309 resource_url, app_ids)); 319 resource_url, app_ids));
310 } 320 }
311 321
312 bool GDataWapiService::HasAccessToken() const { 322 bool GDataWapiService::HasAccessToken() const {
313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
314 324
315 return runner_->auth_service()->HasAccessToken(); 325 return runner_->auth_service()->HasAccessToken();
316 } 326 }
317 327
318 bool GDataWapiService::HasRefreshToken() const { 328 bool GDataWapiService::HasRefreshToken() const {
319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
320 330
321 return runner_->auth_service()->HasRefreshToken(); 331 return runner_->auth_service()->HasRefreshToken();
322 } 332 }
323 333
324 OperationRegistry* GDataWapiService::operation_registry() const { 334 gdata::OperationRegistry* GDataWapiService::operation_registry() const {
325 return runner_->operation_registry(); 335 return runner_->operation_registry();
326 } 336 }
327 337
328 void GDataWapiService::OnOAuth2RefreshTokenChanged() { 338 void GDataWapiService::OnOAuth2RefreshTokenChanged() {
329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
330 if (CanStartOperation()) { 340 if (CanStartOperation()) {
331 FOR_EACH_OBSERVER( 341 FOR_EACH_OBSERVER(
332 DriveServiceObserver, observers_, OnReadyToPerformOperations()); 342 DriveServiceObserver, observers_, OnReadyToPerformOperations());
333 } 343 }
334 } 344 }
335 345
336 void GDataWapiService::OnProgressUpdate( 346 void GDataWapiService::OnProgressUpdate(
337 const OperationProgressStatusList& list) { 347 const gdata::OperationProgressStatusList& list) {
338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
339 FOR_EACH_OBSERVER( 349 FOR_EACH_OBSERVER(
340 DriveServiceObserver, observers_, OnProgressUpdate(list)); 350 DriveServiceObserver, observers_, OnProgressUpdate(list));
341 } 351 }
342 352
343 void GDataWapiService::OnAuthenticationFailed(GDataErrorCode error) { 353 void GDataWapiService::OnAuthenticationFailed(gdata::GDataErrorCode error) {
344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
345 FOR_EACH_OBSERVER( 355 FOR_EACH_OBSERVER(
346 DriveServiceObserver, observers_, OnAuthenticationFailed(error)); 356 DriveServiceObserver, observers_, OnAuthenticationFailed(error));
347 } 357 }
348 358
349 } // namespace gdata 359 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698