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

Side by Side Diff: content/browser/power_save_blocker_linux.cc

Issue 10392152: RefCounted types should not have public destructors, Linux fixes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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) 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 "content/browser/power_save_blocker.h" 5 #include "content/browser/power_save_blocker.h"
6 6
7 #include <X11/Xlib.h> 7 #include <X11/Xlib.h>
8 #include <X11/extensions/dpms.h> 8 #include <X11/extensions/dpms.h>
9 // Xlib #defines Status, but we can't have that for some of our headers. 9 // Xlib #defines Status, but we can't have that for some of our headers.
10 #ifdef Status 10 #ifdef Status
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // D-Bus interface. It is responsible for obtaining specific object proxies, 64 // D-Bus interface. It is responsible for obtaining specific object proxies,
65 // making D-Bus method calls and handling D-Bus responses. 65 // making D-Bus method calls and handling D-Bus responses.
66 // 66 //
67 // When a new DBusPowerBlocker is created, only a specific implementation of 67 // When a new DBusPowerBlocker is created, only a specific implementation of
68 // the delegate is instantiated. See the DBusPowerSaveBlocker constructor for 68 // the delegate is instantiated. See the DBusPowerSaveBlocker constructor for
69 // more details. This is ref_counted to make sure that the callbacks stay 69 // more details. This is ref_counted to make sure that the callbacks stay
70 // alive even after the DBusPowerSaveBlocker object is deleted. 70 // alive even after the DBusPowerSaveBlocker object is deleted.
71 class Delegate : public base::RefCountedThreadSafe<Delegate> { 71 class Delegate : public base::RefCountedThreadSafe<Delegate> {
72 public: 72 public:
73 Delegate() {} 73 Delegate() {}
74 virtual void ApplyBlock(PowerSaveBlocker::PowerSaveBlockerType type) = 0;
75
76 protected:
74 virtual ~Delegate() {} 77 virtual ~Delegate() {}
75 virtual void ApplyBlock(PowerSaveBlocker::PowerSaveBlockerType type) = 0; 78
76 private: 79 private:
80 friend class base::RefCountedThreadSafe<Delegate>;
81
77 DISALLOW_COPY_AND_ASSIGN(Delegate); 82 DISALLOW_COPY_AND_ASSIGN(Delegate);
78 }; 83 };
79 84
80 // Returns a pointer to the sole instance of this class 85 // Returns a pointer to the sole instance of this class
81 static DBusPowerSaveBlocker* GetInstance(); 86 static DBusPowerSaveBlocker* GetInstance();
82 87
83 // Forwards a power save block request to the concrete implementation of the 88 // Forwards a power save block request to the concrete implementation of the
84 // Delegate interface. If |delegate_| is NULL, the application runs under an 89 // Delegate interface. If |delegate_| is NULL, the application runs under an
85 // unsupported desktop environment. In this case, the method does nothing. 90 // unsupported desktop environment. In this case, the method does nothing.
86 void ApplyBlock(PowerSaveBlocker::PowerSaveBlockerType type) { 91 void ApplyBlock(PowerSaveBlocker::PowerSaveBlockerType type) {
(...skipping 26 matching lines...) Expand all
113 118
114 // Delegate implementation for KDE4. It uses the 119 // Delegate implementation for KDE4. It uses the
115 // org.freedesktop.PowerManagement interface. It works on XFCE4, too. 120 // org.freedesktop.PowerManagement interface. It works on XFCE4, too.
116 class KDEPowerSaveBlocker : public DBusPowerSaveBlocker::Delegate { 121 class KDEPowerSaveBlocker : public DBusPowerSaveBlocker::Delegate {
117 public: 122 public:
118 KDEPowerSaveBlocker() 123 KDEPowerSaveBlocker()
119 : inhibit_cookie_(0), 124 : inhibit_cookie_(0),
120 pending_inhibit_call_(false), 125 pending_inhibit_call_(false),
121 postponed_uninhibit_call_(false) { 126 postponed_uninhibit_call_(false) {
122 } 127 }
123 ~KDEPowerSaveBlocker() {}
124 128
125 virtual void ApplyBlock( 129 virtual void ApplyBlock(
126 PowerSaveBlocker::PowerSaveBlockerType type) OVERRIDE { 130 PowerSaveBlocker::PowerSaveBlockerType type) OVERRIDE {
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
128 DCHECK(pending_inhibit_call_ || !postponed_uninhibit_call_); 132 DCHECK(pending_inhibit_call_ || !postponed_uninhibit_call_);
129 133
130 // If we have a pending inhibit call, we add a postponed uninhibit 134 // If we have a pending inhibit call, we add a postponed uninhibit
131 // request, such that it will be canceled as soon as the response arrives. 135 // request, such that it will be canceled as soon as the response arrives.
132 // If we have an active inhibit request and receive a new one, 136 // If we have an active inhibit request and receive a new one,
133 // we ignore it since the 'freedesktop' interface has only one Inhibit level 137 // we ignore it since the 'freedesktop' interface has only one Inhibit level
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // This is an invalid argument 192 // This is an invalid argument
189 NOTREACHED(); 193 NOTREACHED();
190 break; 194 break;
191 } 195 }
192 196
193 object_proxy->CallMethod(&method_call, 197 object_proxy->CallMethod(&method_call,
194 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 198 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
195 bus_callback); 199 bus_callback);
196 } 200 }
197 201
202 protected:
203 virtual ~KDEPowerSaveBlocker() {}
204
198 private: 205 private:
199 // Inhibit() response callback. 206 // Inhibit() response callback.
200 // Stores the cookie so we can use it later when calling UnInhibit(). 207 // Stores the cookie so we can use it later when calling UnInhibit().
201 // If the response from D-Bus is successful and there is a postponed 208 // If the response from D-Bus is successful and there is a postponed
202 // uninhibit request, we cancel the cookie that we just received. 209 // uninhibit request, we cancel the cookie that we just received.
203 void OnInhibitResponse(dbus::Response* response) { 210 void OnInhibitResponse(dbus::Response* response) {
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
205 DCHECK(pending_inhibit_call_); 212 DCHECK(pending_inhibit_call_);
206 pending_inhibit_call_ = false; 213 pending_inhibit_call_ = false;
207 if (response) { 214 if (response) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 kInhibitLogOut = 1, 258 kInhibitLogOut = 1,
252 kInhibitSwitchUser = 2, 259 kInhibitSwitchUser = 2,
253 kInhibitSuspendSession = 4, 260 kInhibitSuspendSession = 4,
254 kInhibitMarkSessionAsIdle = 8 261 kInhibitMarkSessionAsIdle = 8
255 }; 262 };
256 263
257 GnomePowerSaveBlocker() 264 GnomePowerSaveBlocker()
258 : inhibit_cookie_(0), 265 : inhibit_cookie_(0),
259 pending_inhibit_calls_(0), 266 pending_inhibit_calls_(0),
260 postponed_uninhibit_calls_(0) {} 267 postponed_uninhibit_calls_(0) {}
261 ~GnomePowerSaveBlocker() {}
262 268
263 virtual void ApplyBlock( 269 virtual void ApplyBlock(
264 PowerSaveBlocker::PowerSaveBlockerType type) OVERRIDE { 270 PowerSaveBlocker::PowerSaveBlockerType type) OVERRIDE {
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
266 DCHECK(postponed_uninhibit_calls_ <= pending_inhibit_calls_); 272 DCHECK(postponed_uninhibit_calls_ <= pending_inhibit_calls_);
267 273
268 // If we have a pending inhibit call, we add a postponed uninhibit request, 274 // If we have a pending inhibit call, we add a postponed uninhibit request,
269 // such that it will be canceled as soon as the response arrives. We want to 275 // such that it will be canceled as soon as the response arrives. We want to
270 // cancel the current inhibit request whether |type| is 276 // cancel the current inhibit request whether |type| is
271 // kPowerSaveBlockPreventNone or not. If |type| represents an inhibit 277 // kPowerSaveBlockPreventNone or not. If |type| represents an inhibit
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 // This is an invalid argument. 367 // This is an invalid argument.
362 NOTREACHED(); 368 NOTREACHED();
363 break; 369 break;
364 } 370 }
365 371
366 object_proxy->CallMethod(&method_call, 372 object_proxy->CallMethod(&method_call,
367 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 373 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
368 bus_callback); 374 bus_callback);
369 } 375 }
370 376
377 protected:
378 virtual ~GnomePowerSaveBlocker() {}
379
371 private: 380 private:
372 // Inhibit() response callback. 381 // Inhibit() response callback.
373 // Stores the cookie so we can use it later when calling UnInhibit(). 382 // Stores the cookie so we can use it later when calling UnInhibit().
374 // If the response from D-Bus is successful and there is a postponed 383 // If the response from D-Bus is successful and there is a postponed
375 // uninhibit request, we cancel the cookie that we just received. 384 // uninhibit request, we cancel the cookie that we just received.
376 void OnInhibitResponse(dbus::Response* response) { 385 void OnInhibitResponse(dbus::Response* response) {
377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
378 DCHECK_GT(pending_inhibit_calls_, 0); 387 DCHECK_GT(pending_inhibit_calls_, 0);
379 --pending_inhibit_calls_; 388 --pending_inhibit_calls_;
380 if (response) { 389 if (response) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 } 501 }
493 502
494 } // namespace 503 } // namespace
495 504
496 // Called only from UI thread. 505 // Called only from UI thread.
497 // static 506 // static
498 void PowerSaveBlocker::ApplyBlock(PowerSaveBlockerType type) { 507 void PowerSaveBlocker::ApplyBlock(PowerSaveBlockerType type) {
499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
500 DBusPowerSaveBlocker::GetInstance()->ApplyBlock(type); 509 DBusPowerSaveBlocker::GetInstance()->ApplyBlock(type);
501 } 510 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698