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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10693109: Use Drive v2 API: enable behind --enable-drive-api flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 5 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/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 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 const base::SequencedWorkerPool::SequenceToken& sequence_token) 666 const base::SequencedWorkerPool::SequenceToken& sequence_token)
667 : profile_(profile), 667 : profile_(profile),
668 cache_(cache), 668 cache_(cache),
669 uploader_(uploader), 669 uploader_(uploader),
670 documents_service_(documents_service), 670 documents_service_(documents_service),
671 webapps_registry_(webapps_registry), 671 webapps_registry_(webapps_registry),
672 update_timer_(true /* retain_user_task */, true /* is_repeating */), 672 update_timer_(true /* retain_user_task */, true /* is_repeating */),
673 hide_hosted_docs_(false), 673 hide_hosted_docs_(false),
674 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 674 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
675 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()), 675 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()),
676 sequence_token_(sequence_token) { 676 sequence_token_(sequence_token),
677 use_drive_api_(false) {
677 // Should be created from the file browser extension API on UI thread. 678 // Should be created from the file browser extension API on UI thread.
678 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
679 } 680 }
680 681
681 void GDataFileSystem::Initialize() { 682 void GDataFileSystem::Initialize(bool use_drive_api) {
682 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
683 684
684 documents_service_->Initialize(profile_); 685 use_drive_api_ = use_drive_api;
686
687 documents_service_->Initialize(profile_, use_drive_api_);
685 688
686 root_.reset(new GDataRootDirectory); 689 root_.reset(new GDataRootDirectory);
687 690
688 PrefService* pref_service = profile_->GetPrefs(); 691 PrefService* pref_service = profile_->GetPrefs();
689 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); 692 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles);
690 693
691 InitializePreferenceObserver(); 694 InitializePreferenceObserver();
692 } 695 }
693 696
694 void GDataFileSystem::CheckForUpdates() { 697 void GDataFileSystem::CheckForUpdates() {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 std::string() /* no search query */, 884 std::string() /* no search query */,
882 std::string() /* no directory resource ID */, 885 std::string() /* no directory resource ID */,
883 callback, 886 callback,
884 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded, 887 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded,
885 ui_weak_ptr_)); 888 ui_weak_ptr_));
886 return; 889 return;
887 } 890 }
888 891
889 scoped_ptr<AccountMetadataFeed> account_metadata; 892 scoped_ptr<AccountMetadataFeed> account_metadata;
890 if (feed_data.get()) { 893 if (feed_data.get()) {
891 account_metadata = AccountMetadataFeed::CreateFrom(*feed_data); 894 account_metadata = AccountMetadataFeed::CreateFrom(*feed_data,
895 use_drive_api_);
892 #ifndef NDEBUG 896 #ifndef NDEBUG
893 // Save account metadata feed for analysis. 897 // Save account metadata feed for analysis.
894 const FilePath path = 898 const FilePath path =
895 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append( 899 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append(
896 kAccountMetadataFile); 900 kAccountMetadataFile);
897 PostBlockingPoolSequencedTask( 901 PostBlockingPoolSequencedTask(
898 FROM_HERE, 902 FROM_HERE,
899 sequence_token_, 903 sequence_token_,
900 base::Bind(&SaveFeedOnBlockingPoolForDebugging, 904 base::Bind(&SaveFeedOnBlockingPoolForDebugging,
901 path, base::Passed(&feed_data))); 905 path, base::Passed(&feed_data)));
902 #endif 906 #endif
903 } 907 }
904 908
905 if (!account_metadata.get()) { 909 if (!account_metadata.get()) {
906 LoadFeedFromServer(initial_origin, 910 LoadFeedFromServer(initial_origin,
907 local_changestamp + 1, 0, 911 local_changestamp + 1, 0,
908 true, /* should_fetch_multiple_feeds */ 912 true, /* should_fetch_multiple_feeds */
909 search_file_path, 913 search_file_path,
910 std::string() /* no search query */, 914 std::string() /* no search query */,
911 std::string() /* no directory resource ID */, 915 std::string() /* no directory resource ID */,
912 callback, 916 callback,
913 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded, 917 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded,
914 ui_weak_ptr_)); 918 ui_weak_ptr_));
915 return; 919 return;
916 } 920 }
917 921
918 webapps_registry_->UpdateFromFeed(account_metadata.get()); 922 if (!use_drive_api_)
923 webapps_registry_->UpdateFromFeed(account_metadata.get());
919 924
920 bool changes_detected = true; 925 bool changes_detected = true;
921 if (local_changestamp >= account_metadata->largest_changestamp()) { 926 if (local_changestamp >= account_metadata->largest_changestamp()) {
922 if (local_changestamp > account_metadata->largest_changestamp()) { 927 if (local_changestamp > account_metadata->largest_changestamp()) {
923 LOG(WARNING) << "Cached client feed is fresher than server, client = " 928 LOG(WARNING) << "Cached client feed is fresher than server, client = "
924 << local_changestamp 929 << local_changestamp
925 << ", server = " 930 << ", server = "
926 << account_metadata->largest_changestamp(); 931 << account_metadata->largest_changestamp();
927 } 932 }
928 root_->set_origin(initial_origin); 933 root_->set_origin(initial_origin);
(...skipping 1497 matching lines...) Expand 10 before | Expand all | Expand 10 after
2426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2431 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2427 2432
2428 base::PlatformFileError error = GDataToPlatformError(status); 2433 base::PlatformFileError error = GDataToPlatformError(status);
2429 if (error != base::PLATFORM_FILE_OK) { 2434 if (error != base::PLATFORM_FILE_OK) {
2430 callback.Run(error, -1, -1); 2435 callback.Run(error, -1, -1);
2431 return; 2436 return;
2432 } 2437 }
2433 2438
2434 scoped_ptr<AccountMetadataFeed> feed; 2439 scoped_ptr<AccountMetadataFeed> feed;
2435 if (data.get()) 2440 if (data.get())
2436 feed = AccountMetadataFeed::CreateFrom(*data); 2441 feed = AccountMetadataFeed::CreateFrom(*data, use_drive_api_);
2437 if (!feed.get()) { 2442 if (!feed.get()) {
2438 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, -1, -1); 2443 callback.Run(base::PLATFORM_FILE_ERROR_FAILED, -1, -1);
2439 return; 2444 return;
2440 } 2445 }
2441 2446
2442 callback.Run(base::PLATFORM_FILE_OK, 2447 callback.Run(base::PLATFORM_FILE_OK,
2443 feed->quota_bytes_total(), 2448 feed->quota_bytes_total(),
2444 feed->quota_bytes_used()); 2449 feed->quota_bytes_used());
2445 } 2450 }
2446 2451
(...skipping 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after
3921 // must go through here. Removes the |file_path| from the remembered set so 3926 // must go through here. Removes the |file_path| from the remembered set so
3922 // that subsequent operations can open the file again. 3927 // that subsequent operations can open the file again.
3923 open_files_.erase(file_path); 3928 open_files_.erase(file_path);
3924 3929
3925 // Then invokes the user-supplied callback function. 3930 // Then invokes the user-supplied callback function.
3926 if (!callback.is_null()) 3931 if (!callback.is_null())
3927 callback.Run(result); 3932 callback.Run(result);
3928 } 3933 }
3929 3934
3930 } // namespace gdata 3935 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698