| 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 "content/browser/power_save_blocker_impl.h" | 5 #include "content/browser/power_save_blocker_impl.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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // initializing on the UI thread, then just cancel it. We don't need to | 150 // initializing on the UI thread, then just cancel it. We don't need to |
| 151 // remove the block because we haven't even applied it yet. | 151 // remove the block because we haven't even applied it yet. |
| 152 enqueue_apply_ = false; | 152 enqueue_apply_ = false; |
| 153 } else if (api_ != NO_API) { | 153 } else if (api_ != NO_API) { |
| 154 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 154 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 155 base::Bind(&Delegate::RemoveBlock, this, api_)); | 155 base::Bind(&Delegate::RemoveBlock, this, api_)); |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 | 158 |
| 159 void PowerSaveBlockerImpl::Delegate::InitOnUIThread() { | 159 void PowerSaveBlockerImpl::Delegate::InitOnUIThread() { |
| 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 160 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 161 base::AutoLock lock(lock_); | 161 base::AutoLock lock(lock_); |
| 162 api_ = SelectAPI(); | 162 api_ = SelectAPI(); |
| 163 if (enqueue_apply_ && api_ != NO_API) { | 163 if (enqueue_apply_ && api_ != NO_API) { |
| 164 // The thread we use here becomes the origin and D-Bus thread for the D-Bus | 164 // The thread we use here becomes the origin and D-Bus thread for the D-Bus |
| 165 // library, so we need to use the same thread above for RemoveBlock(). It | 165 // library, so we need to use the same thread above for RemoveBlock(). It |
| 166 // must be a thread that allows I/O operations, so we use the FILE thread. | 166 // must be a thread that allows I/O operations, so we use the FILE thread. |
| 167 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 167 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 168 base::Bind(&Delegate::ApplyBlock, this, api_)); | 168 base::Bind(&Delegate::ApplyBlock, this, api_)); |
| 169 } | 169 } |
| 170 enqueue_apply_ = false; | 170 enqueue_apply_ = false; |
| 171 } | 171 } |
| 172 | 172 |
| 173 void PowerSaveBlockerImpl::Delegate::ApplyBlock(DBusAPI api) { | 173 void PowerSaveBlockerImpl::Delegate::ApplyBlock(DBusAPI api) { |
| 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 174 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 175 DCHECK(!bus_.get()); // ApplyBlock() should only be called once. | 175 DCHECK(!bus_.get()); // ApplyBlock() should only be called once. |
| 176 | 176 |
| 177 dbus::Bus::Options options; | 177 dbus::Bus::Options options; |
| 178 options.bus_type = dbus::Bus::SESSION; | 178 options.bus_type = dbus::Bus::SESSION; |
| 179 options.connection_type = dbus::Bus::PRIVATE; | 179 options.connection_type = dbus::Bus::PRIVATE; |
| 180 bus_ = new dbus::Bus(options); | 180 bus_ = new dbus::Bus(options); |
| 181 | 181 |
| 182 scoped_refptr<dbus::ObjectProxy> object_proxy; | 182 scoped_refptr<dbus::ObjectProxy> object_proxy; |
| 183 scoped_ptr<dbus::MethodCall> method_call; | 183 scoped_ptr<dbus::MethodCall> method_call; |
| 184 scoped_ptr<dbus::MessageWriter> message_writer; | 184 scoped_ptr<dbus::MessageWriter> message_writer; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 // in order to remove the request. | 244 // in order to remove the request. |
| 245 dbus::MessageReader message_reader(response.get()); | 245 dbus::MessageReader message_reader(response.get()); |
| 246 if (!message_reader.PopUint32(&inhibit_cookie_)) | 246 if (!message_reader.PopUint32(&inhibit_cookie_)) |
| 247 LOG(ERROR) << "Invalid Inhibit() response: " << response->ToString(); | 247 LOG(ERROR) << "Invalid Inhibit() response: " << response->ToString(); |
| 248 } else { | 248 } else { |
| 249 LOG(ERROR) << "No response to Inhibit() request!"; | 249 LOG(ERROR) << "No response to Inhibit() request!"; |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 | 252 |
| 253 void PowerSaveBlockerImpl::Delegate::RemoveBlock(DBusAPI api) { | 253 void PowerSaveBlockerImpl::Delegate::RemoveBlock(DBusAPI api) { |
| 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 254 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 255 DCHECK(bus_.get()); // RemoveBlock() should only be called once. | 255 DCHECK(bus_.get()); // RemoveBlock() should only be called once. |
| 256 | 256 |
| 257 scoped_refptr<dbus::ObjectProxy> object_proxy; | 257 scoped_refptr<dbus::ObjectProxy> object_proxy; |
| 258 scoped_ptr<dbus::MethodCall> method_call; | 258 scoped_ptr<dbus::MethodCall> method_call; |
| 259 | 259 |
| 260 switch (api) { | 260 switch (api) { |
| 261 case NO_API: | 261 case NO_API: |
| 262 NOTREACHED(); // We should never call this method with this value. | 262 NOTREACHED(); // We should never call this method with this value. |
| 263 return; | 263 return; |
| 264 case GNOME_API: | 264 case GNOME_API: |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 const std::string& description) | 330 const std::string& description) |
| 331 : delegate_(new Delegate(type, description)) { | 331 : delegate_(new Delegate(type, description)) { |
| 332 delegate_->Init(); | 332 delegate_->Init(); |
| 333 } | 333 } |
| 334 | 334 |
| 335 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { | 335 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { |
| 336 delegate_->CleanUp(); | 336 delegate_->CleanUp(); |
| 337 } | 337 } |
| 338 | 338 |
| 339 } // namespace content | 339 } // namespace content |
| OLD | NEW |