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

Side by Side Diff: chrome/browser/chromeos/policy/recommendation_restorer.cc

Issue 833893003: Move UserActivityDetector to ui/base/user_activity/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: don't build test on android Created 5 years, 11 months 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
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/chromeos/profiles/profile_helper.h" 15 #include "chrome/browser/chromeos/profiles/profile_helper.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
21 #include "ui/wm/core/user_activity_detector.h" 21 #include "ui/base/user_activity/user_activity_detector.h"
22 22
23 namespace policy { 23 namespace policy {
24 24
25 namespace { 25 namespace {
26 // The amount of idle time after which recommended values are restored. 26 // The amount of idle time after which recommended values are restored.
27 const int kRestoreDelayInMs = 60 * 1000; // 1 minute. 27 const int kRestoreDelayInMs = 60 * 1000; // 1 minute.
28 } // namespace 28 } // namespace
29 29
30 RecommendationRestorer::RecommendationRestorer(Profile* profile) 30 RecommendationRestorer::RecommendationRestorer(Profile* profile)
31 : logged_in_(false) { 31 : logged_in_(false) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return; 101 return;
102 } 102 }
103 103
104 if (!pref->GetRecommendedValue() || !pref->HasUserSetting()) 104 if (!pref->GetRecommendedValue() || !pref->HasUserSetting())
105 return; 105 return;
106 106
107 if (logged_in_) { 107 if (logged_in_) {
108 allow_delay = false; 108 allow_delay = false;
109 } else if (allow_delay) { 109 } else if (allow_delay) {
110 // 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.
111 const wm::UserActivityDetector* user_activity_detector = 111 const ui::UserActivityDetector* user_activity_detector =
112 wm::UserActivityDetector::Get(); 112 ui::UserActivityDetector::Get();
113 if (user_activity_detector && 113 if (user_activity_detector &&
114 user_activity_detector->last_activity_time().is_null()) { 114 user_activity_detector->last_activity_time().is_null()) {
115 allow_delay = false; 115 allow_delay = false;
116 } 116 }
117 } 117 }
118 118
119 if (allow_delay) 119 if (allow_delay)
120 StartTimer(); 120 StartTimer();
121 else 121 else
122 pref_change_registrar_.prefs()->ClearPref(pref->name().c_str()); 122 pref_change_registrar_.prefs()->ClearPref(pref->name().c_str());
123 } 123 }
124 124
125 void RecommendationRestorer::RestoreAll() { 125 void RecommendationRestorer::RestoreAll() {
126 Restore(false, prefs::kAccessibilityLargeCursorEnabled); 126 Restore(false, prefs::kAccessibilityLargeCursorEnabled);
127 Restore(false, prefs::kAccessibilitySpokenFeedbackEnabled); 127 Restore(false, prefs::kAccessibilitySpokenFeedbackEnabled);
128 Restore(false, prefs::kAccessibilityHighContrastEnabled); 128 Restore(false, prefs::kAccessibilityHighContrastEnabled);
129 Restore(false, prefs::kAccessibilityScreenMagnifierEnabled); 129 Restore(false, prefs::kAccessibilityScreenMagnifierEnabled);
130 Restore(false, prefs::kAccessibilityScreenMagnifierType); 130 Restore(false, prefs::kAccessibilityScreenMagnifierType);
131 Restore(false, prefs::kAccessibilityVirtualKeyboardEnabled); 131 Restore(false, prefs::kAccessibilityVirtualKeyboardEnabled);
132 } 132 }
133 133
134 void RecommendationRestorer::StartTimer() { 134 void RecommendationRestorer::StartTimer() {
135 // 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
136 // 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
137 // |kRestoreDelayInMs|. 137 // |kRestoreDelayInMs|.
138 wm::UserActivityDetector* user_activity_detector = 138 ui::UserActivityDetector* user_activity_detector =
139 wm::UserActivityDetector::Get(); 139 ui::UserActivityDetector::Get();
140 if (user_activity_detector && !user_activity_detector->HasObserver(this)) 140 if (user_activity_detector && !user_activity_detector->HasObserver(this))
141 user_activity_detector->AddObserver(this); 141 user_activity_detector->AddObserver(this);
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 (wm::UserActivityDetector::Get()) 159 if (ui::UserActivityDetector::Get())
160 wm::UserActivityDetector::Get()->RemoveObserver(this); 160 ui::UserActivityDetector::Get()->RemoveObserver(this);
161 } 161 }
162 162
163 } // namespace policy 163 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/recommendation_restorer.h ('k') | chrome/browser/chromeos/session_length_limiter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698