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

Side by Side Diff: chrome/browser/chromeos/system/automatic_reboot_manager.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
« no previous file with comments | « chrome/browser/chromeos/session_length_limiter.cc ('k') | chrome/browser/idle_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/system/automatic_reboot_manager.h" 5 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <string> 12 #include <string>
13 13
14 #include "ash/shell.h"
15 #include "base/bind.h" 14 #include "base/bind.h"
16 #include "base/bind_helpers.h" 15 #include "base/bind_helpers.h"
17 #include "base/callback.h" 16 #include "base/callback.h"
18 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
19 #include "base/files/file_util.h" 18 #include "base/files/file_util.h"
20 #include "base/files/scoped_file.h" 19 #include "base/files/scoped_file.h"
21 #include "base/location.h" 20 #include "base/location.h"
22 #include "base/logging.h" 21 #include "base/logging.h"
23 #include "base/memory/ref_counted.h" 22 #include "base/memory/ref_counted.h"
24 #include "base/path_service.h" 23 #include "base/path_service.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 content::NotificationService::AllSources()); 164 content::NotificationService::AllSources());
166 165
167 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); 166 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get();
168 dbus_thread_manager->GetPowerManagerClient()->AddObserver(this); 167 dbus_thread_manager->GetPowerManagerClient()->AddObserver(this);
169 dbus_thread_manager->GetUpdateEngineClient()->AddObserver(this); 168 dbus_thread_manager->GetUpdateEngineClient()->AddObserver(this);
170 169
171 // If no user is logged in, a reboot may be performed whenever the user is 170 // If no user is logged in, a reboot may be performed whenever the user is
172 // idle. Start listening for user activity to determine whether the user is 171 // idle. Start listening for user activity to determine whether the user is
173 // idle or not. 172 // idle or not.
174 if (!user_manager::UserManager::Get()->IsUserLoggedIn()) { 173 if (!user_manager::UserManager::Get()->IsUserLoggedIn()) {
175 if (ash::Shell::HasInstance()) 174 if (wm::UserActivityDetector::Get())
176 ash::Shell::GetInstance()->user_activity_detector()->AddObserver(this); 175 wm::UserActivityDetector::Get()->AddObserver(this);
177 notification_registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, 176 notification_registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED,
178 content::NotificationService::AllSources()); 177 content::NotificationService::AllSources());
179 login_screen_idle_timer_.reset( 178 login_screen_idle_timer_.reset(
180 new base::OneShotTimer<AutomaticRebootManager>); 179 new base::OneShotTimer<AutomaticRebootManager>);
181 OnUserActivity(NULL); 180 OnUserActivity(NULL);
182 } 181 }
183 182
184 // In a regular browser, base::ThreadTaskRunnerHandle::Get() and 183 // In a regular browser, base::ThreadTaskRunnerHandle::Get() and
185 // base::MessageLoopProxy::current() return pointers to the same object. 184 // base::MessageLoopProxy::current() return pointers to the same object.
186 // In unit tests, using base::ThreadTaskRunnerHandle::Get() has the advantage 185 // In unit tests, using base::ThreadTaskRunnerHandle::Get() has the advantage
187 // that it allows a custom base::SingleThreadTaskRunner to be injected. 186 // that it allows a custom base::SingleThreadTaskRunner to be injected.
188 content::BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior( 187 content::BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior(
189 FROM_HERE, 188 FROM_HERE,
190 base::Bind(&GetSystemEventTimes, 189 base::Bind(&GetSystemEventTimes,
191 base::ThreadTaskRunnerHandle::Get(), 190 base::ThreadTaskRunnerHandle::Get(),
192 base::Bind(&AutomaticRebootManager::Init, 191 base::Bind(&AutomaticRebootManager::Init,
193 weak_ptr_factory_.GetWeakPtr())), 192 weak_ptr_factory_.GetWeakPtr())),
194 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 193 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
195 } 194 }
196 195
197 AutomaticRebootManager::~AutomaticRebootManager() { 196 AutomaticRebootManager::~AutomaticRebootManager() {
198 FOR_EACH_OBSERVER(AutomaticRebootManagerObserver, 197 FOR_EACH_OBSERVER(AutomaticRebootManagerObserver,
199 observers_, 198 observers_,
200 WillDestroyAutomaticRebootManager()); 199 WillDestroyAutomaticRebootManager());
201 200
202 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get(); 201 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get();
203 dbus_thread_manager->GetPowerManagerClient()->RemoveObserver(this); 202 dbus_thread_manager->GetPowerManagerClient()->RemoveObserver(this);
204 dbus_thread_manager->GetUpdateEngineClient()->RemoveObserver(this); 203 dbus_thread_manager->GetUpdateEngineClient()->RemoveObserver(this);
205 if (ash::Shell::HasInstance()) 204 if (wm::UserActivityDetector::Get())
206 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); 205 wm::UserActivityDetector::Get()->RemoveObserver(this);
207 } 206 }
208 207
209 void AutomaticRebootManager::AddObserver( 208 void AutomaticRebootManager::AddObserver(
210 AutomaticRebootManagerObserver* observer) { 209 AutomaticRebootManagerObserver* observer) {
211 observers_.AddObserver(observer); 210 observers_.AddObserver(observer);
212 } 211 }
213 212
214 void AutomaticRebootManager::RemoveObserver( 213 void AutomaticRebootManager::RemoveObserver(
215 AutomaticRebootManagerObserver* observer) { 214 AutomaticRebootManagerObserver* observer) {
216 observers_.RemoveObserver(observer); 215 observers_.RemoveObserver(observer);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 const content::NotificationDetails& details) { 262 const content::NotificationDetails& details) {
264 if (type == chrome::NOTIFICATION_APP_TERMINATING) { 263 if (type == chrome::NOTIFICATION_APP_TERMINATING) {
265 if (user_manager::UserManager::Get()->IsUserLoggedIn()) { 264 if (user_manager::UserManager::Get()->IsUserLoggedIn()) {
266 // The browser is terminating during a session, either because the session 265 // The browser is terminating during a session, either because the session
267 // is ending or because the browser is being restarted. 266 // is ending or because the browser is being restarted.
268 MaybeReboot(true); 267 MaybeReboot(true);
269 } 268 }
270 } else if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) { 269 } else if (type == chrome::NOTIFICATION_LOGIN_USER_CHANGED) {
271 // A session is starting. Stop listening for user activity as it no longer 270 // A session is starting. Stop listening for user activity as it no longer
272 // is a relevant criterion. 271 // is a relevant criterion.
273 if (ash::Shell::HasInstance()) 272 if (wm::UserActivityDetector::Get())
274 ash::Shell::GetInstance()->user_activity_detector()->RemoveObserver(this); 273 wm::UserActivityDetector::Get()->RemoveObserver(this);
275 notification_registrar_.Remove( 274 notification_registrar_.Remove(
276 this, chrome::NOTIFICATION_LOGIN_USER_CHANGED, 275 this, chrome::NOTIFICATION_LOGIN_USER_CHANGED,
277 content::NotificationService::AllSources()); 276 content::NotificationService::AllSources());
278 login_screen_idle_timer_.reset(); 277 login_screen_idle_timer_.reset();
279 } else { 278 } else {
280 NOTREACHED(); 279 NOTREACHED();
281 } 280 }
282 } 281 }
283 282
284 // static 283 // static
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 409 }
411 410
412 login_screen_idle_timer_.reset(); 411 login_screen_idle_timer_.reset();
413 grace_start_timer_.reset(); 412 grace_start_timer_.reset();
414 grace_end_timer_.reset(); 413 grace_end_timer_.reset();
415 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); 414 DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
416 } 415 }
417 416
418 } // namespace system 417 } // namespace system
419 } // namespace chromeos 418 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/session_length_limiter.cc ('k') | chrome/browser/idle_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698