| 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" | 7 #include "ash/shell.h" |
| 8 #include "ash/wm/user_activity_detector.h" | |
| 9 #include "base/bind.h" | 8 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 11 #include "base/location.h" | 10 #include "base/location.h" |
| 12 #include "base/logging.h" | 11 #include "base/logging.h" |
| 13 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 14 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 15 #include "base/values.h" | 14 #include "base/values.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 20 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
| 21 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 22 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
| 22 #include "ui/wm/core/user_activity_detector.h" |
| 23 | 23 |
| 24 namespace policy { | 24 namespace policy { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 // The amount of idle time after which recommended values are restored. | 27 // The amount of idle time after which recommended values are restored. |
| 28 const int kRestoreDelayInMs = 60 * 1000; // 1 minute. | 28 const int kRestoreDelayInMs = 60 * 1000; // 1 minute. |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 RecommendationRestorer::RecommendationRestorer(Profile* profile) | 31 RecommendationRestorer::RecommendationRestorer(Profile* profile) |
| 32 : logged_in_(false) { | 32 : logged_in_(false) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 | 98 |
| 99 if (!pref->GetRecommendedValue() || !pref->HasUserSetting()) | 99 if (!pref->GetRecommendedValue() || !pref->HasUserSetting()) |
| 100 return; | 100 return; |
| 101 | 101 |
| 102 if (logged_in_) { | 102 if (logged_in_) { |
| 103 allow_delay = false; | 103 allow_delay = false; |
| 104 } else if (allow_delay && ash::Shell::HasInstance()) { | 104 } else if (allow_delay && ash::Shell::HasInstance()) { |
| 105 // Skip the delay if there has been no user input since the browser started. | 105 // Skip the delay if there has been no user input since the browser started. |
| 106 const ash::UserActivityDetector* user_activity_detector = | 106 const wm::UserActivityDetector* user_activity_detector = |
| 107 ash::Shell::GetInstance()->user_activity_detector(); | 107 ash::Shell::GetInstance()->user_activity_detector(); |
| 108 allow_delay = !user_activity_detector->last_activity_time().is_null(); | 108 allow_delay = !user_activity_detector->last_activity_time().is_null(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 if (allow_delay) | 111 if (allow_delay) |
| 112 StartTimer(); | 112 StartTimer(); |
| 113 else | 113 else |
| 114 pref_change_registrar_.prefs()->ClearPref(pref->name().c_str()); | 114 pref_change_registrar_.prefs()->ClearPref(pref->name().c_str()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void RecommendationRestorer::RestoreAll() { | 117 void RecommendationRestorer::RestoreAll() { |
| 118 Restore(false, prefs::kLargeCursorEnabled); | 118 Restore(false, prefs::kLargeCursorEnabled); |
| 119 Restore(false, prefs::kSpokenFeedbackEnabled); | 119 Restore(false, prefs::kSpokenFeedbackEnabled); |
| 120 Restore(false, prefs::kHighContrastEnabled); | 120 Restore(false, prefs::kHighContrastEnabled); |
| 121 Restore(false, prefs::kScreenMagnifierEnabled); | 121 Restore(false, prefs::kScreenMagnifierEnabled); |
| 122 Restore(false, prefs::kScreenMagnifierType); | 122 Restore(false, prefs::kScreenMagnifierType); |
| 123 Restore(false, prefs::kVirtualKeyboardEnabled); | 123 Restore(false, prefs::kVirtualKeyboardEnabled); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void RecommendationRestorer::StartTimer() { | 126 void RecommendationRestorer::StartTimer() { |
| 127 // Listen for user activity so that the timer can be reset while the user is | 127 // Listen for user activity so that the timer can be reset while the user is |
| 128 // active, causing it to fire only when the user remains idle for | 128 // active, causing it to fire only when the user remains idle for |
| 129 // |kRestoreDelayInMs|. | 129 // |kRestoreDelayInMs|. |
| 130 if (ash::Shell::HasInstance()) { | 130 if (ash::Shell::HasInstance()) { |
| 131 ash::UserActivityDetector* user_activity_detector = | 131 wm::UserActivityDetector* user_activity_detector = |
| 132 ash::Shell::GetInstance()->user_activity_detector(); | 132 ash::Shell::GetInstance()->user_activity_detector(); |
| 133 if (!user_activity_detector->HasObserver(this)) | 133 if (!user_activity_detector->HasObserver(this)) |
| 134 user_activity_detector->AddObserver(this); | 134 user_activity_detector->AddObserver(this); |
| 135 } | 135 } |
| 136 | 136 |
| 137 // There should be a separate timer for each pref. However, in the common | 137 // There should be a separate timer for each pref. However, in the common |
| 138 // case of the user changing settings, a single timer is sufficient. This is | 138 // case of the user changing settings, a single timer is sufficient. This is |
| 139 // because a change initiated by the user implies user activity, so that even | 139 // because a change initiated by the user implies user activity, so that even |
| 140 // if there was a separate timer per pref, they would all be reset at that | 140 // if there was a separate timer per pref, they would all be reset at that |
| 141 // point, causing them to fire at exactly the same time. In the much rarer | 141 // point, causing them to fire at exactly the same time. In the much rarer |
| 142 // case of a recommended value changing, a single timer is a close | 142 // case of a recommended value changing, a single timer is a close |
| 143 // approximation of the behavior that would be obtained by resetting the timer | 143 // approximation of the behavior that would be obtained by resetting the timer |
| 144 // for the affected pref only. | 144 // for the affected pref only. |
| 145 restore_timer_.Start(FROM_HERE, | 145 restore_timer_.Start(FROM_HERE, |
| 146 base::TimeDelta::FromMilliseconds(kRestoreDelayInMs), | 146 base::TimeDelta::FromMilliseconds(kRestoreDelayInMs), |
| 147 base::Bind(&RecommendationRestorer::RestoreAll, | 147 base::Bind(&RecommendationRestorer::RestoreAll, |
| 148 base::Unretained(this))); | 148 base::Unretained(this))); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void RecommendationRestorer::StopTimer() { | 151 void RecommendationRestorer::StopTimer() { |
| 152 restore_timer_.Stop(); | 152 restore_timer_.Stop(); |
| 153 if (ash::Shell::HasInstance()) | 153 if (ash::Shell::HasInstance()) |
| 154 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); | 154 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); |
| 155 } | 155 } |
| 156 | 156 |
| 157 } // namespace policy | 157 } // namespace policy |
| OLD | NEW |