diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-05 06:26:22 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-05 06:26:22 +0000 |
commit | eb556b07f02df21fd250c2573db0402b67098369 (patch) | |
tree | d7ed39094ea2a6a8be035990f6805cf80a4c552e | |
parent | 92b89da4d9adcefa099318bd06f67d5be4b7f730 (diff) | |
download | chromium_src-eb556b07f02df21fd250c2573db0402b67098369.zip chromium_src-eb556b07f02df21fd250c2573db0402b67098369.tar.gz chromium_src-eb556b07f02df21fd250c2573db0402b67098369.tar.bz2 |
Merge 130750 - Wired preference that hides hosted documents for the directory view.
BUG=chromium-os:28907
TEST=open file maneger, flip hosted documents option back and forth
Review URL: https://chromiumcodereview.appspot.com/9947002
TBR=zelidrag@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10008001
git-svn-id: svn://svn.chromium.org/chrome/branches/1084/src@130845 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 83 insertions, 1 deletions
diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.cc b/chrome/browser/chromeos/gdata/gdata_file_system.cc index 966ee06..7311810 100644 --- a/chrome/browser/chromeos/gdata/gdata_file_system.cc +++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc @@ -27,10 +27,14 @@ #include "chrome/browser/chromeos/gdata/gdata_sync_client.h" #include "chrome/browser/chromeos/gdata/gdata_system_service.h" #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" +#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_constants.h" +#include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_paths_internal.h" +#include "chrome/common/pref_names.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/notification_details.h" #include "net/base/mime_util.h" #include "webkit/fileapi/file_system_file_util_proxy.h" #include "webkit/fileapi/file_system_types.h" @@ -515,6 +519,7 @@ GDataFileSystem::GDataFileSystem(Profile* profile, true /* manual reset */, false /* initially not signaled */)), cache_initialization_started_(false), num_pending_tasks_(0), + hide_hosted_docs_(false), ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST( new base::WeakPtrFactory<GDataFileSystem>(this))), ui_weak_ptr_(ui_weak_ptr_factory_->GetWeakPtr()) { @@ -541,6 +546,11 @@ void GDataFileSystem::Initialize() { root_.reset(new GDataRootDirectory(this)); root_->set_file_name(kGDataRootDirectory); + + PrefService* pref_service = profile_->GetPrefs(); + hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); + + InitializePreferenceObserver(); } GDataFileSystem::~GDataFileSystem() { @@ -2844,6 +2854,40 @@ void GDataFileSystem::AddUploadedFile(const FilePath& virtual_dir_path, CacheOperationCallback()); } +void GDataFileSystem::Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + if (type == chrome::NOTIFICATION_PREF_CHANGED) { + PrefService* pref_service = profile_->GetPrefs(); + std::string* pref_name = content::Details<std::string>(details).ptr(); + if (*pref_name == prefs::kDisableGDataHostedFiles) { + SetHideHostedDocuments( + pref_service->GetBoolean(prefs::kDisableGDataHostedFiles)); + } + } else { + NOTREACHED(); + } +} + +bool GDataFileSystem::hide_hosted_documents() { + base::AutoLock lock(lock_); + return hide_hosted_docs_; +} + +void GDataFileSystem::SetHideHostedDocuments(bool hide) { + FilePath root_path; + { + base::AutoLock lock(lock_); + if (hide == hide_hosted_docs_) + return; + + hide_hosted_docs_ = hide; + root_path = root_->GetFilePath(); + } + + // Kick of directory refresh when this setting changes. + NotifyDirectoryChanged(root_path); +} //===================== GDataFileSystem: Cache entry points ==================== @@ -3931,4 +3975,9 @@ void GDataFileSystem::PostBlockingPoolSequencedTaskAndReply( DCHECK(posted); } +void GDataFileSystem::InitializePreferenceObserver() { + pref_registrar_.Init(profile_->GetPrefs()); + pref_registrar_.Add(prefs::kDisableGDataHostedFiles, this); +} + } // namespace gdata diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.h b/chrome/browser/chromeos/gdata/gdata_file_system.h index 77d440a..4d5bbd3 100644 --- a/chrome/browser/chromeos/gdata/gdata_file_system.h +++ b/chrome/browser/chromeos/gdata/gdata_file_system.h @@ -24,8 +24,10 @@ #include "chrome/browser/chromeos/gdata/gdata_params.h" #include "chrome/browser/chromeos/gdata/gdata_parser.h" #include "chrome/browser/chromeos/gdata/gdata_uploader.h" +#include "chrome/browser/prefs/pref_change_registrar.h" #include "chrome/browser/profiles/profile_keyed_service.h" #include "chrome/browser/profiles/profile_keyed_service_factory.h" +#include "content/public/browser/notification_observer.h" namespace base { class WaitableEvent; @@ -395,10 +397,14 @@ class GDataFileSystemInterface { DocumentEntry* entry, const FilePath& file_content_path, FileOperationType cache_operation) = 0; + + // Returns true if hosted documents should be hidden. + virtual bool hide_hosted_documents() = 0; }; // The production implementation of GDataFileSystemInterface. -class GDataFileSystem : public GDataFileSystemInterface { +class GDataFileSystem : public GDataFileSystemInterface, + public content::NotificationObserver { public: GDataFileSystem(Profile* profile, DocumentsServiceInterface* documents_service); @@ -475,6 +481,12 @@ class GDataFileSystem : public GDataFileSystemInterface { DocumentEntry* entry, const FilePath& file_content_path, FileOperationType cache_operation) OVERRIDE; + virtual bool hide_hosted_documents() OVERRIDE; + + // content::NotificationObserver implementation. + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; private: friend class GDataUploader; @@ -1258,6 +1270,12 @@ class GDataFileSystem : public GDataFileSystemInterface { const std::string& resource_id, const std::string& md5); + // Changes state of hosted documents visibility, triggers directory refresh. + void SetHideHostedDocuments(bool hide); + + // Initializes preference change observer. + void InitializePreferenceObserver(); + scoped_ptr<GDataRootDirectory> root_; // This guards regular states. @@ -1286,6 +1304,11 @@ class GDataFileSystem : public GDataFileSystemInterface { int num_pending_tasks_; base::Lock num_pending_tasks_lock_; + // True if hosted documents should be hidden. + bool hide_hosted_docs_; + + PrefChangeRegistrar pref_registrar_; + // WeakPtrFactory and WeakPtr bound to the UI thread. scoped_ptr<base::WeakPtrFactory<GDataFileSystem> > ui_weak_ptr_factory_; base::WeakPtr<GDataFileSystem> ui_weak_ptr_; diff --git a/chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc b/chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc index 7300f2e..0533d91 100644 --- a/chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc +++ b/chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc @@ -158,6 +158,7 @@ void GDataFileSystemProxy::ReadDirectory(const GURL& file_url, file_path, base::Bind(&GDataFileSystemProxy::OnReadDirectory, this, + file_system_->hide_hosted_documents(), proxy, callback)); } @@ -248,6 +249,7 @@ void GDataFileSystemProxy::OnGetMetadata( } void GDataFileSystemProxy::OnReadDirectory( + bool hide_hosted_documents, scoped_refptr<base::MessageLoopProxy> proxy, const FileSystemOperationInterface::ReadDirectoryCallback& callback, base::PlatformFileError error, @@ -271,6 +273,12 @@ void GDataFileSystemProxy::OnReadDirectory( for (GDataFileCollection::const_iterator iter = directory->children().begin(); iter != directory->children().end(); ++iter) { + if (hide_hosted_documents) { + GDataFile* file = iter->second->AsGDataFile(); + if (file && file->is_hosted_document()) + continue; + } + entries.push_back(GDataFileToFileUtilProxyEntry(*(iter->second))); } diff --git a/chrome/browser/chromeos/gdata/gdata_file_system_proxy.h b/chrome/browser/chromeos/gdata/gdata_file_system_proxy.h index 18ef780..913aa1a 100644 --- a/chrome/browser/chromeos/gdata/gdata_file_system_proxy.h +++ b/chrome/browser/chromeos/gdata/gdata_file_system_proxy.h @@ -75,6 +75,7 @@ class GDataFileSystemProxy : public fileapi::RemoteFileSystemProxyInterface { // so it is safe to retrieve data from it, but this pointer is not safe to // be used outside of this method. void OnReadDirectory( + bool hide_hosted_documents, scoped_refptr<base::MessageLoopProxy> proxy, const fileapi::FileSystemOperationInterface::ReadDirectoryCallback& callback, diff --git a/chrome/browser/chromeos/gdata/mock_gdata_file_system.h b/chrome/browser/chromeos/gdata/mock_gdata_file_system.h index 69e61be..99ff272 100644 --- a/chrome/browser/chromeos/gdata/mock_gdata_file_system.h +++ b/chrome/browser/chromeos/gdata/mock_gdata_file_system.h @@ -85,6 +85,7 @@ class MockGDataFileSystem : public GDataFileSystemInterface { DocumentEntry* entry, const FilePath& file_content_path, FileOperationType cache_operation)); + MOCK_METHOD0(hide_hosted_documents, bool()); }; } // namespace gdata |