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

Side by Side Diff: chrome/browser/ui/gesture_prefs_observer_factory_aura.cc

Issue 11316163: Remove the last usages of PrefObserver outside of Prefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 8 years 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/ui/gesture_prefs_observer_factory_aura.h" 5 #include "chrome/browser/ui/gesture_prefs_observer_factory_aura.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
7 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
8 #include "base/prefs/public/pref_change_registrar.h" 10 #include "base/prefs/public/pref_change_registrar.h"
9 #include "base/prefs/public/pref_observer.h"
10 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_dependency_manager.h" 13 #include "chrome/browser/profiles/profile_dependency_manager.h"
13 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
14 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
15 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/overscroll_configuration.h" 17 #include "content/public/browser/overscroll_configuration.h"
17 #include "ui/base/gestures/gesture_configuration.h" 18 #include "ui/base/gestures/gesture_configuration.h"
18 19
19 using ui::GestureConfiguration; 20 using ui::GestureConfiguration;
20 21
21 namespace { 22 namespace {
22 23
23 struct OverscrollPref { 24 struct OverscrollPref {
24 const char* pref_name; 25 const char* pref_name;
25 content::OverscrollConfig config; 26 content::OverscrollConfig config;
26 }; 27 };
27 28
28 // This class manages gesture configuration preferences. 29 // This class manages gesture configuration preferences.
29 class GesturePrefsObserver : public PrefObserver, 30 class GesturePrefsObserver : public ProfileKeyedService {
30 public ProfileKeyedService {
31 public: 31 public:
32 explicit GesturePrefsObserver(PrefService* prefs); 32 explicit GesturePrefsObserver(PrefService* prefs);
33 virtual ~GesturePrefsObserver(); 33 virtual ~GesturePrefsObserver();
34 34
35 static const OverscrollPref* GetOverscrollPrefs() { 35 static const OverscrollPref* GetOverscrollPrefs() {
36 using namespace content; 36 using namespace content;
37 static OverscrollPref overscroll_prefs[] = { 37 static OverscrollPref overscroll_prefs[] = {
38 { prefs::kOverscrollHorizontalThresholdComplete, 38 { prefs::kOverscrollHorizontalThresholdComplete,
39 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE }, 39 OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE },
40 { prefs::kOverscrollVerticalThresholdComplete, 40 { prefs::kOverscrollVerticalThresholdComplete,
41 OVERSCROLL_CONFIG_VERT_THRESHOLD_COMPLETE }, 41 OVERSCROLL_CONFIG_VERT_THRESHOLD_COMPLETE },
42 { prefs::kOverscrollMinimumThresholdStart, 42 { prefs::kOverscrollMinimumThresholdStart,
43 OVERSCROLL_CONFIG_MIN_THRESHOLD_START }, 43 OVERSCROLL_CONFIG_MIN_THRESHOLD_START },
44 { prefs::kOverscrollHorizontalResistThreshold, 44 { prefs::kOverscrollHorizontalResistThreshold,
45 OVERSCROLL_CONFIG_HORIZ_RESIST_AFTER }, 45 OVERSCROLL_CONFIG_HORIZ_RESIST_AFTER },
46 { prefs::kOverscrollVerticalResistThreshold, 46 { prefs::kOverscrollVerticalResistThreshold,
47 OVERSCROLL_CONFIG_VERT_RESIST_AFTER }, 47 OVERSCROLL_CONFIG_VERT_RESIST_AFTER },
48 { NULL, 48 { NULL,
49 OVERSCROLL_CONFIG_NONE }, 49 OVERSCROLL_CONFIG_NONE },
50 }; 50 };
51 51
52 return overscroll_prefs; 52 return overscroll_prefs;
53 } 53 }
54 54
55 // ProfileKeyedService implementation. 55 // ProfileKeyedService implementation.
56 virtual void Shutdown() OVERRIDE; 56 virtual void Shutdown() OVERRIDE;
57 57
58 // PrefObserver implementation.
59 virtual void OnPreferenceChanged(PrefServiceBase* service,
60 const std::string& pref_name) OVERRIDE;
61
62 private: 58 private:
63 void Update(); 59 void Update();
64 60
65 void UpdateOverscrollPrefs(); 61 void UpdateOverscrollPrefs();
66 62
67 PrefChangeRegistrar registrar_; 63 PrefChangeRegistrar registrar_;
68 PrefService* prefs_; 64 PrefService* prefs_;
69 65
70 DISALLOW_COPY_AND_ASSIGN(GesturePrefsObserver); 66 DISALLOW_COPY_AND_ASSIGN(GesturePrefsObserver);
71 }; 67 };
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 prefs::kOverscrollVerticalThresholdComplete, 99 prefs::kOverscrollVerticalThresholdComplete,
104 prefs::kOverscrollMinimumThresholdStart, 100 prefs::kOverscrollMinimumThresholdStart,
105 prefs::kOverscrollHorizontalResistThreshold, 101 prefs::kOverscrollHorizontalResistThreshold,
106 prefs::kOverscrollVerticalResistThreshold, 102 prefs::kOverscrollVerticalResistThreshold,
107 }; 103 };
108 104
109 GesturePrefsObserver::GesturePrefsObserver(PrefService* prefs) 105 GesturePrefsObserver::GesturePrefsObserver(PrefService* prefs)
110 : prefs_(prefs) { 106 : prefs_(prefs) {
111 registrar_.Init(prefs); 107 registrar_.Init(prefs);
112 registrar_.RemoveAll(); 108 registrar_.RemoveAll();
109 base::Closure callback = base::Bind(&GesturePrefsObserver::Update,
110 base::Unretained(this));
113 for (size_t i = 0; i < arraysize(kPrefsToObserve); ++i) 111 for (size_t i = 0; i < arraysize(kPrefsToObserve); ++i)
114 registrar_.Add(kPrefsToObserve[i], this); 112 registrar_.Add(kPrefsToObserve[i], callback);
115 for (size_t i = 0; i < arraysize(kOverscrollPrefs); ++i) 113 for (size_t i = 0; i < arraysize(kOverscrollPrefs); ++i)
116 registrar_.Add(kOverscrollPrefs[i], this); 114 registrar_.Add(kOverscrollPrefs[i], callback);
117 } 115 }
118 116
119 GesturePrefsObserver::~GesturePrefsObserver() {} 117 GesturePrefsObserver::~GesturePrefsObserver() {}
120 118
121 void GesturePrefsObserver::Shutdown() { 119 void GesturePrefsObserver::Shutdown() {
122 registrar_.RemoveAll(); 120 registrar_.RemoveAll();
123 } 121 }
124 122
125 void GesturePrefsObserver::OnPreferenceChanged(PrefServiceBase* service,
126 const std::string& pref_name) {
127 Update();
128 }
129
130 void GesturePrefsObserver::Update() { 123 void GesturePrefsObserver::Update() {
131 GestureConfiguration::set_fling_acceleration_curve_coefficients(0, 124 GestureConfiguration::set_fling_acceleration_curve_coefficients(0,
132 prefs_->GetDouble(prefs::kFlingAccelerationCurveCoefficient0)); 125 prefs_->GetDouble(prefs::kFlingAccelerationCurveCoefficient0));
133 GestureConfiguration::set_fling_acceleration_curve_coefficients(1, 126 GestureConfiguration::set_fling_acceleration_curve_coefficients(1,
134 prefs_->GetDouble(prefs::kFlingAccelerationCurveCoefficient1)); 127 prefs_->GetDouble(prefs::kFlingAccelerationCurveCoefficient1));
135 GestureConfiguration::set_fling_acceleration_curve_coefficients(2, 128 GestureConfiguration::set_fling_acceleration_curve_coefficients(2,
136 prefs_->GetDouble(prefs::kFlingAccelerationCurveCoefficient2)); 129 prefs_->GetDouble(prefs::kFlingAccelerationCurveCoefficient2));
137 GestureConfiguration::set_fling_acceleration_curve_coefficients(3, 130 GestureConfiguration::set_fling_acceleration_curve_coefficients(3,
138 prefs_->GetDouble(prefs::kFlingAccelerationCurveCoefficient3)); 131 prefs_->GetDouble(prefs::kFlingAccelerationCurveCoefficient3));
139 GestureConfiguration::set_long_press_time_in_seconds( 132 GestureConfiguration::set_long_press_time_in_seconds(
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 // Use same gesture preferences on incognito windows. 345 // Use same gesture preferences on incognito windows.
353 return true; 346 return true;
354 } 347 }
355 348
356 bool GesturePrefsObserverFactoryAura::ServiceIsNULLWhileTesting() const { 349 bool GesturePrefsObserverFactoryAura::ServiceIsNULLWhileTesting() const {
357 // Some tests replace the PrefService of the TestingProfile after the 350 // Some tests replace the PrefService of the TestingProfile after the
358 // GesturePrefsObserver has been created, which makes Shutdown() 351 // GesturePrefsObserver has been created, which makes Shutdown()
359 // remove the registrar from a non-existent PrefService. 352 // remove the registrar from a non-existent PrefService.
360 return true; 353 return true;
361 } 354 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698