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

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

Issue 10830211: Revert 150436 - gdata: Remove hide_hosted_documents from ReadDirectoryCallback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 DocumentsServiceInterface* documents_service, 509 DocumentsServiceInterface* documents_service,
510 GDataUploaderInterface* uploader, 510 GDataUploaderInterface* uploader,
511 DriveWebAppsRegistryInterface* webapps_registry, 511 DriveWebAppsRegistryInterface* webapps_registry,
512 base::SequencedTaskRunner* blocking_task_runner) 512 base::SequencedTaskRunner* blocking_task_runner)
513 : profile_(profile), 513 : profile_(profile),
514 cache_(cache), 514 cache_(cache),
515 uploader_(uploader), 515 uploader_(uploader),
516 documents_service_(documents_service), 516 documents_service_(documents_service),
517 webapps_registry_(webapps_registry), 517 webapps_registry_(webapps_registry),
518 update_timer_(true /* retain_user_task */, true /* is_repeating */), 518 update_timer_(true /* retain_user_task */, true /* is_repeating */),
519 hide_hosted_docs_(false),
519 blocking_task_runner_(blocking_task_runner), 520 blocking_task_runner_(blocking_task_runner),
520 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 521 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
521 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()) { 522 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()) {
522 // Should be created from the file browser extension API on UI thread. 523 // Should be created from the file browser extension API on UI thread.
523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
524 } 525 }
525 526
526 void GDataFileSystem::Initialize() { 527 void GDataFileSystem::Initialize() {
527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
528 529
529 documents_service_->Initialize(profile_); 530 documents_service_->Initialize(profile_);
530 531
531 directory_service_.reset(new GDataDirectoryService); 532 directory_service_.reset(new GDataDirectoryService);
532 feed_loader_.reset(new GDataWapiFeedLoader(directory_service_.get(), 533 feed_loader_.reset(new GDataWapiFeedLoader(directory_service_.get(),
533 documents_service_, 534 documents_service_,
534 webapps_registry_, 535 webapps_registry_,
535 cache_, 536 cache_,
536 blocking_task_runner_)); 537 blocking_task_runner_));
537 feed_loader_->AddObserver(this); 538 feed_loader_->AddObserver(this);
538 539
540 PrefService* pref_service = profile_->GetPrefs();
541 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles);
542
539 InitializePreferenceObserver(); 543 InitializePreferenceObserver();
540 } 544 }
541 545
542 void GDataFileSystem::CheckForUpdates() { 546 void GDataFileSystem::CheckForUpdates() {
543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 547 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
544 ContentOrigin initial_origin = directory_service_->origin(); 548 ContentOrigin initial_origin = directory_service_->origin();
545 if (initial_origin == FROM_SERVER) { 549 if (initial_origin == FROM_SERVER) {
546 directory_service_->set_origin(REFRESHING); 550 directory_service_->set_origin(REFRESHING);
547 feed_loader_->ReloadFromServerIfNeeded( 551 feed_loader_->ReloadFromServerIfNeeded(
548 initial_origin, 552 initial_origin,
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 } 1859 }
1856 1860
1857 void GDataFileSystem::OnReadDirectory(const ReadDirectoryCallback& callback, 1861 void GDataFileSystem::OnReadDirectory(const ReadDirectoryCallback& callback,
1858 GDataFileError error, 1862 GDataFileError error,
1859 GDataEntry* entry) { 1863 GDataEntry* entry) {
1860 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1864 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1861 1865
1862 if (error != GDATA_FILE_OK) { 1866 if (error != GDATA_FILE_OK) {
1863 if (!callback.is_null()) 1867 if (!callback.is_null())
1864 callback.Run(error, 1868 callback.Run(error,
1869 hide_hosted_docs_,
1865 scoped_ptr<GDataEntryProtoVector>()); 1870 scoped_ptr<GDataEntryProtoVector>());
1866 return; 1871 return;
1867 } 1872 }
1868 DCHECK(entry); 1873 DCHECK(entry);
1869 1874
1870 GDataDirectory* directory = entry->AsGDataDirectory(); 1875 GDataDirectory* directory = entry->AsGDataDirectory();
1871 if (!directory) { 1876 if (!directory) {
1872 if (!callback.is_null()) 1877 if (!callback.is_null())
1873 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, 1878 callback.Run(GDATA_FILE_ERROR_NOT_FOUND,
1879 hide_hosted_docs_,
1874 scoped_ptr<GDataEntryProtoVector>()); 1880 scoped_ptr<GDataEntryProtoVector>());
1875 return; 1881 return;
1876 } 1882 }
1877 1883
1878 scoped_ptr<GDataEntryProtoVector> entries(new GDataEntryProtoVector); 1884 scoped_ptr<GDataEntryProtoVector> entries(new GDataEntryProtoVector);
1879 for (GDataFileCollection::const_iterator iter = 1885 for (GDataFileCollection::const_iterator iter =
1880 directory->child_files().begin(); 1886 directory->child_files().begin();
1881 iter != directory->child_files().end(); ++iter) { 1887 iter != directory->child_files().end(); ++iter) {
1882 GDataEntryProto proto; 1888 GDataEntryProto proto;
1883 static_cast<const GDataEntry*>(iter->second)->ToProtoFull(&proto); 1889 static_cast<const GDataEntry*>(iter->second)->ToProtoFull(&proto);
1884 entries->push_back(proto); 1890 entries->push_back(proto);
1885 } 1891 }
1886 for (GDataDirectoryCollection::const_iterator iter = 1892 for (GDataDirectoryCollection::const_iterator iter =
1887 directory->child_directories().begin(); 1893 directory->child_directories().begin();
1888 iter != directory->child_directories().end(); ++iter) { 1894 iter != directory->child_directories().end(); ++iter) {
1889 GDataEntryProto proto; 1895 GDataEntryProto proto;
1890 static_cast<const GDataEntry*>(iter->second)->ToProtoFull(&proto); 1896 static_cast<const GDataEntry*>(iter->second)->ToProtoFull(&proto);
1891 entries->push_back(proto); 1897 entries->push_back(proto);
1892 } 1898 }
1893 1899
1894 if (!callback.is_null()) 1900 if (!callback.is_null())
1895 callback.Run(GDATA_FILE_OK, entries.Pass()); 1901 callback.Run(GDATA_FILE_OK, hide_hosted_docs_, entries.Pass());
1896 } 1902 }
1897 1903
1898 void GDataFileSystem::RequestDirectoryRefresh(const FilePath& file_path) { 1904 void GDataFileSystem::RequestDirectoryRefresh(const FilePath& file_path) {
1899 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1905 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1900 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1906 BrowserThread::CurrentlyOn(BrowserThread::IO));
1901 RunTaskOnUIThread( 1907 RunTaskOnUIThread(
1902 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread, 1908 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread,
1903 ui_weak_ptr_, 1909 ui_weak_ptr_,
1904 file_path)); 1910 file_path));
1905 } 1911 }
(...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after
2957 NOTREACHED() << "Unexpected upload mode: " << upload_mode; 2963 NOTREACHED() << "Unexpected upload mode: " << upload_mode;
2958 } 2964 }
2959 } 2965 }
2960 2966
2961 void GDataFileSystem::Observe(int type, 2967 void GDataFileSystem::Observe(int type,
2962 const content::NotificationSource& source, 2968 const content::NotificationSource& source,
2963 const content::NotificationDetails& details) { 2969 const content::NotificationDetails& details) {
2964 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2970 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2965 2971
2966 if (type == chrome::NOTIFICATION_PREF_CHANGED) { 2972 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
2973 PrefService* pref_service = profile_->GetPrefs();
2967 std::string* pref_name = content::Details<std::string>(details).ptr(); 2974 std::string* pref_name = content::Details<std::string>(details).ptr();
2968 if (*pref_name == prefs::kDisableGDataHostedFiles) { 2975 if (*pref_name == prefs::kDisableGDataHostedFiles) {
2969 const FilePath root_path = directory_service_->root()->GetFilePath(); 2976 SetHideHostedDocuments(
2970 // Kick off directory refresh when this setting changes. 2977 pref_service->GetBoolean(prefs::kDisableGDataHostedFiles));
2971 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
2972 OnDirectoryChanged(root_path));
2973 } 2978 }
2974 } else { 2979 } else {
2975 NOTREACHED(); 2980 NOTREACHED();
2976 } 2981 }
2977 } 2982 }
2978 2983
2984 void GDataFileSystem::SetHideHostedDocuments(bool hide) {
2985 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2986
2987 if (hide == hide_hosted_docs_)
2988 return;
2989
2990 hide_hosted_docs_ = hide;
2991 const FilePath root_path = directory_service_->root()->GetFilePath();
2992
2993 // Kick off directory refresh when this setting changes.
2994 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
2995 OnDirectoryChanged(root_path));
2996 }
2997
2979 //============= GDataFileSystem: internal helper functions ===================== 2998 //============= GDataFileSystem: internal helper functions =====================
2980 2999
2981 void GDataFileSystem::InitializePreferenceObserver() { 3000 void GDataFileSystem::InitializePreferenceObserver() {
2982 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3001 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2983 3002
2984 pref_registrar_.reset(new PrefChangeRegistrar()); 3003 pref_registrar_.reset(new PrefChangeRegistrar());
2985 pref_registrar_->Init(profile_->GetPrefs()); 3004 pref_registrar_->Init(profile_->GetPrefs());
2986 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 3005 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
2987 } 3006 }
2988 3007
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
3405 } 3424 }
3406 3425
3407 PlatformFileInfoProto entry_file_info; 3426 PlatformFileInfoProto entry_file_info;
3408 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 3427 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
3409 *entry_proto->mutable_file_info() = entry_file_info; 3428 *entry_proto->mutable_file_info() = entry_file_info;
3410 if (!callback.is_null()) 3429 if (!callback.is_null())
3411 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 3430 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3412 } 3431 }
3413 3432
3414 } // namespace gdata 3433 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698