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

Side by Side Diff: chrome/browser/google_apis/drive_api_service.cc

Issue 16175003: google_apis: Rename OperationRunner to RequestSender (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 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/google_apis/drive_api_service.h" 5 #include "chrome/browser/google_apis/drive_api_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/message_loop_proxy.h" 11 #include "base/message_loop/message_loop_proxy.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/task_runner_util.h" 13 #include "base/task_runner_util.h"
14 #include "base/threading/sequenced_worker_pool.h" 14 #include "base/threading/sequenced_worker_pool.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/google_apis/auth_service.h" 16 #include "chrome/browser/google_apis/auth_service.h"
17 #include "chrome/browser/google_apis/drive_api_operations.h" 17 #include "chrome/browser/google_apis/drive_api_operations.h"
18 #include "chrome/browser/google_apis/drive_api_parser.h" 18 #include "chrome/browser/google_apis/drive_api_parser.h"
19 #include "chrome/browser/google_apis/drive_api_util.h" 19 #include "chrome/browser/google_apis/drive_api_util.h"
20 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 20 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
21 #include "chrome/browser/google_apis/operation_runner.h" 21 #include "chrome/browser/google_apis/request_sender.h"
22 #include "chrome/browser/google_apis/time_util.h" 22 #include "chrome/browser/google_apis/time_util.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
25 25
26 using content::BrowserThread; 26 using content::BrowserThread;
27 27
28 namespace google_apis { 28 namespace google_apis {
29 29
30 namespace { 30 namespace {
31 31
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 const char kDriveApiRootDirectoryResourceId[] = "root"; 218 const char kDriveApiRootDirectoryResourceId[] = "root";
219 219
220 } // namespace 220 } // namespace
221 221
222 DriveAPIService::DriveAPIService( 222 DriveAPIService::DriveAPIService(
223 net::URLRequestContextGetter* url_request_context_getter, 223 net::URLRequestContextGetter* url_request_context_getter,
224 const GURL& base_url, 224 const GURL& base_url,
225 const std::string& custom_user_agent) 225 const std::string& custom_user_agent)
226 : url_request_context_getter_(url_request_context_getter), 226 : url_request_context_getter_(url_request_context_getter),
227 profile_(NULL), 227 profile_(NULL),
228 runner_(NULL), 228 sender_(NULL),
229 url_generator_(base_url), 229 url_generator_(base_url),
230 custom_user_agent_(custom_user_agent) { 230 custom_user_agent_(custom_user_agent) {
231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
232 } 232 }
233 233
234 DriveAPIService::~DriveAPIService() { 234 DriveAPIService::~DriveAPIService() {
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
236 if (runner_.get()) 236 if (sender_.get())
237 runner_->auth_service()->RemoveObserver(this); 237 sender_->auth_service()->RemoveObserver(this);
238 } 238 }
239 239
240 void DriveAPIService::Initialize(Profile* profile) { 240 void DriveAPIService::Initialize(Profile* profile) {
241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
242 profile_ = profile; 242 profile_ = profile;
243 243
244 std::vector<std::string> scopes; 244 std::vector<std::string> scopes;
245 scopes.push_back(kDriveScope); 245 scopes.push_back(kDriveScope);
246 scopes.push_back(kDriveAppsReadonlyScope); 246 scopes.push_back(kDriveAppsReadonlyScope);
247 runner_.reset(new OperationRunner(profile, 247 sender_.reset(new RequestSender(profile,
248 url_request_context_getter_, 248 url_request_context_getter_,
249 scopes, 249 scopes,
250 custom_user_agent_)); 250 custom_user_agent_));
251 runner_->Initialize(); 251 sender_->Initialize();
252 252
253 runner_->auth_service()->AddObserver(this); 253 sender_->auth_service()->AddObserver(this);
254 } 254 }
255 255
256 void DriveAPIService::AddObserver(DriveServiceObserver* observer) { 256 void DriveAPIService::AddObserver(DriveServiceObserver* observer) {
257 observers_.AddObserver(observer); 257 observers_.AddObserver(observer);
258 } 258 }
259 259
260 void DriveAPIService::RemoveObserver(DriveServiceObserver* observer) { 260 void DriveAPIService::RemoveObserver(DriveServiceObserver* observer) {
261 observers_.RemoveObserver(observer); 261 observers_.RemoveObserver(observer);
262 } 262 }
263 263
264 bool DriveAPIService::CanStartOperation() const { 264 bool DriveAPIService::CanStartOperation() const {
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
266 266
267 return HasRefreshToken(); 267 return HasRefreshToken();
268 } 268 }
269 269
270 void DriveAPIService::CancelAll() { 270 void DriveAPIService::CancelAll() {
271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
272 runner_->CancelAll(); 272 sender_->CancelAll();
273 } 273 }
274 274
275 bool DriveAPIService::CancelForFilePath(const base::FilePath& file_path) { 275 bool DriveAPIService::CancelForFilePath(const base::FilePath& file_path) {
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
277 return runner_->operation_registry()->CancelForFilePath(file_path); 277 return sender_->operation_registry()->CancelForFilePath(file_path);
278 } 278 }
279 279
280 std::string DriveAPIService::CanonicalizeResourceId( 280 std::string DriveAPIService::CanonicalizeResourceId(
281 const std::string& resource_id) const { 281 const std::string& resource_id) const {
282 return drive::util::CanonicalizeResourceId(resource_id); 282 return drive::util::CanonicalizeResourceId(resource_id);
283 } 283 }
284 284
285 std::string DriveAPIService::GetRootResourceId() const { 285 std::string DriveAPIService::GetRootResourceId() const {
286 return kDriveApiRootDirectoryResourceId; 286 return kDriveApiRootDirectoryResourceId;
287 } 287 }
288 288
289 void DriveAPIService::GetAllResourceList( 289 void DriveAPIService::GetAllResourceList(
290 const GetResourceListCallback& callback) { 290 const GetResourceListCallback& callback) {
291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
292 DCHECK(!callback.is_null()); 292 DCHECK(!callback.is_null());
293 293
294 // The simplest way to fetch the all resources list looks files.list method, 294 // The simplest way to fetch the all resources list looks files.list method,
295 // but it seems impossible to know the returned list's changestamp. 295 // but it seems impossible to know the returned list's changestamp.
296 // Thus, instead, we use changes.list method with includeDeleted=false here. 296 // Thus, instead, we use changes.list method with includeDeleted=false here.
297 // The returned list should contain only resources currently existing. 297 // The returned list should contain only resources currently existing.
298 runner_->StartOperationWithRetry( 298 sender_->StartRequestWithRetry(
299 new GetChangelistOperation( 299 new GetChangelistOperation(
300 runner_.get(), 300 sender_.get(),
301 url_request_context_getter_, 301 url_request_context_getter_,
302 url_generator_, 302 url_generator_,
303 false, // include deleted 303 false, // include deleted
304 0, 304 0,
305 kMaxNumFilesResourcePerRequest, 305 kMaxNumFilesResourcePerRequest,
306 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback))); 306 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
307 } 307 }
308 308
309 void DriveAPIService::GetResourceListInDirectory( 309 void DriveAPIService::GetResourceListInDirectory(
310 const std::string& directory_resource_id, 310 const std::string& directory_resource_id,
311 const GetResourceListCallback& callback) { 311 const GetResourceListCallback& callback) {
312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
313 DCHECK(!directory_resource_id.empty()); 313 DCHECK(!directory_resource_id.empty());
314 DCHECK(!callback.is_null()); 314 DCHECK(!callback.is_null());
315 315
316 // Because children.list method on Drive API v2 returns only the list of 316 // Because children.list method on Drive API v2 returns only the list of
317 // children's references, but we need all file resource list. 317 // children's references, but we need all file resource list.
318 // So, here we use files.list method instead, with setting parents query. 318 // So, here we use files.list method instead, with setting parents query.
319 // After the migration from GData WAPI to Drive API v2, we should clean the 319 // After the migration from GData WAPI to Drive API v2, we should clean the
320 // code up by moving the resposibility to include "parents" in the query 320 // code up by moving the resposibility to include "parents" in the query
321 // to client side. 321 // to client side.
322 // We aren't interested in files in trash in this context, neither. 322 // We aren't interested in files in trash in this context, neither.
323 runner_->StartOperationWithRetry( 323 sender_->StartRequestWithRetry(
324 new GetFilelistOperation( 324 new GetFilelistOperation(
325 runner_.get(), 325 sender_.get(),
326 url_request_context_getter_, 326 url_request_context_getter_,
327 url_generator_, 327 url_generator_,
328 base::StringPrintf( 328 base::StringPrintf(
329 "'%s' in parents and trashed = false", 329 "'%s' in parents and trashed = false",
330 drive::util::EscapeQueryStringValue( 330 drive::util::EscapeQueryStringValue(
331 directory_resource_id).c_str()), 331 directory_resource_id).c_str()),
332 kMaxNumFilesResourcePerRequest, 332 kMaxNumFilesResourcePerRequest,
333 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback))); 333 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
334 } 334 }
335 335
336 void DriveAPIService::Search(const std::string& search_query, 336 void DriveAPIService::Search(const std::string& search_query,
337 const GetResourceListCallback& callback) { 337 const GetResourceListCallback& callback) {
338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
339 DCHECK(!search_query.empty()); 339 DCHECK(!search_query.empty());
340 DCHECK(!callback.is_null()); 340 DCHECK(!callback.is_null());
341 341
342 runner_->StartOperationWithRetry( 342 sender_->StartRequestWithRetry(
343 new GetFilelistOperation( 343 new GetFilelistOperation(
344 runner_.get(), 344 sender_.get(),
345 url_request_context_getter_, 345 url_request_context_getter_,
346 url_generator_, 346 url_generator_,
347 drive::util::TranslateQuery(search_query), 347 drive::util::TranslateQuery(search_query),
348 kMaxNumFilesResourcePerRequestForSearch, 348 kMaxNumFilesResourcePerRequestForSearch,
349 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback))); 349 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
350 } 350 }
351 351
352 void DriveAPIService::SearchByTitle( 352 void DriveAPIService::SearchByTitle(
353 const std::string& title, 353 const std::string& title,
354 const std::string& directory_resource_id, 354 const std::string& directory_resource_id,
355 const GetResourceListCallback& callback) { 355 const GetResourceListCallback& callback) {
356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
357 DCHECK(!title.empty()); 357 DCHECK(!title.empty());
358 DCHECK(!callback.is_null()); 358 DCHECK(!callback.is_null());
359 359
360 std::string query; 360 std::string query;
361 base::StringAppendF(&query, "title = '%s'", 361 base::StringAppendF(&query, "title = '%s'",
362 drive::util::EscapeQueryStringValue(title).c_str()); 362 drive::util::EscapeQueryStringValue(title).c_str());
363 if (!directory_resource_id.empty()) { 363 if (!directory_resource_id.empty()) {
364 base::StringAppendF( 364 base::StringAppendF(
365 &query, " and '%s' in parents", 365 &query, " and '%s' in parents",
366 drive::util::EscapeQueryStringValue(directory_resource_id).c_str()); 366 drive::util::EscapeQueryStringValue(directory_resource_id).c_str());
367 } 367 }
368 query += " and trashed = false"; 368 query += " and trashed = false";
369 369
370 runner_->StartOperationWithRetry( 370 sender_->StartRequestWithRetry(
371 new GetFilelistOperation( 371 new GetFilelistOperation(
372 runner_.get(), 372 sender_.get(),
373 url_request_context_getter_, 373 url_request_context_getter_,
374 url_generator_, 374 url_generator_,
375 query, 375 query,
376 kMaxNumFilesResourcePerRequest, 376 kMaxNumFilesResourcePerRequest,
377 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback))); 377 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
378 } 378 }
379 379
380 void DriveAPIService::GetChangeList(int64 start_changestamp, 380 void DriveAPIService::GetChangeList(int64 start_changestamp,
381 const GetResourceListCallback& callback) { 381 const GetResourceListCallback& callback) {
382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
383 DCHECK(!callback.is_null()); 383 DCHECK(!callback.is_null());
384 384
385 runner_->StartOperationWithRetry( 385 sender_->StartRequestWithRetry(
386 new GetChangelistOperation( 386 new GetChangelistOperation(
387 runner_.get(), 387 sender_.get(),
388 url_request_context_getter_, 388 url_request_context_getter_,
389 url_generator_, 389 url_generator_,
390 true, // include deleted 390 true, // include deleted
391 start_changestamp, 391 start_changestamp,
392 kMaxNumFilesResourcePerRequest, 392 kMaxNumFilesResourcePerRequest,
393 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback))); 393 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
394 } 394 }
395 395
396 void DriveAPIService::ContinueGetResourceList( 396 void DriveAPIService::ContinueGetResourceList(
397 const GURL& override_url, 397 const GURL& override_url,
398 const GetResourceListCallback& callback) { 398 const GetResourceListCallback& callback) {
399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
400 DCHECK(!callback.is_null()); 400 DCHECK(!callback.is_null());
401 401
402 runner_->StartOperationWithRetry( 402 sender_->StartRequestWithRetry(
403 new drive::ContinueGetFileListOperation( 403 new drive::ContinueGetFileListOperation(
404 runner_.get(), 404 sender_.get(),
405 url_request_context_getter_, 405 url_request_context_getter_,
406 override_url, 406 override_url,
407 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback))); 407 base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
408 } 408 }
409 409
410 void DriveAPIService::GetResourceEntry( 410 void DriveAPIService::GetResourceEntry(
411 const std::string& resource_id, 411 const std::string& resource_id,
412 const GetResourceEntryCallback& callback) { 412 const GetResourceEntryCallback& callback) {
413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
414 DCHECK(!callback.is_null()); 414 DCHECK(!callback.is_null());
415 415
416 runner_->StartOperationWithRetry(new GetFileOperation( 416 sender_->StartRequestWithRetry(new GetFileOperation(
417 runner_.get(), 417 sender_.get(),
418 url_request_context_getter_, 418 url_request_context_getter_,
419 url_generator_, 419 url_generator_,
420 resource_id, 420 resource_id,
421 base::Bind(&ParseResourceEntryAndRun, callback))); 421 base::Bind(&ParseResourceEntryAndRun, callback)));
422 } 422 }
423 423
424 void DriveAPIService::GetAboutResource( 424 void DriveAPIService::GetAboutResource(
425 const GetAboutResourceCallback& callback) { 425 const GetAboutResourceCallback& callback) {
426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
427 DCHECK(!callback.is_null()); 427 DCHECK(!callback.is_null());
428 428
429 runner_->StartOperationWithRetry( 429 sender_->StartRequestWithRetry(
430 new GetAboutOperation( 430 new GetAboutOperation(
431 runner_.get(), 431 sender_.get(),
432 url_request_context_getter_, 432 url_request_context_getter_,
433 url_generator_, 433 url_generator_,
434 callback)); 434 callback));
435 } 435 }
436 436
437 void DriveAPIService::GetAppList(const GetAppListCallback& callback) { 437 void DriveAPIService::GetAppList(const GetAppListCallback& callback) {
438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
439 DCHECK(!callback.is_null()); 439 DCHECK(!callback.is_null());
440 440
441 runner_->StartOperationWithRetry(new GetApplistOperation( 441 sender_->StartRequestWithRetry(new GetApplistOperation(
442 runner_.get(), 442 sender_.get(),
443 url_request_context_getter_, 443 url_request_context_getter_,
444 url_generator_, 444 url_generator_,
445 base::Bind(&ParseAppListAndRun, callback))); 445 base::Bind(&ParseAppListAndRun, callback)));
446 } 446 }
447 447
448 void DriveAPIService::DownloadFile( 448 void DriveAPIService::DownloadFile(
449 const base::FilePath& virtual_path, 449 const base::FilePath& virtual_path,
450 const base::FilePath& local_cache_path, 450 const base::FilePath& local_cache_path,
451 const GURL& download_url, 451 const GURL& download_url,
452 const DownloadActionCallback& download_action_callback, 452 const DownloadActionCallback& download_action_callback,
453 const GetContentCallback& get_content_callback, 453 const GetContentCallback& get_content_callback,
454 const ProgressCallback& progress_callback) { 454 const ProgressCallback& progress_callback) {
455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
456 DCHECK(!download_action_callback.is_null()); 456 DCHECK(!download_action_callback.is_null());
457 // get_content_callback may be null. 457 // get_content_callback may be null.
458 458
459 runner_->StartOperationWithRetry( 459 sender_->StartRequestWithRetry(
460 new DownloadFileRequest(runner_.get(), 460 new DownloadFileRequest(sender_.get(),
461 url_request_context_getter_, 461 url_request_context_getter_,
462 download_action_callback, 462 download_action_callback,
463 get_content_callback, 463 get_content_callback,
464 progress_callback, 464 progress_callback,
465 download_url, 465 download_url,
466 virtual_path, 466 virtual_path,
467 local_cache_path)); 467 local_cache_path));
468 } 468 }
469 469
470 void DriveAPIService::DeleteResource( 470 void DriveAPIService::DeleteResource(
471 const std::string& resource_id, 471 const std::string& resource_id,
472 const std::string& etag, 472 const std::string& etag,
473 const EntryActionCallback& callback) { 473 const EntryActionCallback& callback) {
474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
475 DCHECK(!callback.is_null()); 475 DCHECK(!callback.is_null());
476 476
477 runner_->StartOperationWithRetry(new drive::TrashResourceOperation( 477 sender_->StartRequestWithRetry(new drive::TrashResourceOperation(
478 runner_.get(), 478 sender_.get(),
479 url_request_context_getter_, 479 url_request_context_getter_,
480 url_generator_, 480 url_generator_,
481 resource_id, 481 resource_id,
482 callback)); 482 callback));
483 } 483 }
484 484
485 void DriveAPIService::AddNewDirectory( 485 void DriveAPIService::AddNewDirectory(
486 const std::string& parent_resource_id, 486 const std::string& parent_resource_id,
487 const std::string& directory_name, 487 const std::string& directory_name,
488 const GetResourceEntryCallback& callback) { 488 const GetResourceEntryCallback& callback) {
489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
490 DCHECK(!callback.is_null()); 490 DCHECK(!callback.is_null());
491 491
492 runner_->StartOperationWithRetry( 492 sender_->StartRequestWithRetry(
493 new drive::CreateDirectoryOperation( 493 new drive::CreateDirectoryOperation(
494 runner_.get(), 494 sender_.get(),
495 url_request_context_getter_, 495 url_request_context_getter_,
496 url_generator_, 496 url_generator_,
497 parent_resource_id, 497 parent_resource_id,
498 directory_name, 498 directory_name,
499 base::Bind(&ParseResourceEntryAndRun, callback))); 499 base::Bind(&ParseResourceEntryAndRun, callback)));
500 } 500 }
501 501
502 void DriveAPIService::CopyResource( 502 void DriveAPIService::CopyResource(
503 const std::string& resource_id, 503 const std::string& resource_id,
504 const std::string& parent_resource_id, 504 const std::string& parent_resource_id,
505 const std::string& new_name, 505 const std::string& new_name,
506 const GetResourceEntryCallback& callback) { 506 const GetResourceEntryCallback& callback) {
507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
508 DCHECK(!callback.is_null()); 508 DCHECK(!callback.is_null());
509 509
510 runner_->StartOperationWithRetry( 510 sender_->StartRequestWithRetry(
511 new drive::CopyResourceOperation( 511 new drive::CopyResourceOperation(
512 runner_.get(), 512 sender_.get(),
513 url_request_context_getter_, 513 url_request_context_getter_,
514 url_generator_, 514 url_generator_,
515 resource_id, 515 resource_id,
516 parent_resource_id, 516 parent_resource_id,
517 new_name, 517 new_name,
518 base::Bind(&ParseResourceEntryAndRun, callback))); 518 base::Bind(&ParseResourceEntryAndRun, callback)));
519 } 519 }
520 520
521 void DriveAPIService::CopyHostedDocument( 521 void DriveAPIService::CopyHostedDocument(
522 const std::string& resource_id, 522 const std::string& resource_id,
523 const std::string& new_name, 523 const std::string& new_name,
524 const GetResourceEntryCallback& callback) { 524 const GetResourceEntryCallback& callback) {
525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
526 DCHECK(!callback.is_null()); 526 DCHECK(!callback.is_null());
527 527
528 runner_->StartOperationWithRetry( 528 sender_->StartRequestWithRetry(
529 new drive::CopyResourceOperation( 529 new drive::CopyResourceOperation(
530 runner_.get(), 530 sender_.get(),
531 url_request_context_getter_, 531 url_request_context_getter_,
532 url_generator_, 532 url_generator_,
533 resource_id, 533 resource_id,
534 std::string(), // parent_resource_id. 534 std::string(), // parent_resource_id.
535 new_name, 535 new_name,
536 base::Bind(&ParseResourceEntryAndRun, callback))); 536 base::Bind(&ParseResourceEntryAndRun, callback)));
537 } 537 }
538 538
539 void DriveAPIService::RenameResource( 539 void DriveAPIService::RenameResource(
540 const std::string& resource_id, 540 const std::string& resource_id,
541 const std::string& new_name, 541 const std::string& new_name,
542 const EntryActionCallback& callback) { 542 const EntryActionCallback& callback) {
543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
544 DCHECK(!callback.is_null()); 544 DCHECK(!callback.is_null());
545 545
546 runner_->StartOperationWithRetry( 546 sender_->StartRequestWithRetry(
547 new drive::RenameResourceOperation( 547 new drive::RenameResourceOperation(
548 runner_.get(), 548 sender_.get(),
549 url_request_context_getter_, 549 url_request_context_getter_,
550 url_generator_, 550 url_generator_,
551 resource_id, 551 resource_id,
552 new_name, 552 new_name,
553 callback)); 553 callback));
554 } 554 }
555 555
556 void DriveAPIService::TouchResource( 556 void DriveAPIService::TouchResource(
557 const std::string& resource_id, 557 const std::string& resource_id,
558 const base::Time& modified_date, 558 const base::Time& modified_date,
559 const base::Time& last_viewed_by_me_date, 559 const base::Time& last_viewed_by_me_date,
560 const GetResourceEntryCallback& callback) { 560 const GetResourceEntryCallback& callback) {
561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
562 DCHECK(!modified_date.is_null()); 562 DCHECK(!modified_date.is_null());
563 DCHECK(!last_viewed_by_me_date.is_null()); 563 DCHECK(!last_viewed_by_me_date.is_null());
564 DCHECK(!callback.is_null()); 564 DCHECK(!callback.is_null());
565 565
566 runner_->StartOperationWithRetry( 566 sender_->StartRequestWithRetry(
567 new drive::TouchResourceOperation( 567 new drive::TouchResourceOperation(
568 runner_.get(), 568 sender_.get(),
569 url_request_context_getter_, 569 url_request_context_getter_,
570 url_generator_, 570 url_generator_,
571 resource_id, 571 resource_id,
572 modified_date, 572 modified_date,
573 last_viewed_by_me_date, 573 last_viewed_by_me_date,
574 base::Bind(&ParseResourceEntryAndRun, callback))); 574 base::Bind(&ParseResourceEntryAndRun, callback)));
575 } 575 }
576 576
577 void DriveAPIService::AddResourceToDirectory( 577 void DriveAPIService::AddResourceToDirectory(
578 const std::string& parent_resource_id, 578 const std::string& parent_resource_id,
579 const std::string& resource_id, 579 const std::string& resource_id,
580 const EntryActionCallback& callback) { 580 const EntryActionCallback& callback) {
581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
582 DCHECK(!callback.is_null()); 582 DCHECK(!callback.is_null());
583 583
584 runner_->StartOperationWithRetry( 584 sender_->StartRequestWithRetry(
585 new drive::InsertResourceOperation( 585 new drive::InsertResourceOperation(
586 runner_.get(), 586 sender_.get(),
587 url_request_context_getter_, 587 url_request_context_getter_,
588 url_generator_, 588 url_generator_,
589 parent_resource_id, 589 parent_resource_id,
590 resource_id, 590 resource_id,
591 callback)); 591 callback));
592 } 592 }
593 593
594 void DriveAPIService::RemoveResourceFromDirectory( 594 void DriveAPIService::RemoveResourceFromDirectory(
595 const std::string& parent_resource_id, 595 const std::string& parent_resource_id,
596 const std::string& resource_id, 596 const std::string& resource_id,
597 const EntryActionCallback& callback) { 597 const EntryActionCallback& callback) {
598 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 598 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
599 DCHECK(!callback.is_null()); 599 DCHECK(!callback.is_null());
600 600
601 runner_->StartOperationWithRetry( 601 sender_->StartRequestWithRetry(
602 new drive::DeleteResourceOperation( 602 new drive::DeleteResourceOperation(
603 runner_.get(), 603 sender_.get(),
604 url_request_context_getter_, 604 url_request_context_getter_,
605 url_generator_, 605 url_generator_,
606 parent_resource_id, 606 parent_resource_id,
607 resource_id, 607 resource_id,
608 callback)); 608 callback));
609 } 609 }
610 610
611 void DriveAPIService::InitiateUploadNewFile( 611 void DriveAPIService::InitiateUploadNewFile(
612 const base::FilePath& drive_file_path, 612 const base::FilePath& drive_file_path,
613 const std::string& content_type, 613 const std::string& content_type,
614 int64 content_length, 614 int64 content_length,
615 const std::string& parent_resource_id, 615 const std::string& parent_resource_id,
616 const std::string& title, 616 const std::string& title,
617 const InitiateUploadCallback& callback) { 617 const InitiateUploadCallback& callback) {
618 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 618 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
619 DCHECK(!callback.is_null()); 619 DCHECK(!callback.is_null());
620 620
621 runner_->StartOperationWithRetry( 621 sender_->StartRequestWithRetry(
622 new drive::InitiateUploadNewFileOperation( 622 new drive::InitiateUploadNewFileOperation(
623 runner_.get(), 623 sender_.get(),
624 url_request_context_getter_, 624 url_request_context_getter_,
625 url_generator_, 625 url_generator_,
626 drive_file_path, 626 drive_file_path,
627 content_type, 627 content_type,
628 content_length, 628 content_length,
629 parent_resource_id, 629 parent_resource_id,
630 title, 630 title,
631 callback)); 631 callback));
632 } 632 }
633 633
634 void DriveAPIService::InitiateUploadExistingFile( 634 void DriveAPIService::InitiateUploadExistingFile(
635 const base::FilePath& drive_file_path, 635 const base::FilePath& drive_file_path,
636 const std::string& content_type, 636 const std::string& content_type,
637 int64 content_length, 637 int64 content_length,
638 const std::string& resource_id, 638 const std::string& resource_id,
639 const std::string& etag, 639 const std::string& etag,
640 const InitiateUploadCallback& callback) { 640 const InitiateUploadCallback& callback) {
641 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 641 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
642 DCHECK(!callback.is_null()); 642 DCHECK(!callback.is_null());
643 643
644 runner_->StartOperationWithRetry( 644 sender_->StartRequestWithRetry(
645 new drive::InitiateUploadExistingFileOperation( 645 new drive::InitiateUploadExistingFileOperation(
646 runner_.get(), 646 sender_.get(),
647 url_request_context_getter_, 647 url_request_context_getter_,
648 url_generator_, 648 url_generator_,
649 drive_file_path, 649 drive_file_path,
650 content_type, 650 content_type,
651 content_length, 651 content_length,
652 resource_id, 652 resource_id,
653 etag, 653 etag,
654 callback)); 654 callback));
655 } 655 }
656 656
657 void DriveAPIService::ResumeUpload( 657 void DriveAPIService::ResumeUpload(
658 const base::FilePath& drive_file_path, 658 const base::FilePath& drive_file_path,
659 const GURL& upload_url, 659 const GURL& upload_url,
660 int64 start_position, 660 int64 start_position,
661 int64 end_position, 661 int64 end_position,
662 int64 content_length, 662 int64 content_length,
663 const std::string& content_type, 663 const std::string& content_type,
664 const base::FilePath& local_file_path, 664 const base::FilePath& local_file_path,
665 const UploadRangeCallback& callback, 665 const UploadRangeCallback& callback,
666 const ProgressCallback& progress_callback) { 666 const ProgressCallback& progress_callback) {
667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
668 DCHECK(!callback.is_null()); 668 DCHECK(!callback.is_null());
669 669
670 runner_->StartOperationWithRetry( 670 sender_->StartRequestWithRetry(
671 new drive::ResumeUploadOperation( 671 new drive::ResumeUploadOperation(
672 runner_.get(), 672 sender_.get(),
673 url_request_context_getter_, 673 url_request_context_getter_,
674 drive_file_path, 674 drive_file_path,
675 upload_url, 675 upload_url,
676 start_position, 676 start_position,
677 end_position, 677 end_position,
678 content_length, 678 content_length,
679 content_type, 679 content_type,
680 local_file_path, 680 local_file_path,
681 base::Bind(&ParseResourceEntryForUploadRangeAndRun, callback), 681 base::Bind(&ParseResourceEntryForUploadRangeAndRun, callback),
682 progress_callback)); 682 progress_callback));
683 } 683 }
684 684
685 void DriveAPIService::GetUploadStatus( 685 void DriveAPIService::GetUploadStatus(
686 const base::FilePath& drive_file_path, 686 const base::FilePath& drive_file_path,
687 const GURL& upload_url, 687 const GURL& upload_url,
688 int64 content_length, 688 int64 content_length,
689 const UploadRangeCallback& callback) { 689 const UploadRangeCallback& callback) {
690 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 690 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
691 DCHECK(!callback.is_null()); 691 DCHECK(!callback.is_null());
692 692
693 runner_->StartOperationWithRetry(new drive::GetUploadStatusOperation( 693 sender_->StartRequestWithRetry(new drive::GetUploadStatusOperation(
694 runner_.get(), 694 sender_.get(),
695 url_request_context_getter_, 695 url_request_context_getter_,
696 drive_file_path, 696 drive_file_path,
697 upload_url, 697 upload_url,
698 content_length, 698 content_length,
699 base::Bind(&ParseResourceEntryForUploadRangeAndRun, callback))); 699 base::Bind(&ParseResourceEntryForUploadRangeAndRun, callback)));
700 } 700 }
701 701
702 void DriveAPIService::AuthorizeApp( 702 void DriveAPIService::AuthorizeApp(
703 const std::string& resource_id, 703 const std::string& resource_id,
704 const std::string& app_id, 704 const std::string& app_id,
705 const AuthorizeAppCallback& callback) { 705 const AuthorizeAppCallback& callback) {
706 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 706 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
707 DCHECK(!callback.is_null()); 707 DCHECK(!callback.is_null());
708 708
709 runner_->StartOperationWithRetry(new GetFileOperation( 709 sender_->StartRequestWithRetry(new GetFileOperation(
710 runner_.get(), 710 sender_.get(),
711 url_request_context_getter_, 711 url_request_context_getter_,
712 url_generator_, 712 url_generator_,
713 resource_id, 713 resource_id,
714 base::Bind(&ExtractOpenUrlAndRun, app_id, callback))); 714 base::Bind(&ExtractOpenUrlAndRun, app_id, callback)));
715 } 715 }
716 716
717 bool DriveAPIService::HasAccessToken() const { 717 bool DriveAPIService::HasAccessToken() const {
718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
719 719
720 return runner_->auth_service()->HasAccessToken(); 720 return sender_->auth_service()->HasAccessToken();
721 } 721 }
722 722
723 bool DriveAPIService::HasRefreshToken() const { 723 bool DriveAPIService::HasRefreshToken() const {
724 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 724 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
725 725
726 return runner_->auth_service()->HasRefreshToken(); 726 return sender_->auth_service()->HasRefreshToken();
727 } 727 }
728 728
729 void DriveAPIService::ClearAccessToken() { 729 void DriveAPIService::ClearAccessToken() {
730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
731 return runner_->auth_service()->ClearAccessToken(); 731 return sender_->auth_service()->ClearAccessToken();
732 } 732 }
733 733
734 void DriveAPIService::ClearRefreshToken() { 734 void DriveAPIService::ClearRefreshToken() {
735 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 735 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
736 return runner_->auth_service()->ClearRefreshToken(); 736 return sender_->auth_service()->ClearRefreshToken();
737 } 737 }
738 738
739 void DriveAPIService::OnOAuth2RefreshTokenChanged() { 739 void DriveAPIService::OnOAuth2RefreshTokenChanged() {
740 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 740 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
741 if (CanStartOperation()) { 741 if (CanStartOperation()) {
742 FOR_EACH_OBSERVER( 742 FOR_EACH_OBSERVER(
743 DriveServiceObserver, observers_, OnReadyToPerformOperations()); 743 DriveServiceObserver, observers_, OnReadyToPerformOperations());
744 } else if (!HasRefreshToken()) { 744 } else if (!HasRefreshToken()) {
745 FOR_EACH_OBSERVER( 745 FOR_EACH_OBSERVER(
746 DriveServiceObserver, observers_, OnRefreshTokenInvalid()); 746 DriveServiceObserver, observers_, OnRefreshTokenInvalid());
747 } 747 }
748 } 748 }
749 749
750 } // namespace google_apis 750 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/drive_api_service.h ('k') | chrome/browser/google_apis/gdata_contacts_operations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698