diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-24 03:15:41 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-24 03:15:41 +0000 |
commit | 4317e01a956051fee5c4ffc8ebf61b7729ef2b1a (patch) | |
tree | 3bcf7e295ce577d9f936f24c928530562a0bf37d /chrome/browser/prefs | |
parent | 8a947a3224b4c3fefee6babec16de2d09ef5a8c7 (diff) | |
download | chromium_src-4317e01a956051fee5c4ffc8ebf61b7729ef2b1a.zip chromium_src-4317e01a956051fee5c4ffc8ebf61b7729ef2b1a.tar.gz chromium_src-4317e01a956051fee5c4ffc8ebf61b7729ef2b1a.tar.bz2 |
Splits shelf alignment and auto-hide behavior into two values, one
synced and one not synced. On first login to a machine the local value
is initialized to the synced value. Changes made on the local machine
set both places. This gives the effect that new machines get an
initial value from the last set value, but changes made don't effect
any existing machines the user is using.
BUG=139256
TEST=see bug
R=bauerb@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11233049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163758 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/prefs')
-rw-r--r-- | chrome/browser/prefs/pref_model_associator.cc | 2 | ||||
-rw-r--r-- | chrome/browser/prefs/pref_model_associator.h | 3 | ||||
-rw-r--r-- | chrome/browser/prefs/pref_service.cc | 18 | ||||
-rw-r--r-- | chrome/browser/prefs/pref_service.h | 16 | ||||
-rw-r--r-- | chrome/browser/prefs/pref_service_observer.h | 17 |
5 files changed, 56 insertions, 0 deletions
diff --git a/chrome/browser/prefs/pref_model_associator.cc b/chrome/browser/prefs/pref_model_associator.cc index 27fec3b..623fbcf 100644 --- a/chrome/browser/prefs/pref_model_associator.cc +++ b/chrome/browser/prefs/pref_model_associator.cc @@ -164,6 +164,7 @@ syncer::SyncError PrefModelAssociator::MergeDataAndStartSyncing( } models_associated_ = true; + pref_service_->HasSyncedChanged(); return syncer::SyncError(); } @@ -172,6 +173,7 @@ void PrefModelAssociator::StopSyncing(syncer::ModelType type) { models_associated_ = false; sync_processor_.reset(); sync_error_factory_.reset(); + pref_service_->HasSyncedChanged(); } Value* PrefModelAssociator::MergePreference( diff --git a/chrome/browser/prefs/pref_model_associator.h b/chrome/browser/prefs/pref_model_associator.h index a9eebac..a5cfbdd 100644 --- a/chrome/browser/prefs/pref_model_associator.h +++ b/chrome/browser/prefs/pref_model_associator.h @@ -34,6 +34,9 @@ class PrefModelAssociator PrefModelAssociator(); virtual ~PrefModelAssociator(); + // See description above field for details. + bool models_associated() const { return models_associated_; } + // syncer::SyncableService implementation. virtual syncer::SyncDataList GetAllSyncData( syncer::ModelType type) const OVERRIDE; diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc index 043be89..cca8041 100644 --- a/chrome/browser/prefs/pref_service.cc +++ b/chrome/browser/prefs/pref_service.cc @@ -27,6 +27,7 @@ #include "chrome/browser/prefs/command_line_pref_store.h" #include "chrome/browser/prefs/pref_model_associator.h" #include "chrome/browser/prefs/pref_notifier_impl.h" +#include "chrome/browser/prefs/pref_service_observer.h" #include "chrome/browser/prefs/pref_value_store.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/prefs/prefs_tab_helper.h" @@ -256,6 +257,23 @@ void PrefService::CommitPendingWrite() { user_pref_store_->CommitPendingWrite(); } +void PrefService::AddObserver(PrefServiceObserver* observer) { + observer_list_.AddObserver(observer); +} + +void PrefService::RemoveObserver(PrefServiceObserver* observer) { + observer_list_.RemoveObserver(observer); +} + +bool PrefService::HasSynced() { + return pref_sync_associator_.get() && + pref_sync_associator_->models_associated(); +} + +void PrefService::HasSyncedChanged() { + FOR_EACH_OBSERVER(PrefServiceObserver, observer_list_, OnHasSyncedChanged()); +} + namespace { // If there's no g_browser_process or no local state, return true (for testing). diff --git a/chrome/browser/prefs/pref_service.h b/chrome/browser/prefs/pref_service.h index 6451a54..94dc0f0 100644 --- a/chrome/browser/prefs/pref_service.h +++ b/chrome/browser/prefs/pref_service.h @@ -17,6 +17,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/hash_tables.h" +#include "base/observer_list.h" #include "base/prefs/public/pref_service_base.h" #include "base/threading/non_thread_safe.h" @@ -26,6 +27,7 @@ class PersistentPrefStore; class PrefModelAssociator; class PrefNotifier; class PrefNotifierImpl; +class PrefServiceObserver; class PrefStore; class PrefValueStore; @@ -128,6 +130,18 @@ class PrefService : public PrefServiceBase, public base::NonThreadSafe { // immediately (basically, during shutdown). void CommitPendingWrite(); + void AddObserver(PrefServiceObserver* observer); + void RemoveObserver(PrefServiceObserver* observer); + + // Returns true if preferences state has synchronized with the remote + // preferences. If true is returned it can be assumed the local preferences + // has applied changes from the remote preferences. The two may not be + // identical if a change is in flight (from either side). + bool HasSynced(); + + // Invoked internally when the HasSynced() state changes. + void HasSyncedChanged(); + // PrefServiceBase implementation. virtual bool IsManagedPreference(const char* pref_name) const OVERRIDE; virtual bool IsUserModifiablePreference(const char* pref_name) const OVERRIDE; @@ -341,6 +355,8 @@ class PrefService : public PrefServiceBase, public base::NonThreadSafe { // "forked" PrefService. bool pref_service_forked_; + ObserverList<PrefServiceObserver> observer_list_; + DISALLOW_COPY_AND_ASSIGN(PrefService); }; diff --git a/chrome/browser/prefs/pref_service_observer.h b/chrome/browser/prefs/pref_service_observer.h new file mode 100644 index 0000000..5e8e098 --- /dev/null +++ b/chrome/browser/prefs/pref_service_observer.h @@ -0,0 +1,17 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_PREFS_PREF_SERVICE_OBSERVER_H_ +#define CHROME_BROWSER_PREFS_PREF_SERVICE_OBSERVER_H_ + +class PrefServiceObserver { + public: + // Invoked when PrefService::HasSycned() changes. + virtual void OnHasSyncedChanged() = 0; + + protected: + virtual ~PrefServiceObserver() {} +}; + +#endif // CHROME_BROWSER_PREFS_PREF_SERVICE_OBSERVER_H_ |