| 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/ui/gesture_prefs_observer_factory_aura.h" | 5 #include "chrome/browser/ui/gesture_prefs_observer_factory_aura.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/prefs/public/pref_change_registrar.h" | 8 #include "base/prefs/public/pref_change_registrar.h" |
| 9 #include "base/prefs/public/pref_observer.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/profiles/profile_dependency_manager.h" | 12 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 14 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
| 15 #include "ui/base/gestures/gesture_configuration.h" | 16 #include "ui/base/gestures/gesture_configuration.h" |
| 16 | 17 |
| 17 using ui::GestureConfiguration; | 18 using ui::GestureConfiguration; |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // This class manages gesture configuration preferences. | 22 // This class manages gesture configuration preferences. |
| 22 class GesturePrefsObserver : public content::NotificationObserver, | 23 class GesturePrefsObserver : public PrefObserver, |
| 23 public ProfileKeyedService { | 24 public ProfileKeyedService { |
| 24 public: | 25 public: |
| 25 explicit GesturePrefsObserver(PrefService* prefs); | 26 explicit GesturePrefsObserver(PrefService* prefs); |
| 26 virtual ~GesturePrefsObserver(); | 27 virtual ~GesturePrefsObserver(); |
| 27 | 28 |
| 28 // ProfileKeyedService implementation. | 29 // ProfileKeyedService implementation. |
| 29 virtual void Shutdown() OVERRIDE; | 30 virtual void Shutdown() OVERRIDE; |
| 30 | 31 |
| 31 // content::NotificationObserver implementation. | 32 // PrefObserver implementation. |
| 32 virtual void Observe(int type, | 33 virtual void OnPreferenceChanged(PrefServiceBase* service, |
| 33 const content::NotificationSource& source, | 34 const std::string& pref_name) OVERRIDE; |
| 34 const content::NotificationDetails& details) OVERRIDE; | |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 void Update(); | 37 void Update(); |
| 38 | 38 |
| 39 PrefChangeRegistrar registrar_; | 39 PrefChangeRegistrar registrar_; |
| 40 PrefService* prefs_; | 40 PrefService* prefs_; |
| 41 | 41 |
| 42 DISALLOW_COPY_AND_ASSIGN(GesturePrefsObserver); | 42 DISALLOW_COPY_AND_ASSIGN(GesturePrefsObserver); |
| 43 }; | 43 }; |
| 44 | 44 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 74 for (size_t i = 0; i < arraysize(kPrefsToObserve); ++i) | 74 for (size_t i = 0; i < arraysize(kPrefsToObserve); ++i) |
| 75 registrar_.Add(kPrefsToObserve[i], this); | 75 registrar_.Add(kPrefsToObserve[i], this); |
| 76 } | 76 } |
| 77 | 77 |
| 78 GesturePrefsObserver::~GesturePrefsObserver() {} | 78 GesturePrefsObserver::~GesturePrefsObserver() {} |
| 79 | 79 |
| 80 void GesturePrefsObserver::Shutdown() { | 80 void GesturePrefsObserver::Shutdown() { |
| 81 registrar_.RemoveAll(); | 81 registrar_.RemoveAll(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void GesturePrefsObserver::Observe( | 84 void GesturePrefsObserver::OnPreferenceChanged(PrefServiceBase* service, |
| 85 int type, | 85 const std::string& pref_name) { |
| 86 const content::NotificationSource& source, | |
| 87 const content::NotificationDetails& details) { | |
| 88 Update(); | 86 Update(); |
| 89 } | 87 } |
| 90 | 88 |
| 91 void GesturePrefsObserver::Update() { | 89 void GesturePrefsObserver::Update() { |
| 92 GestureConfiguration::set_long_press_time_in_seconds( | 90 GestureConfiguration::set_long_press_time_in_seconds( |
| 93 prefs_->GetDouble( | 91 prefs_->GetDouble( |
| 94 prefs::kLongPressTimeInSeconds)); | 92 prefs::kLongPressTimeInSeconds)); |
| 95 GestureConfiguration::set_semi_long_press_time_in_seconds( | 93 GestureConfiguration::set_semi_long_press_time_in_seconds( |
| 96 prefs_->GetDouble( | 94 prefs_->GetDouble( |
| 97 prefs::kSemiLongPressTimeInSeconds)); | 95 prefs::kSemiLongPressTimeInSeconds)); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 // Use same gesture preferences on incognito windows. | 260 // Use same gesture preferences on incognito windows. |
| 263 return true; | 261 return true; |
| 264 } | 262 } |
| 265 | 263 |
| 266 bool GesturePrefsObserverFactoryAura::ServiceIsNULLWhileTesting() const { | 264 bool GesturePrefsObserverFactoryAura::ServiceIsNULLWhileTesting() const { |
| 267 // Some tests replace the PrefService of the TestingProfile after the | 265 // Some tests replace the PrefService of the TestingProfile after the |
| 268 // GesturePrefsObserver has been created, which makes Shutdown() | 266 // GesturePrefsObserver has been created, which makes Shutdown() |
| 269 // remove the registrar from a non-existent PrefService. | 267 // remove the registrar from a non-existent PrefService. |
| 270 return true; | 268 return true; |
| 271 } | 269 } |
| OLD | NEW |