OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/policy/recommendation_restorer.h" | 5 #include "chrome/browser/chromeos/policy/recommendation_restorer.h" |
6 | 6 |
7 #include "ash/shell.h" | |
8 #include "base/bind.h" | 7 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
10 #include "base/location.h" | 9 #include "base/location.h" |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
13 #include "base/time/time.h" | 12 #include "base/time/time.h" |
14 #include "base/values.h" | 13 #include "base/values.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 if (!pref) { | 99 if (!pref) { |
101 NOTREACHED(); | 100 NOTREACHED(); |
102 return; | 101 return; |
103 } | 102 } |
104 | 103 |
105 if (!pref->GetRecommendedValue() || !pref->HasUserSetting()) | 104 if (!pref->GetRecommendedValue() || !pref->HasUserSetting()) |
106 return; | 105 return; |
107 | 106 |
108 if (logged_in_) { | 107 if (logged_in_) { |
109 allow_delay = false; | 108 allow_delay = false; |
110 } else if (allow_delay && ash::Shell::HasInstance()) { | 109 } else if (allow_delay) { |
111 // Skip the delay if there has been no user input since the browser started. | 110 // Skip the delay if there has been no user input since the browser started. |
112 const wm::UserActivityDetector* user_activity_detector = | 111 const wm::UserActivityDetector* user_activity_detector = |
113 ash::Shell::GetInstance()->user_activity_detector(); | 112 wm::UserActivityDetector::Get(); |
114 allow_delay = !user_activity_detector->last_activity_time().is_null(); | 113 if (user_activity_detector && |
| 114 user_activity_detector->last_activity_time().is_null()) { |
| 115 allow_delay = false; |
| 116 } |
115 } | 117 } |
116 | 118 |
117 if (allow_delay) | 119 if (allow_delay) |
118 StartTimer(); | 120 StartTimer(); |
119 else | 121 else |
120 pref_change_registrar_.prefs()->ClearPref(pref->name().c_str()); | 122 pref_change_registrar_.prefs()->ClearPref(pref->name().c_str()); |
121 } | 123 } |
122 | 124 |
123 void RecommendationRestorer::RestoreAll() { | 125 void RecommendationRestorer::RestoreAll() { |
124 Restore(false, prefs::kAccessibilityLargeCursorEnabled); | 126 Restore(false, prefs::kAccessibilityLargeCursorEnabled); |
125 Restore(false, prefs::kAccessibilitySpokenFeedbackEnabled); | 127 Restore(false, prefs::kAccessibilitySpokenFeedbackEnabled); |
126 Restore(false, prefs::kAccessibilityHighContrastEnabled); | 128 Restore(false, prefs::kAccessibilityHighContrastEnabled); |
127 Restore(false, prefs::kAccessibilityScreenMagnifierEnabled); | 129 Restore(false, prefs::kAccessibilityScreenMagnifierEnabled); |
128 Restore(false, prefs::kAccessibilityScreenMagnifierType); | 130 Restore(false, prefs::kAccessibilityScreenMagnifierType); |
129 Restore(false, prefs::kAccessibilityVirtualKeyboardEnabled); | 131 Restore(false, prefs::kAccessibilityVirtualKeyboardEnabled); |
130 } | 132 } |
131 | 133 |
132 void RecommendationRestorer::StartTimer() { | 134 void RecommendationRestorer::StartTimer() { |
133 // Listen for user activity so that the timer can be reset while the user is | 135 // Listen for user activity so that the timer can be reset while the user is |
134 // active, causing it to fire only when the user remains idle for | 136 // active, causing it to fire only when the user remains idle for |
135 // |kRestoreDelayInMs|. | 137 // |kRestoreDelayInMs|. |
136 if (ash::Shell::HasInstance()) { | 138 wm::UserActivityDetector* user_activity_detector = |
137 wm::UserActivityDetector* user_activity_detector = | 139 wm::UserActivityDetector::Get(); |
138 ash::Shell::GetInstance()->user_activity_detector(); | 140 if (user_activity_detector && !user_activity_detector->HasObserver(this)) |
139 if (!user_activity_detector->HasObserver(this)) | 141 user_activity_detector->AddObserver(this); |
140 user_activity_detector->AddObserver(this); | |
141 } | |
142 | 142 |
143 // There should be a separate timer for each pref. However, in the common | 143 // There should be a separate timer for each pref. However, in the common |
144 // case of the user changing settings, a single timer is sufficient. This is | 144 // case of the user changing settings, a single timer is sufficient. This is |
145 // because a change initiated by the user implies user activity, so that even | 145 // because a change initiated by the user implies user activity, so that even |
146 // if there was a separate timer per pref, they would all be reset at that | 146 // if there was a separate timer per pref, they would all be reset at that |
147 // point, causing them to fire at exactly the same time. In the much rarer | 147 // point, causing them to fire at exactly the same time. In the much rarer |
148 // case of a recommended value changing, a single timer is a close | 148 // case of a recommended value changing, a single timer is a close |
149 // approximation of the behavior that would be obtained by resetting the timer | 149 // approximation of the behavior that would be obtained by resetting the timer |
150 // for the affected pref only. | 150 // for the affected pref only. |
151 restore_timer_.Start(FROM_HERE, | 151 restore_timer_.Start(FROM_HERE, |
152 base::TimeDelta::FromMilliseconds(kRestoreDelayInMs), | 152 base::TimeDelta::FromMilliseconds(kRestoreDelayInMs), |
153 base::Bind(&RecommendationRestorer::RestoreAll, | 153 base::Bind(&RecommendationRestorer::RestoreAll, |
154 base::Unretained(this))); | 154 base::Unretained(this))); |
155 } | 155 } |
156 | 156 |
157 void RecommendationRestorer::StopTimer() { | 157 void RecommendationRestorer::StopTimer() { |
158 restore_timer_.Stop(); | 158 restore_timer_.Stop(); |
159 if (ash::Shell::HasInstance()) | 159 if (wm::UserActivityDetector::Get()) |
160 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); | 160 wm::UserActivityDetector::Get()->RemoveObserver(this); |
161 } | 161 } |
162 | 162 |
163 } // namespace policy | 163 } // namespace policy |
OLD | NEW |