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 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 } | 572 } |
573 | 573 |
574 void GDataFileSystem::CheckForUpdates() { | 574 void GDataFileSystem::CheckForUpdates() { |
575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
576 ContentOrigin initial_origin = directory_service_->origin(); | 576 ContentOrigin initial_origin = directory_service_->origin(); |
577 if (initial_origin == FROM_SERVER) { | 577 if (initial_origin == FROM_SERVER) { |
578 directory_service_->set_origin(REFRESHING); | 578 directory_service_->set_origin(REFRESHING); |
579 feed_loader_->ReloadFromServerIfNeeded( | 579 feed_loader_->ReloadFromServerIfNeeded( |
580 initial_origin, | 580 initial_origin, |
581 directory_service_->largest_changestamp(), | 581 directory_service_->largest_changestamp(), |
582 directory_service_->root()->GetFilePath(), | |
583 base::Bind(&GDataFileSystem::OnUpdateChecked, | 582 base::Bind(&GDataFileSystem::OnUpdateChecked, |
584 ui_weak_ptr_, | 583 ui_weak_ptr_, |
585 initial_origin)); | 584 initial_origin)); |
586 } | 585 } |
587 } | 586 } |
588 | 587 |
589 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin, | 588 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin, |
590 GDataFileError error, | 589 GDataFileError error) { |
591 GDataEntry* /* entry */) { | |
592 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
593 | 591 |
594 if (error != GDATA_FILE_OK) { | 592 if (error != GDATA_FILE_OK) |
595 directory_service_->set_origin(initial_origin); | 593 directory_service_->set_origin(initial_origin); |
596 } | |
597 } | 594 } |
598 | 595 |
599 GDataFileSystem::~GDataFileSystem() { | 596 GDataFileSystem::~GDataFileSystem() { |
600 // This should be called from UI thread, from GDataSystemService shutdown. | 597 // This should be called from UI thread, from GDataSystemService shutdown. |
601 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 598 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
602 | 599 |
603 feed_loader_->RemoveObserver(this); | 600 feed_loader_->RemoveObserver(this); |
604 | 601 |
605 // Cancel all the in-flight operations. | 602 // Cancel all the in-flight operations. |
606 // This asynchronously cancels the URL fetch operations. | 603 // This asynchronously cancels the URL fetch operations. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 ui_weak_ptr_, | 702 ui_weak_ptr_, |
706 search_file_path, | 703 search_file_path, |
707 callback))); | 704 callback))); |
708 return; | 705 return; |
709 } else if (directory_service_->origin() == UNINITIALIZED) { | 706 } else if (directory_service_->origin() == UNINITIALIZED) { |
710 // Load root feed from this disk cache. Upon completion, kick off server | 707 // Load root feed from this disk cache. Upon completion, kick off server |
711 // fetching. | 708 // fetching. |
712 directory_service_->set_origin(INITIALIZING); | 709 directory_service_->set_origin(INITIALIZING); |
713 feed_loader_->LoadFromCache( | 710 feed_loader_->LoadFromCache( |
714 true, // should_load_from_server | 711 true, // should_load_from_server |
715 search_file_path, | |
716 // This is the initial load, hence we'll notify when it's done. | 712 // This is the initial load, hence we'll notify when it's done. |
717 base::Bind(&GDataFileSystem::RunAndNotifyInitialLoadFinished, | 713 base::Bind(&GDataFileSystem::FindAndNotifyInitialLoadFinished, |
718 ui_weak_ptr_, | 714 ui_weak_ptr_, |
| 715 search_file_path, |
719 callback)); | 716 callback)); |
720 return; | 717 return; |
721 } | 718 } |
722 | 719 |
723 // Post a task to the same thread, rather than calling it here, as | 720 // Post a task to the same thread, rather than calling it here, as |
724 // FindEntryByPath() is asynchronous. | 721 // FindEntryByPath() is asynchronous. |
725 base::MessageLoopProxy::current()->PostTask( | 722 base::MessageLoopProxy::current()->PostTask( |
726 FROM_HERE, | 723 FROM_HERE, |
727 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, | 724 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, |
728 ui_weak_ptr_, | 725 ui_weak_ptr_, |
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2023 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2020 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2024 | 2021 |
2025 if (error != GDATA_FILE_OK || | 2022 if (error != GDATA_FILE_OK || |
2026 !entry_proto->file_info().is_directory()) { | 2023 !entry_proto->file_info().is_directory()) { |
2027 LOG(ERROR) << "Directory entry not found: " << file_path.value(); | 2024 LOG(ERROR) << "Directory entry not found: " << file_path.value(); |
2028 return; | 2025 return; |
2029 } | 2026 } |
2030 | 2027 |
2031 feed_loader_->LoadFromServer( | 2028 feed_loader_->LoadFromServer( |
2032 directory_service_->origin(), | 2029 directory_service_->origin(), |
2033 0, // Not delta feed. | 2030 0, // start_changestamp - Not a delta feed. |
2034 0, // Not used. | 2031 0, // root_feed_changestamp - Not used. |
2035 true, // multiple feeds | 2032 true, // multiple feeds |
2036 file_path, | |
2037 std::string(), // No search query | 2033 std::string(), // No search query |
2038 GURL(), /* feed not explicitly set */ | 2034 GURL(), // feed_to_load - Feed not explicitly set |
2039 entry_proto->resource_id(), | 2035 entry_proto->resource_id(), // Load the feed for this directory. |
2040 FindEntryCallback(), // Not used. | 2036 FileOperationCallback(), // load_finished_callback. |
2041 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, | 2037 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, |
2042 ui_weak_ptr_)); | 2038 ui_weak_ptr_, |
| 2039 file_path)); |
2043 } | 2040 } |
2044 | 2041 |
2045 void GDataFileSystem::OnRequestDirectoryRefresh( | 2042 void GDataFileSystem::OnRequestDirectoryRefresh( |
| 2043 const FilePath& directory_path, |
2046 GetDocumentsParams* params, | 2044 GetDocumentsParams* params, |
2047 GDataFileError error) { | 2045 GDataFileError error) { |
2048 DCHECK(params); | 2046 DCHECK(params); |
2049 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2047 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2050 | 2048 |
2051 const FilePath& directory_path = params->search_file_path; | |
2052 if (error != GDATA_FILE_OK) { | 2049 if (error != GDATA_FILE_OK) { |
2053 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() | 2050 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() |
2054 << ": " << error; | 2051 << ": " << error; |
2055 return; | 2052 return; |
2056 } | 2053 } |
2057 | 2054 |
2058 int64 unused_delta_feed_changestamp = 0; | 2055 int64 unused_delta_feed_changestamp = 0; |
2059 FeedToFileResourceMapUmaStats unused_uma_stats; | 2056 FeedToFileResourceMapUmaStats unused_uma_stats; |
2060 FileResourceIdMap file_map; | 2057 FileResourceIdMap file_map; |
2061 GDataWapiFeedProcessor feed_processor(directory_service_.get()); | 2058 GDataWapiFeedProcessor feed_processor(directory_service_.get()); |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2441 new std::vector<DocumentFeed*>); | 2438 new std::vector<DocumentFeed*>); |
2442 | 2439 |
2443 ContentOrigin initial_origin = directory_service_->origin(); | 2440 ContentOrigin initial_origin = directory_service_->origin(); |
2444 feed_loader_->LoadFromServer( | 2441 feed_loader_->LoadFromServer( |
2445 initial_origin, | 2442 initial_origin, |
2446 0, 0, // We don't use change stamps when fetching search | 2443 0, 0, // We don't use change stamps when fetching search |
2447 // data; we always fetch the whole result feed. | 2444 // data; we always fetch the whole result feed. |
2448 false, // Stop fetching search results after first feed | 2445 false, // Stop fetching search results after first feed |
2449 // chunk to avoid displaying huge number of search | 2446 // chunk to avoid displaying huge number of search |
2450 // results (especially since we don't cache them). | 2447 // results (especially since we don't cache them). |
2451 FilePath(), // Not used. | |
2452 search_query, | 2448 search_query, |
2453 next_feed, | 2449 next_feed, |
2454 std::string(), // No directory resource ID. | 2450 std::string(), // No directory resource ID. |
2455 FindEntryCallback(), // Not used. | 2451 FileOperationCallback(), // Not used. |
2456 base::Bind(&GDataFileSystem::OnSearch, ui_weak_ptr_, callback)); | 2452 base::Bind(&GDataFileSystem::OnSearch, ui_weak_ptr_, callback)); |
2457 } | 2453 } |
2458 | 2454 |
2459 void GDataFileSystem::OnDirectoryChanged(const FilePath& directory_path) { | 2455 void GDataFileSystem::OnDirectoryChanged(const FilePath& directory_path) { |
2460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2456 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2461 | 2457 |
2462 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2458 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
2463 OnDirectoryChanged(directory_path)); | 2459 OnDirectoryChanged(directory_path)); |
2464 } | 2460 } |
2465 | 2461 |
2466 void GDataFileSystem::OnDocumentFeedFetched(int num_accumulated_entries) { | 2462 void GDataFileSystem::OnDocumentFeedFetched(int num_accumulated_entries) { |
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 OnDocumentFeedFetched(num_accumulated_entries)); | 2466 OnDocumentFeedFetched(num_accumulated_entries)); |
2471 } | 2467 } |
2472 | 2468 |
2473 void GDataFileSystem::OnFeedFromServerLoaded() { | 2469 void GDataFileSystem::OnFeedFromServerLoaded() { |
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 OnFeedFromServerLoaded()); | 2473 OnFeedFromServerLoaded()); |
2478 } | 2474 } |
2479 | 2475 |
2480 void GDataFileSystem::LoadRootFeedFromCacheForTesting() { | 2476 void GDataFileSystem::LoadRootFeedFromCacheForTesting() { |
2481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2482 | 2478 |
2483 feed_loader_->LoadFromCache( | 2479 feed_loader_->LoadFromCache( |
2484 false, // should_load_from_server. | 2480 false, // should_load_from_server. |
2485 // search_path doesn't matter if FindEntryCallback parameter is null . | 2481 FileOperationCallback()); |
2486 FilePath(), | |
2487 FindEntryCallback()); | |
2488 } | 2482 } |
2489 | 2483 |
2490 GDataFileError GDataFileSystem::UpdateFromFeedForTesting( | 2484 GDataFileError GDataFileSystem::UpdateFromFeedForTesting( |
2491 const std::vector<DocumentFeed*>& feed_list, | 2485 const std::vector<DocumentFeed*>& feed_list, |
2492 int64 start_changestamp, | 2486 int64 start_changestamp, |
2493 int64 root_feed_changestamp) { | 2487 int64 root_feed_changestamp) { |
2494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2495 | 2489 |
2496 return feed_loader_->UpdateFromFeed(feed_list, | 2490 return feed_loader_->UpdateFromFeed(feed_list, |
2497 start_changestamp, | 2491 start_changestamp, |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2840 | 2834 |
2841 void GDataFileSystem::NotifyFileSystemToBeUnmounted() { | 2835 void GDataFileSystem::NotifyFileSystemToBeUnmounted() { |
2842 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2836 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2843 | 2837 |
2844 DVLOG(1) << "File System is to be unmounted"; | 2838 DVLOG(1) << "File System is to be unmounted"; |
2845 // Notify the observers that the file system is being unmounted. | 2839 // Notify the observers that the file system is being unmounted. |
2846 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2840 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
2847 OnFileSystemBeingUnmounted()); | 2841 OnFileSystemBeingUnmounted()); |
2848 } | 2842 } |
2849 | 2843 |
2850 void GDataFileSystem::RunAndNotifyInitialLoadFinished( | 2844 void GDataFileSystem::FindAndNotifyInitialLoadFinished( |
| 2845 const FilePath& search_file_path, |
2851 const FindEntryCallback& callback, | 2846 const FindEntryCallback& callback, |
2852 GDataFileError error, | 2847 GDataFileError error) { |
2853 GDataEntry* entry) { | |
2854 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2848 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2855 DCHECK(!callback.is_null()); | 2849 DCHECK(!callback.is_null()); |
2856 | 2850 |
2857 callback.Run(error, entry); | 2851 // TODO(satorux): Remove this: crbug.com/141196. |
| 2852 directory_service_->FindEntryByPathAndRunSync(search_file_path, callback); |
2858 | 2853 |
2859 DVLOG(1) << "RunAndNotifyInitialLoadFinished"; | 2854 DVLOG(1) << "RunAndNotifyInitialLoadFinished"; |
2860 | 2855 |
2861 // Notify the observers that root directory has been initialized. | 2856 // Notify the observers that root directory has been initialized. |
2862 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2857 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
2863 OnInitialLoadFinished()); | 2858 OnInitialLoadFinished()); |
2864 } | 2859 } |
2865 | 2860 |
2866 GDataFileError GDataFileSystem::AddNewDirectory( | 2861 GDataFileError GDataFileSystem::AddNewDirectory( |
2867 const FilePath& directory_path, base::Value* entry_value) { | 2862 const FilePath& directory_path, base::Value* entry_value) { |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3456 return; | 3451 return; |
3457 } | 3452 } |
3458 | 3453 |
3459 PlatformFileInfoProto entry_file_info; | 3454 PlatformFileInfoProto entry_file_info; |
3460 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3455 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3461 *entry_proto->mutable_file_info() = entry_file_info; | 3456 *entry_proto->mutable_file_info() = entry_file_info; |
3462 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3457 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
3463 } | 3458 } |
3464 | 3459 |
3465 } // namespace gdata | 3460 } // namespace gdata |
OLD | NEW |