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

Side by Side Diff: chrome/browser/chromeos/session_length_limiter.cc

Issue 693643004: Make UserActivityDetector a singleton (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@athena_do_not_use_ash45
Patch Set: Created 6 years, 1 month 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 (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 "ash/shell.h"
10 #include "base/bind.h" 9 #include "base/bind.h"
11 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
12 #include "base/location.h" 11 #include "base/location.h"
13 #include "base/logging.h" 12 #include "base/logging.h"
14 #include "base/prefs/pref_registry_simple.h" 13 #include "base/prefs/pref_registry_simple.h"
15 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
16 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/lifetime/application_lifetime.h" 16 #include "chrome/browser/lifetime/application_lifetime.h"
18 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
19 #include "ui/events/event.h" 18 #include "ui/events/event.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // 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
92 // 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
93 // 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
94 // 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
95 // boolean indicating user activity. 94 // boolean indicating user activity.
96 if (!browser_restarted || !RestoreStateAfterCrash()) { 95 if (!browser_restarted || !RestoreStateAfterCrash()) {
97 local_state->ClearPref(prefs::kSessionUserActivitySeen); 96 local_state->ClearPref(prefs::kSessionUserActivitySeen);
98 UpdateSessionStartTime(); 97 UpdateSessionStartTime();
99 } 98 }
100 99
101 if (!user_activity_seen_ && ash::Shell::HasInstance()) 100 if (!user_activity_seen_ && wm::UserActivityDetector::Get())
102 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); 101 wm::UserActivityDetector::Get()->AddObserver(this);
103 } 102 }
104 103
105 SessionLengthLimiter::~SessionLengthLimiter() { 104 SessionLengthLimiter::~SessionLengthLimiter() {
106 if (!user_activity_seen_ && ash::Shell::HasInstance()) 105 if (!user_activity_seen_ && wm::UserActivityDetector::Get())
107 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); 106 wm::UserActivityDetector::Get()->RemoveObserver(this);
108 } 107 }
109 108
110 void SessionLengthLimiter::OnUserActivity(const ui::Event* event) { 109 void SessionLengthLimiter::OnUserActivity(const ui::Event* event) {
111 if (user_activity_seen_) 110 if (user_activity_seen_)
112 return; 111 return;
113 if (ash::Shell::HasInstance()) 112 if (wm::UserActivityDetector::Get())
114 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); 113 wm::UserActivityDetector::Get()->RemoveObserver(this);
115 user_activity_seen_ = true; 114 user_activity_seen_ = true;
116 115
117 PrefService* local_state = g_browser_process->local_state(); 116 PrefService* local_state = g_browser_process->local_state();
118 local_state->SetBoolean(prefs::kSessionUserActivitySeen, true); 117 local_state->SetBoolean(prefs::kSessionUserActivitySeen, true);
119 if (session_start_time_.is_null()) { 118 if (session_start_time_.is_null()) {
120 // 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
121 // 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
122 // and persist it in local state. 121 // and persist it in local state.
123 session_start_time_ = delegate_->GetCurrentTime(); 122 session_start_time_ = delegate_->GetCurrentTime();
124 local_state->SetInt64(prefs::kSessionStartTime, 123 local_state->SetInt64(prefs::kSessionStartTime,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 return; 203 return;
205 } 204 }
206 205
207 // 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.
208 timer_.reset(new base::OneShotTimer<SessionLengthLimiter::Delegate>); 207 timer_.reset(new base::OneShotTimer<SessionLengthLimiter::Delegate>);
209 timer_->Start(FROM_HERE, remaining, delegate_.get(), 208 timer_->Start(FROM_HERE, remaining, delegate_.get(),
210 &SessionLengthLimiter::Delegate::StopSession); 209 &SessionLengthLimiter::Delegate::StopSession);
211 } 210 }
212 211
213 } // namespace chromeos 212 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/recommendation_restorer.cc ('k') | chrome/browser/chromeos/system/automatic_reboot_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698