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/chromeos/session_length_limiter.h" | 5 #include "chrome/browser/chromeos/session_length_limiter.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/lifetime/application_lifetime.h" | 16 #include "chrome/browser/lifetime/application_lifetime.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "ui/base/user_activity/user_activity_detector.h" |
18 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
19 #include "ui/wm/core/user_activity_detector.h" | |
20 | 20 |
21 namespace chromeos { | 21 namespace chromeos { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // The minimum session time limit that can be set. | 25 // The minimum session time limit that can be set. |
26 const int kSessionLengthLimitMinMs = 30 * 1000; // 30 seconds. | 26 const int kSessionLengthLimitMinMs = 30 * 1000; // 30 seconds. |
27 | 27 |
28 // The maximum session time limit that can be set. | 28 // The maximum session time limit that can be set. |
29 const int kSessionLengthLimitMaxMs = 24 * 60 * 60 * 1000; // 24 hours. | 29 const int kSessionLengthLimitMaxMs = 24 * 60 * 60 * 1000; // 24 hours. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // If this is a browser restart after a crash, try to restore the session | 90 // If this is a browser restart after a crash, try to restore the session |
91 // start time and the boolean indicating user activity from local state. If | 91 // start time and the boolean indicating user activity from local state. If |
92 // this is not a browser restart after a crash or the attempt to restore | 92 // this is not a browser restart after a crash or the attempt to restore |
93 // fails, set the session start time to the current time and clear the | 93 // fails, set the session start time to the current time and clear the |
94 // boolean indicating user activity. | 94 // boolean indicating user activity. |
95 if (!browser_restarted || !RestoreStateAfterCrash()) { | 95 if (!browser_restarted || !RestoreStateAfterCrash()) { |
96 local_state->ClearPref(prefs::kSessionUserActivitySeen); | 96 local_state->ClearPref(prefs::kSessionUserActivitySeen); |
97 UpdateSessionStartTime(); | 97 UpdateSessionStartTime(); |
98 } | 98 } |
99 | 99 |
100 if (!user_activity_seen_ && wm::UserActivityDetector::Get()) | 100 if (!user_activity_seen_ && ui::UserActivityDetector::Get()) |
101 wm::UserActivityDetector::Get()->AddObserver(this); | 101 ui::UserActivityDetector::Get()->AddObserver(this); |
102 } | 102 } |
103 | 103 |
104 SessionLengthLimiter::~SessionLengthLimiter() { | 104 SessionLengthLimiter::~SessionLengthLimiter() { |
105 if (!user_activity_seen_ && wm::UserActivityDetector::Get()) | 105 if (!user_activity_seen_ && ui::UserActivityDetector::Get()) |
106 wm::UserActivityDetector::Get()->RemoveObserver(this); | 106 ui::UserActivityDetector::Get()->RemoveObserver(this); |
107 } | 107 } |
108 | 108 |
109 void SessionLengthLimiter::OnUserActivity(const ui::Event* event) { | 109 void SessionLengthLimiter::OnUserActivity(const ui::Event* event) { |
110 if (user_activity_seen_) | 110 if (user_activity_seen_) |
111 return; | 111 return; |
112 if (wm::UserActivityDetector::Get()) | 112 if (ui::UserActivityDetector::Get()) |
113 wm::UserActivityDetector::Get()->RemoveObserver(this); | 113 ui::UserActivityDetector::Get()->RemoveObserver(this); |
114 user_activity_seen_ = true; | 114 user_activity_seen_ = true; |
115 | 115 |
116 PrefService* local_state = g_browser_process->local_state(); | 116 PrefService* local_state = g_browser_process->local_state(); |
117 local_state->SetBoolean(prefs::kSessionUserActivitySeen, true); | 117 local_state->SetBoolean(prefs::kSessionUserActivitySeen, true); |
118 if (session_start_time_.is_null()) { | 118 if (session_start_time_.is_null()) { |
119 // If instructed to wait for initial user activity and this is the first | 119 // If instructed to wait for initial user activity and this is the first |
120 // activity in the session, set the session start time to the current time | 120 // activity in the session, set the session start time to the current time |
121 // and persist it in local state. | 121 // and persist it in local state. |
122 session_start_time_ = delegate_->GetCurrentTime(); | 122 session_start_time_ = delegate_->GetCurrentTime(); |
123 local_state->SetInt64(prefs::kSessionStartTime, | 123 local_state->SetInt64(prefs::kSessionStartTime, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 return; | 203 return; |
204 } | 204 } |
205 | 205 |
206 // Set a timer to log out the user when the session length limit is reached. | 206 // Set a timer to log out the user when the session length limit is reached. |
207 timer_.reset(new base::OneShotTimer<SessionLengthLimiter::Delegate>); | 207 timer_.reset(new base::OneShotTimer<SessionLengthLimiter::Delegate>); |
208 timer_->Start(FROM_HERE, remaining, delegate_.get(), | 208 timer_->Start(FROM_HERE, remaining, delegate_.get(), |
209 &SessionLengthLimiter::Delegate::StopSession); | 209 &SessionLengthLimiter::Delegate::StopSession); |
210 } | 210 } |
211 | 211 |
212 } // namespace chromeos | 212 } // namespace chromeos |
OLD | NEW |