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 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 } | 545 } |
546 | 546 |
547 void GDataFileSystem::CheckForUpdates() { | 547 void GDataFileSystem::CheckForUpdates() { |
548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
549 ContentOrigin initial_origin = directory_service_->origin(); | 549 ContentOrigin initial_origin = directory_service_->origin(); |
550 if (initial_origin == FROM_SERVER) { | 550 if (initial_origin == FROM_SERVER) { |
551 directory_service_->set_origin(REFRESHING); | 551 directory_service_->set_origin(REFRESHING); |
552 feed_loader_->ReloadFromServerIfNeeded( | 552 feed_loader_->ReloadFromServerIfNeeded( |
553 initial_origin, | 553 initial_origin, |
554 directory_service_->largest_changestamp(), | 554 directory_service_->largest_changestamp(), |
555 directory_service_->root()->GetFilePath(), | |
556 base::Bind(&GDataFileSystem::OnUpdateChecked, | 555 base::Bind(&GDataFileSystem::OnUpdateChecked, |
557 ui_weak_ptr_, | 556 ui_weak_ptr_, |
558 initial_origin)); | 557 initial_origin)); |
559 } | 558 } |
560 } | 559 } |
561 | 560 |
562 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin, | 561 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin, |
563 GDataFileError error, | 562 GDataFileError error) { |
564 GDataEntry* /* entry */) { | |
565 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
566 | 564 |
567 if (error != GDATA_FILE_OK) { | 565 if (error != GDATA_FILE_OK) |
568 directory_service_->set_origin(initial_origin); | 566 directory_service_->set_origin(initial_origin); |
569 } | |
570 } | 567 } |
571 | 568 |
572 GDataFileSystem::~GDataFileSystem() { | 569 GDataFileSystem::~GDataFileSystem() { |
573 // This should be called from UI thread, from GDataSystemService shutdown. | 570 // This should be called from UI thread, from GDataSystemService shutdown. |
574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
575 | 572 |
576 feed_loader_->RemoveObserver(this); | 573 feed_loader_->RemoveObserver(this); |
577 | 574 |
578 // Cancel all the in-flight operations. | 575 // Cancel all the in-flight operations. |
579 // This asynchronously cancels the URL fetch operations. | 576 // This asynchronously cancels the URL fetch operations. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 ui_weak_ptr_, | 675 ui_weak_ptr_, |
679 search_file_path, | 676 search_file_path, |
680 callback))); | 677 callback))); |
681 return; | 678 return; |
682 } else if (directory_service_->origin() == UNINITIALIZED) { | 679 } else if (directory_service_->origin() == UNINITIALIZED) { |
683 // Load root feed from this disk cache. Upon completion, kick off server | 680 // Load root feed from this disk cache. Upon completion, kick off server |
684 // fetching. | 681 // fetching. |
685 directory_service_->set_origin(INITIALIZING); | 682 directory_service_->set_origin(INITIALIZING); |
686 feed_loader_->LoadFromCache( | 683 feed_loader_->LoadFromCache( |
687 true, // should_load_from_server | 684 true, // should_load_from_server |
688 search_file_path, | |
689 // This is the initial load, hence we'll notify when it's done. | 685 // This is the initial load, hence we'll notify when it's done. |
690 base::Bind(&GDataFileSystem::RunAndNotifyInitialLoadFinished, | 686 base::Bind(&GDataFileSystem::FindAndNotifyInitialLoadFinished, |
691 ui_weak_ptr_, | 687 ui_weak_ptr_, |
688 search_file_path, | |
692 callback)); | 689 callback)); |
693 return; | 690 return; |
694 } | 691 } |
695 | 692 |
696 // Post a task to the same thread, rather than calling it here, as | 693 // Post a task to the same thread, rather than calling it here, as |
697 // FindEntryByPath() is asynchronous. | 694 // FindEntryByPath() is asynchronous. |
698 base::MessageLoopProxy::current()->PostTask( | 695 base::MessageLoopProxy::current()->PostTask( |
699 FROM_HERE, | 696 FROM_HERE, |
700 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, | 697 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, |
701 ui_weak_ptr_, | 698 ui_weak_ptr_, |
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1997 | 1994 |
1998 if (error != GDATA_FILE_OK || | 1995 if (error != GDATA_FILE_OK || |
1999 !entry_proto->file_info().is_directory()) { | 1996 !entry_proto->file_info().is_directory()) { |
2000 LOG(ERROR) << "Directory entry not found: " << file_path.value(); | 1997 LOG(ERROR) << "Directory entry not found: " << file_path.value(); |
2001 return; | 1998 return; |
2002 } | 1999 } |
2003 | 2000 |
2004 feed_loader_->LoadFromServer( | 2001 feed_loader_->LoadFromServer( |
2005 directory_service_->origin(), | 2002 directory_service_->origin(), |
2006 0, // Not delta feed. | 2003 0, // Not delta feed. |
2007 0, // Not used. | 2004 0, // Not used. |
achuithb
2012/08/15 00:13:15
Can we say what this param is?
satorux1
2012/08/15 00:26:29
Will do
satorux1
2012/08/15 01:26:23
Done.
| |
2008 true, // multiple feeds | 2005 true, // multiple feeds |
2009 file_path, | |
2010 std::string(), // No search query | 2006 std::string(), // No search query |
2011 GURL(), /* feed not explicitly set */ | 2007 GURL(), /* feed not explicitly set */ |
achuithb
2012/08/15 00:13:15
Can we use // style comment here instead?
satorux1
2012/08/15 00:26:29
Will do
satorux1
2012/08/15 01:26:23
Done.
| |
2012 entry_proto->resource_id(), | 2008 entry_proto->resource_id(), // Load the feed for this directory. |
2013 FindEntryCallback(), // Not used. | 2009 FileOperationCallback(), // Not used. |
2014 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, | 2010 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, |
2015 ui_weak_ptr_)); | 2011 ui_weak_ptr_, |
2012 file_path)); | |
2016 } | 2013 } |
2017 | 2014 |
2018 void GDataFileSystem::OnRequestDirectoryRefresh( | 2015 void GDataFileSystem::OnRequestDirectoryRefresh( |
2016 const FilePath& directory_path, | |
2019 GetDocumentsParams* params, | 2017 GetDocumentsParams* params, |
2020 GDataFileError error) { | 2018 GDataFileError error) { |
2021 DCHECK(params); | 2019 DCHECK(params); |
2022 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2020 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2023 | 2021 |
2024 const FilePath& directory_path = params->search_file_path; | |
2025 if (error != GDATA_FILE_OK) { | 2022 if (error != GDATA_FILE_OK) { |
2026 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() | 2023 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() |
2027 << ": " << error; | 2024 << ": " << error; |
2028 return; | 2025 return; |
2029 } | 2026 } |
2030 | 2027 |
2031 int64 unused_delta_feed_changestamp = 0; | 2028 int64 unused_delta_feed_changestamp = 0; |
2032 FeedToFileResourceMapUmaStats unused_uma_stats; | 2029 FeedToFileResourceMapUmaStats unused_uma_stats; |
2033 FileResourceIdMap file_map; | 2030 FileResourceIdMap file_map; |
2034 GDataWapiFeedProcessor feed_processor(directory_service_.get()); | 2031 GDataWapiFeedProcessor feed_processor(directory_service_.get()); |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2448 new std::vector<DocumentFeed*>); | 2445 new std::vector<DocumentFeed*>); |
2449 | 2446 |
2450 ContentOrigin initial_origin = directory_service_->origin(); | 2447 ContentOrigin initial_origin = directory_service_->origin(); |
2451 feed_loader_->LoadFromServer( | 2448 feed_loader_->LoadFromServer( |
2452 initial_origin, | 2449 initial_origin, |
2453 0, 0, // We don't use change stamps when fetching search | 2450 0, 0, // We don't use change stamps when fetching search |
2454 // data; we always fetch the whole result feed. | 2451 // data; we always fetch the whole result feed. |
2455 false, // Stop fetching search results after first feed | 2452 false, // Stop fetching search results after first feed |
2456 // chunk to avoid displaying huge number of search | 2453 // chunk to avoid displaying huge number of search |
2457 // results (especially since we don't cache them). | 2454 // results (especially since we don't cache them). |
2458 FilePath(), // Not used. | |
2459 search_query, | 2455 search_query, |
2460 next_feed, | 2456 next_feed, |
2461 std::string(), // No directory resource ID. | 2457 std::string(), // No directory resource ID. |
2462 FindEntryCallback(), // Not used. | 2458 FileOperationCallback(), // Not used. |
2463 base::Bind(&GDataFileSystem::OnSearch, ui_weak_ptr_, callback)); | 2459 base::Bind(&GDataFileSystem::OnSearch, ui_weak_ptr_, callback)); |
2464 } | 2460 } |
2465 | 2461 |
2466 void GDataFileSystem::OnDirectoryChanged(const FilePath& directory_path) { | 2462 void GDataFileSystem::OnDirectoryChanged(const FilePath& directory_path) { |
2467 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2463 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2468 | 2464 |
2469 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2465 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
2470 OnDirectoryChanged(directory_path)); | 2466 OnDirectoryChanged(directory_path)); |
2471 } | 2467 } |
2472 | 2468 |
2473 void GDataFileSystem::OnDocumentFeedFetched(int num_accumulated_entries) { | 2469 void GDataFileSystem::OnDocumentFeedFetched(int num_accumulated_entries) { |
2474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2475 | 2471 |
2476 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2472 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
2477 OnDocumentFeedFetched(num_accumulated_entries)); | 2473 OnDocumentFeedFetched(num_accumulated_entries)); |
2478 } | 2474 } |
2479 | 2475 |
2480 void GDataFileSystem::OnFeedFromServerLoaded() { | 2476 void GDataFileSystem::OnFeedFromServerLoaded() { |
2481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2482 | 2478 |
2483 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2479 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
2484 OnFeedFromServerLoaded()); | 2480 OnFeedFromServerLoaded()); |
2485 } | 2481 } |
2486 | 2482 |
2487 void GDataFileSystem::LoadRootFeedFromCacheForTesting() { | 2483 void GDataFileSystem::LoadRootFeedFromCacheForTesting() { |
2488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2489 | 2485 |
2490 feed_loader_->LoadFromCache( | 2486 feed_loader_->LoadFromCache( |
2491 false, // should_load_from_server. | 2487 false, // should_load_from_server. |
2492 // search_path doesn't matter if FindEntryCallback parameter is null . | 2488 FileOperationCallback()); |
2493 FilePath(), | |
2494 FindEntryCallback()); | |
2495 } | 2489 } |
2496 | 2490 |
2497 GDataFileError GDataFileSystem::UpdateFromFeedForTesting( | 2491 GDataFileError GDataFileSystem::UpdateFromFeedForTesting( |
2498 const std::vector<DocumentFeed*>& feed_list, | 2492 const std::vector<DocumentFeed*>& feed_list, |
2499 int64 start_changestamp, | 2493 int64 start_changestamp, |
2500 int64 root_feed_changestamp) { | 2494 int64 root_feed_changestamp) { |
2501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2502 | 2496 |
2503 return feed_loader_->UpdateFromFeed(feed_list, | 2497 return feed_loader_->UpdateFromFeed(feed_list, |
2504 start_changestamp, | 2498 start_changestamp, |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2834 | 2828 |
2835 void GDataFileSystem::NotifyFileSystemToBeUnmounted() { | 2829 void GDataFileSystem::NotifyFileSystemToBeUnmounted() { |
2836 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2830 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2837 | 2831 |
2838 DVLOG(1) << "File System is to be unmounted"; | 2832 DVLOG(1) << "File System is to be unmounted"; |
2839 // Notify the observers that the file system is being unmounted. | 2833 // Notify the observers that the file system is being unmounted. |
2840 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2834 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
2841 OnFileSystemBeingUnmounted()); | 2835 OnFileSystemBeingUnmounted()); |
2842 } | 2836 } |
2843 | 2837 |
2844 void GDataFileSystem::RunAndNotifyInitialLoadFinished( | 2838 void GDataFileSystem::FindAndNotifyInitialLoadFinished( |
2839 const FilePath& search_file_path, | |
2845 const FindEntryCallback& callback, | 2840 const FindEntryCallback& callback, |
2846 GDataFileError error, | 2841 GDataFileError error) { |
2847 GDataEntry* entry) { | |
2848 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2842 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2849 DCHECK(!callback.is_null()); | 2843 DCHECK(!callback.is_null()); |
2850 | 2844 |
2851 callback.Run(error, entry); | 2845 // TODO(satorux): Remove this: crbug.com/141196. |
2846 directory_service_->FindEntryByPathAndRunSync(search_file_path, callback); | |
2852 | 2847 |
2853 DVLOG(1) << "RunAndNotifyInitialLoadFinished"; | 2848 DVLOG(1) << "RunAndNotifyInitialLoadFinished"; |
2854 | 2849 |
2855 // Notify the observers that root directory has been initialized. | 2850 // Notify the observers that root directory has been initialized. |
2856 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2851 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
2857 OnInitialLoadFinished()); | 2852 OnInitialLoadFinished()); |
2858 } | 2853 } |
2859 | 2854 |
2860 GDataFileError GDataFileSystem::AddNewDirectory( | 2855 GDataFileError GDataFileSystem::AddNewDirectory( |
2861 const FilePath& directory_path, base::Value* entry_value) { | 2856 const FilePath& directory_path, base::Value* entry_value) { |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3406 return; | 3401 return; |
3407 } | 3402 } |
3408 | 3403 |
3409 PlatformFileInfoProto entry_file_info; | 3404 PlatformFileInfoProto entry_file_info; |
3410 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3405 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3411 *entry_proto->mutable_file_info() = entry_file_info; | 3406 *entry_proto->mutable_file_info() = entry_file_info; |
3412 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3407 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
3413 } | 3408 } |
3414 | 3409 |
3415 } // namespace gdata | 3410 } // namespace gdata |
OLD | NEW |