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

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

Issue 118993002: drive: Move FileSystem::LoadDirectoryIfNeeded to ChangeListLoader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix Created 7 years 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/change_list_loader.h" 5 #include "chrome/browser/chromeos/drive/change_list_loader.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 353
354 if (loaded_) { 354 if (loaded_) {
355 // We only start to check for updates iff the load is done. 355 // We only start to check for updates iff the load is done.
356 // I.e., we ignore checking updates if not loaded to avoid starting the 356 // I.e., we ignore checking updates if not loaded to avoid starting the
357 // load without user's explicit interaction (such as opening Drive). 357 // load without user's explicit interaction (such as opening Drive).
358 util::Log(logging::LOG_INFO, "Checking for updates"); 358 util::Log(logging::LOG_INFO, "Checking for updates");
359 Load(DirectoryFetchInfo(), callback); 359 Load(DirectoryFetchInfo(), callback);
360 } 360 }
361 } 361 }
362 362
363 void ChangeListLoader::LoadIfNeeded( 363 void ChangeListLoader::LoadDirectoryIfNeeded(
364 const DirectoryFetchInfo& directory_fetch_info, 364 const base::FilePath& directory_path,
365 const FileOperationCallback& callback) { 365 const FileOperationCallback& callback) {
366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
367 DCHECK(!callback.is_null()); 367 DCHECK(!callback.is_null());
368 368
369 // If the resource metadata has been already loaded, for normal change list 369 // If the resource metadata has been already loaded and not refreshing, it
370 // fetch (= empty directory_fetch_info), we have nothing to do. For "fast 370 // means the local metadata is up to date.
371 // fetch", we need to schedule a fetching if a refresh is currently 371 if (loaded_ && !IsRefreshing()) {
372 // running, because we don't want to wait a possibly large delta change 372 callback.Run(FILE_ERROR_OK);
373 // list to arrive.
374 if (loaded_ && (directory_fetch_info.empty() || !IsRefreshing())) {
375 base::MessageLoopProxy::current()->PostTask(
376 FROM_HERE,
377 base::Bind(callback, FILE_ERROR_OK));
378 return; 373 return;
379 } 374 }
380 Load(directory_fetch_info, callback); 375
376 ResourceEntry* entry = new ResourceEntry;
377 base::PostTaskAndReplyWithResult(
378 blocking_task_runner_.get(),
379 FROM_HERE,
380 base::Bind(&ResourceMetadata::GetResourceEntryByPath,
381 base::Unretained(resource_metadata_),
382 directory_path,
383 entry),
384 base::Bind(&ChangeListLoader::LoadDirectoryIfNeededAfterGetEntry,
385 weak_ptr_factory_.GetWeakPtr(),
386 directory_path,
387 callback,
388 true, // should_try_loading_parent
389 base::Owned(entry)));
390 }
391
392 void ChangeListLoader::LoadForTesting(const FileOperationCallback& callback) {
393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
394 DCHECK(!callback.is_null());
395
396 Load(DirectoryFetchInfo(), callback);
381 } 397 }
382 398
383 void ChangeListLoader::GetAboutResource( 399 void ChangeListLoader::GetAboutResource(
384 const google_apis::AboutResourceCallback& callback) { 400 const google_apis::AboutResourceCallback& callback) {
385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
386 DCHECK(!callback.is_null()); 402 DCHECK(!callback.is_null());
387 403
388 if (cached_about_resource_) { 404 if (cached_about_resource_) {
389 base::MessageLoopProxy::current()->PostTask( 405 base::MessageLoopProxy::current()->PostTask(
390 FROM_HERE, 406 FROM_HERE,
391 base::Bind( 407 base::Bind(
392 callback, 408 callback,
393 google_apis::HTTP_NO_CONTENT, 409 google_apis::HTTP_NO_CONTENT,
394 base::Passed(scoped_ptr<google_apis::AboutResource>( 410 base::Passed(scoped_ptr<google_apis::AboutResource>(
395 new google_apis::AboutResource(*cached_about_resource_))))); 411 new google_apis::AboutResource(*cached_about_resource_)))));
396 } else { 412 } else {
397 UpdateAboutResource(callback); 413 UpdateAboutResource(callback);
398 } 414 }
399 } 415 }
400 416
417 void ChangeListLoader::LoadDirectoryIfNeededAfterGetEntry(
418 const base::FilePath& directory_path,
419 const FileOperationCallback& callback,
420 bool should_try_loading_parent,
421 const ResourceEntry* entry,
422 FileError error) {
423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
424 DCHECK(!callback.is_null());
425
426 if (error == FILE_ERROR_NOT_FOUND &&
427 should_try_loading_parent &&
428 util::GetDriveGrandRootPath().IsParent(directory_path)) {
429 // This entry may be found after loading the parent.
430 LoadDirectoryIfNeeded(
431 directory_path.DirName(),
432 base::Bind(&ChangeListLoader::LoadDirectoryIfNeededAfterLoadParent,
433 weak_ptr_factory_.GetWeakPtr(),
434 directory_path,
435 callback));
436 return;
437 }
438 if (error != FILE_ERROR_OK) {
439 callback.Run(error);
440 return;
441 }
442
443 if (!entry->file_info().is_directory()) {
444 callback.Run(FILE_ERROR_NOT_A_DIRECTORY);
445 return;
446 }
447
448 // drive/other does not exist on the server.
449 if (entry->local_id() == util::kDriveOtherDirLocalId) {
450 callback.Run(FILE_ERROR_OK);
451 return;
452 }
453
454 Load(DirectoryFetchInfo(entry->resource_id(),
455 entry->directory_specific_info().changestamp()),
456 callback);
457 }
458
459 void ChangeListLoader::LoadDirectoryIfNeededAfterLoadParent(
460 const base::FilePath& directory_path,
461 const FileOperationCallback& callback,
462 FileError error) {
463 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
464 DCHECK(!callback.is_null());
465
466 if (error != FILE_ERROR_OK) {
467 callback.Run(error);
468 return;
469 }
470
471 ResourceEntry* entry = new ResourceEntry;
472 base::PostTaskAndReplyWithResult(
473 blocking_task_runner_.get(),
474 FROM_HERE,
475 base::Bind(&ResourceMetadata::GetResourceEntryByPath,
476 base::Unretained(resource_metadata_),
477 directory_path,
478 entry),
479 base::Bind(&ChangeListLoader::LoadDirectoryIfNeededAfterGetEntry,
480 weak_ptr_factory_.GetWeakPtr(),
481 directory_path,
482 callback,
483 false, // should_try_loading_parent
484 base::Owned(entry)));
485 }
486
401 void ChangeListLoader::Load(const DirectoryFetchInfo& directory_fetch_info, 487 void ChangeListLoader::Load(const DirectoryFetchInfo& directory_fetch_info,
402 const FileOperationCallback& callback) { 488 const FileOperationCallback& callback) {
403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
404 DCHECK(!callback.is_null()); 490 DCHECK(!callback.is_null());
405 491
406 // Check if this is the first time this ChangeListLoader do loading. 492 // Check if this is the first time this ChangeListLoader do loading.
407 // Note: IsRefreshing() depends on pending_load_callback_ so check in advance. 493 // Note: IsRefreshing() depends on pending_load_callback_ so check in advance.
408 const bool is_initial_load = (!loaded_ && !IsRefreshing()); 494 const bool is_initial_load = (!loaded_ && !IsRefreshing());
409 495
410 // Register the callback function to be called when it is loaded. 496 // Register the callback function to be called when it is loaded.
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 922
837 cached_about_resource_.reset( 923 cached_about_resource_.reset(
838 new google_apis::AboutResource(*about_resource)); 924 new google_apis::AboutResource(*about_resource));
839 } 925 }
840 926
841 callback.Run(status, about_resource.Pass()); 927 callback.Run(status, about_resource.Pass());
842 } 928 }
843 929
844 } // namespace internal 930 } // namespace internal
845 } // namespace drive 931 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/change_list_loader.h ('k') | chrome/browser/chromeos/drive/change_list_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698