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

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

Issue 306032: Simplify threading in browser thread by making only ChromeThread deal with di... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: a few more simplifications Created 11 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/cros_power_library.h" 5 #include "chrome/browser/chromeos/cros_power_library.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/chrome_thread.h" 9 #include "chrome/browser/chrome_thread.h"
10 #include "chrome/browser/chromeos/cros_library.h" 10 #include "chrome/browser/chromeos/cros_library.h"
11 11
12 // Allows InvokeLater without adding refcounting. This class is a Singleton and 12 // Allows InvokeLater without adding refcounting. This class is a Singleton and
13 // won't be deleted until it's last InvokeLater is run. 13 // won't be deleted until it's last InvokeLater is run.
14 template <> 14 template <>
15 struct RunnableMethodTraits<CrosPowerLibrary> { 15 struct RunnableMethodTraits<CrosPowerLibrary> {
16 void RetainCallee(CrosPowerLibrary* obj) {} 16 void RetainCallee(CrosPowerLibrary* obj) {}
17 void ReleaseCallee(CrosPowerLibrary* obj) {} 17 void ReleaseCallee(CrosPowerLibrary* obj) {}
18 }; 18 };
19 19
20 CrosPowerLibrary::CrosPowerLibrary() : status_(chromeos::PowerStatus()) { 20 CrosPowerLibrary::CrosPowerLibrary() : status_(chromeos::PowerStatus()) {
21 if (CrosLibrary::loaded()) { 21 if (!CrosLibrary::loaded())
22 MessageLoop* loop = ChromeThread::GetMessageLoop(ChromeThread::FILE); 22 return;
23 if (loop) 23
24 loop->PostTask(FROM_HERE, NewRunnableMethod(this, 24 ChromeThread::PostTask(
25 &CrosPowerLibrary::InitOnBackgroundThread)); 25 ChromeThread::FILE, FROM_HERE,
26 } 26 NewRunnableMethod(this, &CrosPowerLibrary::InitOnBackgroundThread));
27 } 27 }
28 28
29 CrosPowerLibrary::~CrosPowerLibrary() { 29 CrosPowerLibrary::~CrosPowerLibrary() {
30 if (CrosLibrary::loaded()) { 30 if (CrosLibrary::loaded()) {
31 // FILE thread is already gone by the time we get to this destructor. 31 // FILE thread is already gone by the time we get to this destructor.
32 // So it's ok to just make the disconnect call on the main thread. 32 // So it's ok to just make the disconnect call on the main thread.
33 chromeos::DisconnectPowerStatus(power_status_connection_); 33 chromeos::DisconnectPowerStatus(power_status_connection_);
34 } 34 }
35 } 35 }
36 36
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 84 }
85 85
86 void CrosPowerLibrary::InitOnBackgroundThread() { 86 void CrosPowerLibrary::InitOnBackgroundThread() {
87 power_status_connection_ = chromeos::MonitorPowerStatus( 87 power_status_connection_ = chromeos::MonitorPowerStatus(
88 &PowerStatusChangedHandler, this); 88 &PowerStatusChangedHandler, this);
89 } 89 }
90 90
91 void CrosPowerLibrary::UpdatePowerStatus(const chromeos::PowerStatus& status) { 91 void CrosPowerLibrary::UpdatePowerStatus(const chromeos::PowerStatus& status) {
92 // Make sure we run on UI thread. 92 // Make sure we run on UI thread.
93 if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) { 93 if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
94 MessageLoop* loop = ChromeThread::GetMessageLoop(ChromeThread::UI); 94 ChromeThread::PostTask(
95 if (loop) 95 ChromeThread::UI, FROM_HERE,
96 loop->PostTask(FROM_HERE, NewRunnableMethod(this, 96 NewRunnableMethod(this, &CrosPowerLibrary::UpdatePowerStatus, status));
97 &CrosPowerLibrary::UpdatePowerStatus, status));
98 return; 97 return;
99 } 98 }
100 99
101 DLOG(INFO) << "Power" << 100 DLOG(INFO) << "Power" <<
102 " lpo=" << status.line_power_on << 101 " lpo=" << status.line_power_on <<
103 " sta=" << status.battery_state << 102 " sta=" << status.battery_state <<
104 " per=" << status.battery_percentage << 103 " per=" << status.battery_percentage <<
105 " tte=" << status.battery_time_to_empty << 104 " tte=" << status.battery_time_to_empty <<
106 " ttf=" << status.battery_time_to_full; 105 " ttf=" << status.battery_time_to_full;
107 status_ = status; 106 status_ = status;
108 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(this)); 107 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(this));
109 } 108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698