| 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 <X11/Xlib.h> | 5 #include <X11/Xlib.h> |
| 6 #include <X11/extensions/dpms.h> | 6 #include <X11/extensions/dpms.h> |
| 7 #include <X11/extensions/scrnsaver.h> | 7 #include <X11/extensions/scrnsaver.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "device/power_save_blocker/power_save_blocker_impl.h" | 12 #include "device/power_save_blocker/power_save_blocker.h" |
| 13 |
| 13 // Xlib #defines Status, but we can't have that for some of our headers. | 14 // Xlib #defines Status, but we can't have that for some of our headers. |
| 14 #ifdef Status | 15 #ifdef Status |
| 15 #undef Status | 16 #undef Status |
| 16 #endif | 17 #endif |
| 17 | 18 |
| 18 #include "base/bind.h" | 19 #include "base/bind.h" |
| 19 #include "base/callback.h" | 20 #include "base/callback.h" |
| 20 #include "base/command_line.h" | 21 #include "base/command_line.h" |
| 21 #include "base/environment.h" | 22 #include "base/environment.h" |
| 22 #include "base/files/file_path.h" | 23 #include "base/files/file_path.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 "/org/freedesktop/PowerManagement/Inhibit"; | 64 "/org/freedesktop/PowerManagement/Inhibit"; |
| 64 | 65 |
| 65 const char kFreeDesktopAPIScreenServiceName[] = "org.freedesktop.ScreenSaver"; | 66 const char kFreeDesktopAPIScreenServiceName[] = "org.freedesktop.ScreenSaver"; |
| 66 const char kFreeDesktopAPIScreenInterfaceName[] = "org.freedesktop.ScreenSaver"; | 67 const char kFreeDesktopAPIScreenInterfaceName[] = "org.freedesktop.ScreenSaver"; |
| 67 const char kFreeDesktopAPIScreenObjectPath[] = "/org/freedesktop/ScreenSaver"; | 68 const char kFreeDesktopAPIScreenObjectPath[] = "/org/freedesktop/ScreenSaver"; |
| 68 | 69 |
| 69 } // namespace | 70 } // namespace |
| 70 | 71 |
| 71 namespace device { | 72 namespace device { |
| 72 | 73 |
| 73 class PowerSaveBlockerImpl::Delegate | 74 class PowerSaveBlocker::Delegate |
| 74 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> { | 75 : public base::RefCountedThreadSafe<PowerSaveBlocker::Delegate> { |
| 75 public: | 76 public: |
| 76 // Picks an appropriate D-Bus API to use based on the desktop environment. | 77 // Picks an appropriate D-Bus API to use based on the desktop environment. |
| 77 Delegate(PowerSaveBlockerType type, | 78 Delegate(PowerSaveBlockerType type, |
| 78 const std::string& description, | 79 const std::string& description, |
| 79 bool freedesktop_only, | 80 bool freedesktop_only, |
| 80 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 81 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 81 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner); | 82 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner); |
| 82 | 83 |
| 83 // Post a task to initialize the delegate on the UI thread, which will itself | 84 // Post a task to initialize the delegate on the UI thread, which will itself |
| 84 // then post a task to apply the power save block on the FILE thread. | 85 // then post a task to apply the power save block on the FILE thread. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // The cookie that identifies our inhibit request, | 160 // The cookie that identifies our inhibit request, |
| 160 // or 0 if there is no active inhibit request. | 161 // or 0 if there is no active inhibit request. |
| 161 uint32_t inhibit_cookie_; | 162 uint32_t inhibit_cookie_; |
| 162 | 163 |
| 163 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 164 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 164 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner_; | 165 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner_; |
| 165 | 166 |
| 166 DISALLOW_COPY_AND_ASSIGN(Delegate); | 167 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 167 }; | 168 }; |
| 168 | 169 |
| 169 PowerSaveBlockerImpl::Delegate::Delegate( | 170 PowerSaveBlocker::Delegate::Delegate( |
| 170 PowerSaveBlockerType type, | 171 PowerSaveBlockerType type, |
| 171 const std::string& description, | 172 const std::string& description, |
| 172 bool freedesktop_only, | 173 bool freedesktop_only, |
| 173 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 174 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 174 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner) | 175 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner) |
| 175 : type_(type), | 176 : type_(type), |
| 176 description_(description), | 177 description_(description), |
| 177 freedesktop_only_(freedesktop_only), | 178 freedesktop_only_(freedesktop_only), |
| 178 api_(NO_API), | 179 api_(NO_API), |
| 179 enqueue_apply_(false), | 180 enqueue_apply_(false), |
| 180 inhibit_cookie_(0), | 181 inhibit_cookie_(0), |
| 181 ui_task_runner_(ui_task_runner), | 182 ui_task_runner_(ui_task_runner), |
| 182 blocking_task_runner_(blocking_task_runner) { | 183 blocking_task_runner_(blocking_task_runner) { |
| 183 // We're on the client's thread here, so we don't allocate the dbus::Bus | 184 // We're on the client's thread here, so we don't allocate the dbus::Bus |
| 184 // object yet. We'll do it later in ApplyBlock(), on the FILE thread. | 185 // object yet. We'll do it later in ApplyBlock(), on the FILE thread. |
| 185 } | 186 } |
| 186 | 187 |
| 187 void PowerSaveBlockerImpl::Delegate::Init() { | 188 void PowerSaveBlocker::Delegate::Init() { |
| 188 base::AutoLock lock(lock_); | 189 base::AutoLock lock(lock_); |
| 189 DCHECK(!enqueue_apply_); | 190 DCHECK(!enqueue_apply_); |
| 190 enqueue_apply_ = true; | 191 enqueue_apply_ = true; |
| 191 block_inflight_ = false; | 192 block_inflight_ = false; |
| 192 unblock_inflight_ = false; | 193 unblock_inflight_ = false; |
| 193 enqueue_unblock_ = false; | 194 enqueue_unblock_ = false; |
| 194 ui_task_runner_->PostTask(FROM_HERE, | 195 ui_task_runner_->PostTask(FROM_HERE, |
| 195 base::Bind(&Delegate::InitOnUIThread, this)); | 196 base::Bind(&Delegate::InitOnUIThread, this)); |
| 196 } | 197 } |
| 197 | 198 |
| 198 void PowerSaveBlockerImpl::Delegate::CleanUp() { | 199 void PowerSaveBlocker::Delegate::CleanUp() { |
| 199 base::AutoLock lock(lock_); | 200 base::AutoLock lock(lock_); |
| 200 if (enqueue_apply_) { | 201 if (enqueue_apply_) { |
| 201 // If a call to ApplyBlock() has not yet been enqueued because we are still | 202 // If a call to ApplyBlock() has not yet been enqueued because we are still |
| 202 // initializing on the UI thread, then just cancel it. We don't need to | 203 // initializing on the UI thread, then just cancel it. We don't need to |
| 203 // remove the block because we haven't even applied it yet. | 204 // remove the block because we haven't even applied it yet. |
| 204 enqueue_apply_ = false; | 205 enqueue_apply_ = false; |
| 205 } else { | 206 } else { |
| 206 if (ShouldBlock()) { | 207 if (ShouldBlock()) { |
| 207 blocking_task_runner_->PostTask(FROM_HERE, | 208 blocking_task_runner_->PostTask(FROM_HERE, |
| 208 base::Bind(&Delegate::RemoveBlock, this)); | 209 base::Bind(&Delegate::RemoveBlock, this)); |
| 209 } | 210 } |
| 210 | 211 |
| 211 ui_task_runner_->PostTask( | 212 ui_task_runner_->PostTask( |
| 212 FROM_HERE, base::Bind(&Delegate::XSSSuspendSet, this, false)); | 213 FROM_HERE, base::Bind(&Delegate::XSSSuspendSet, this, false)); |
| 213 } | 214 } |
| 214 } | 215 } |
| 215 | 216 |
| 216 void PowerSaveBlockerImpl::Delegate::InitOnUIThread() { | 217 void PowerSaveBlocker::Delegate::InitOnUIThread() { |
| 217 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 218 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 218 base::AutoLock lock(lock_); | 219 base::AutoLock lock(lock_); |
| 219 api_ = SelectAPI(); | 220 api_ = SelectAPI(); |
| 220 | 221 |
| 221 if (enqueue_apply_) { | 222 if (enqueue_apply_) { |
| 222 if (ShouldBlock()) { | 223 if (ShouldBlock()) { |
| 223 // The thread we use here becomes the origin and D-Bus thread for the | 224 // The thread we use here becomes the origin and D-Bus thread for the |
| 224 // D-Bus library, so we need to use the same thread above for | 225 // D-Bus library, so we need to use the same thread above for |
| 225 // RemoveBlock(). It must be a thread that allows I/O operations, so we | 226 // RemoveBlock(). It must be a thread that allows I/O operations, so we |
| 226 // use the FILE thread. | 227 // use the FILE thread. |
| 227 blocking_task_runner_->PostTask(FROM_HERE, | 228 blocking_task_runner_->PostTask(FROM_HERE, |
| 228 base::Bind(&Delegate::ApplyBlock, this)); | 229 base::Bind(&Delegate::ApplyBlock, this)); |
| 229 } | 230 } |
| 230 XSSSuspendSet(true); | 231 XSSSuspendSet(true); |
| 231 } | 232 } |
| 232 enqueue_apply_ = false; | 233 enqueue_apply_ = false; |
| 233 } | 234 } |
| 234 | 235 |
| 235 bool PowerSaveBlockerImpl::Delegate::ShouldBlock() const { | 236 bool PowerSaveBlocker::Delegate::ShouldBlock() const { |
| 236 return freedesktop_only_ ? api_ == FREEDESKTOP_API : api_ != NO_API; | 237 return freedesktop_only_ ? api_ == FREEDESKTOP_API : api_ != NO_API; |
| 237 } | 238 } |
| 238 | 239 |
| 239 void PowerSaveBlockerImpl::Delegate::ApplyBlock() { | 240 void PowerSaveBlocker::Delegate::ApplyBlock() { |
| 240 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 241 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
| 241 DCHECK(!bus_); // ApplyBlock() should only be called once. | 242 DCHECK(!bus_); // ApplyBlock() should only be called once. |
| 242 DCHECK(!block_inflight_); | 243 DCHECK(!block_inflight_); |
| 243 | 244 |
| 244 dbus::Bus::Options options; | 245 dbus::Bus::Options options; |
| 245 options.bus_type = dbus::Bus::SESSION; | 246 options.bus_type = dbus::Bus::SESSION; |
| 246 options.connection_type = dbus::Bus::PRIVATE; | 247 options.connection_type = dbus::Bus::PRIVATE; |
| 247 bus_ = new dbus::Bus(options); | 248 bus_ = new dbus::Bus(options); |
| 248 | 249 |
| 249 scoped_refptr<dbus::ObjectProxy> object_proxy; | 250 scoped_refptr<dbus::ObjectProxy> object_proxy; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 // reason: The reason for the inhibit | 307 // reason: The reason for the inhibit |
| 307 message_writer->AppendString( | 308 message_writer->AppendString( |
| 308 base::CommandLine::ForCurrentProcess()->GetProgram().value()); | 309 base::CommandLine::ForCurrentProcess()->GetProgram().value()); |
| 309 message_writer->AppendString(description_); | 310 message_writer->AppendString(description_); |
| 310 break; | 311 break; |
| 311 } | 312 } |
| 312 | 313 |
| 313 block_inflight_ = true; | 314 block_inflight_ = true; |
| 314 object_proxy->CallMethod( | 315 object_proxy->CallMethod( |
| 315 method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 316 method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 316 base::Bind(&PowerSaveBlockerImpl::Delegate::ApplyBlockFinished, this)); | 317 base::Bind(&PowerSaveBlocker::Delegate::ApplyBlockFinished, this)); |
| 317 } | 318 } |
| 318 | 319 |
| 319 void PowerSaveBlockerImpl::Delegate::ApplyBlockFinished( | 320 void PowerSaveBlocker::Delegate::ApplyBlockFinished(dbus::Response* response) { |
| 320 dbus::Response* response) { | |
| 321 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 321 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
| 322 DCHECK(bus_); | 322 DCHECK(bus_); |
| 323 DCHECK(block_inflight_); | 323 DCHECK(block_inflight_); |
| 324 block_inflight_ = false; | 324 block_inflight_ = false; |
| 325 | 325 |
| 326 if (response) { | 326 if (response) { |
| 327 // The method returns an inhibit_cookie, used to uniquely identify | 327 // The method returns an inhibit_cookie, used to uniquely identify |
| 328 // this request. It should be used as an argument to Uninhibit() | 328 // this request. It should be used as an argument to Uninhibit() |
| 329 // in order to remove the request. | 329 // in order to remove the request. |
| 330 dbus::MessageReader message_reader(response); | 330 dbus::MessageReader message_reader(response); |
| 331 if (!message_reader.PopUint32(&inhibit_cookie_)) | 331 if (!message_reader.PopUint32(&inhibit_cookie_)) |
| 332 LOG(ERROR) << "Invalid Inhibit() response: " << response->ToString(); | 332 LOG(ERROR) << "Invalid Inhibit() response: " << response->ToString(); |
| 333 } else { | 333 } else { |
| 334 LOG(ERROR) << "No response to Inhibit() request!"; | 334 LOG(ERROR) << "No response to Inhibit() request!"; |
| 335 } | 335 } |
| 336 | 336 |
| 337 if (enqueue_unblock_) { | 337 if (enqueue_unblock_) { |
| 338 enqueue_unblock_ = false; | 338 enqueue_unblock_ = false; |
| 339 // RemoveBlock() was called while the Inhibit operation was in flight, | 339 // RemoveBlock() was called while the Inhibit operation was in flight, |
| 340 // so go ahead and remove the block now. | 340 // so go ahead and remove the block now. |
| 341 blocking_task_runner_->PostTask(FROM_HERE, | 341 blocking_task_runner_->PostTask(FROM_HERE, |
| 342 base::Bind(&Delegate::RemoveBlock, this)); | 342 base::Bind(&Delegate::RemoveBlock, this)); |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 | 345 |
| 346 void PowerSaveBlockerImpl::Delegate::RemoveBlock() { | 346 void PowerSaveBlocker::Delegate::RemoveBlock() { |
| 347 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 347 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
| 348 DCHECK(bus_); // RemoveBlock() should only be called once. | 348 DCHECK(bus_); // RemoveBlock() should only be called once. |
| 349 DCHECK(!unblock_inflight_); | 349 DCHECK(!unblock_inflight_); |
| 350 | 350 |
| 351 if (block_inflight_) { | 351 if (block_inflight_) { |
| 352 DCHECK(!enqueue_unblock_); | 352 DCHECK(!enqueue_unblock_); |
| 353 // Can't call RemoveBlock until ApplyBlock's async operation has | 353 // Can't call RemoveBlock until ApplyBlock's async operation has |
| 354 // finished. Enqueue it for execution once ApplyBlock is done. | 354 // finished. Enqueue it for execution once ApplyBlock is done. |
| 355 enqueue_unblock_ = true; | 355 enqueue_unblock_ = true; |
| 356 return; | 356 return; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 387 break; | 387 break; |
| 388 } | 388 } |
| 389 break; | 389 break; |
| 390 } | 390 } |
| 391 | 391 |
| 392 dbus::MessageWriter message_writer(method_call.get()); | 392 dbus::MessageWriter message_writer(method_call.get()); |
| 393 message_writer.AppendUint32(inhibit_cookie_); | 393 message_writer.AppendUint32(inhibit_cookie_); |
| 394 unblock_inflight_ = true; | 394 unblock_inflight_ = true; |
| 395 object_proxy->CallMethod( | 395 object_proxy->CallMethod( |
| 396 method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 396 method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 397 base::Bind(&PowerSaveBlockerImpl::Delegate::RemoveBlockFinished, this)); | 397 base::Bind(&PowerSaveBlocker::Delegate::RemoveBlockFinished, this)); |
| 398 } | 398 } |
| 399 | 399 |
| 400 void PowerSaveBlockerImpl::Delegate::RemoveBlockFinished( | 400 void PowerSaveBlocker::Delegate::RemoveBlockFinished(dbus::Response* response) { |
| 401 dbus::Response* response) { | |
| 402 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); | 401 DCHECK(blocking_task_runner_->RunsTasksOnCurrentThread()); |
| 403 DCHECK(bus_); | 402 DCHECK(bus_); |
| 404 unblock_inflight_ = false; | 403 unblock_inflight_ = false; |
| 405 | 404 |
| 406 if (!response) | 405 if (!response) |
| 407 LOG(ERROR) << "No response to Uninhibit() request!"; | 406 LOG(ERROR) << "No response to Uninhibit() request!"; |
| 408 // We don't care about checking the result. We assume it works; we can't | 407 // We don't care about checking the result. We assume it works; we can't |
| 409 // really do anything about it anyway if it fails. | 408 // really do anything about it anyway if it fails. |
| 410 inhibit_cookie_ = 0; | 409 inhibit_cookie_ = 0; |
| 411 | 410 |
| 412 bus_->ShutdownAndBlock(); | 411 bus_->ShutdownAndBlock(); |
| 413 bus_ = nullptr; | 412 bus_ = nullptr; |
| 414 } | 413 } |
| 415 | 414 |
| 416 void PowerSaveBlockerImpl::Delegate::XSSSuspendSet(bool suspend) { | 415 void PowerSaveBlocker::Delegate::XSSSuspendSet(bool suspend) { |
| 417 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 416 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 418 | 417 |
| 419 if (!XSSAvailable()) | 418 if (!XSSAvailable()) |
| 420 return; | 419 return; |
| 421 | 420 |
| 422 XDisplay* display = gfx::GetXDisplay(); | 421 XDisplay* display = gfx::GetXDisplay(); |
| 423 XScreenSaverSuspend(display, suspend); | 422 XScreenSaverSuspend(display, suspend); |
| 424 } | 423 } |
| 425 | 424 |
| 426 bool PowerSaveBlockerImpl::Delegate::DPMSEnabled() { | 425 bool PowerSaveBlocker::Delegate::DPMSEnabled() { |
| 427 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 426 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 428 XDisplay* display = gfx::GetXDisplay(); | 427 XDisplay* display = gfx::GetXDisplay(); |
| 429 BOOL enabled = false; | 428 BOOL enabled = false; |
| 430 int dummy; | 429 int dummy; |
| 431 if (DPMSQueryExtension(display, &dummy, &dummy) && DPMSCapable(display)) { | 430 if (DPMSQueryExtension(display, &dummy, &dummy) && DPMSCapable(display)) { |
| 432 CARD16 state; | 431 CARD16 state; |
| 433 DPMSInfo(display, &state, &enabled); | 432 DPMSInfo(display, &state, &enabled); |
| 434 } | 433 } |
| 435 return enabled; | 434 return enabled; |
| 436 } | 435 } |
| 437 | 436 |
| 438 bool PowerSaveBlockerImpl::Delegate::XSSAvailable() { | 437 bool PowerSaveBlocker::Delegate::XSSAvailable() { |
| 439 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 438 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 440 XDisplay* display = gfx::GetXDisplay(); | 439 XDisplay* display = gfx::GetXDisplay(); |
| 441 int dummy; | 440 int dummy; |
| 442 int major; | 441 int major; |
| 443 int minor; | 442 int minor; |
| 444 | 443 |
| 445 if (!XScreenSaverQueryExtension(display, &dummy, &dummy)) | 444 if (!XScreenSaverQueryExtension(display, &dummy, &dummy)) |
| 446 return false; | 445 return false; |
| 447 | 446 |
| 448 if (!XScreenSaverQueryVersion(display, &major, &minor)) | 447 if (!XScreenSaverQueryVersion(display, &major, &minor)) |
| 449 return false; | 448 return false; |
| 450 | 449 |
| 451 return major > 1 || (major == 1 && minor >= 1); | 450 return major > 1 || (major == 1 && minor >= 1); |
| 452 } | 451 } |
| 453 | 452 |
| 454 DBusAPI PowerSaveBlockerImpl::Delegate::SelectAPI() { | 453 DBusAPI PowerSaveBlocker::Delegate::SelectAPI() { |
| 455 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 454 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 456 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 455 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| 457 switch (base::nix::GetDesktopEnvironment(env.get())) { | 456 switch (base::nix::GetDesktopEnvironment(env.get())) { |
| 458 case base::nix::DESKTOP_ENVIRONMENT_GNOME: | 457 case base::nix::DESKTOP_ENVIRONMENT_GNOME: |
| 459 case base::nix::DESKTOP_ENVIRONMENT_UNITY: | 458 case base::nix::DESKTOP_ENVIRONMENT_UNITY: |
| 460 if (DPMSEnabled()) | 459 if (DPMSEnabled()) |
| 461 return GNOME_API; | 460 return GNOME_API; |
| 462 break; | 461 break; |
| 463 case base::nix::DESKTOP_ENVIRONMENT_XFCE: | 462 case base::nix::DESKTOP_ENVIRONMENT_XFCE: |
| 464 case base::nix::DESKTOP_ENVIRONMENT_KDE4: | 463 case base::nix::DESKTOP_ENVIRONMENT_KDE4: |
| 465 case base::nix::DESKTOP_ENVIRONMENT_KDE5: | 464 case base::nix::DESKTOP_ENVIRONMENT_KDE5: |
| 466 if (DPMSEnabled()) | 465 if (DPMSEnabled()) |
| 467 return FREEDESKTOP_API; | 466 return FREEDESKTOP_API; |
| 468 break; | 467 break; |
| 469 case base::nix::DESKTOP_ENVIRONMENT_KDE3: | 468 case base::nix::DESKTOP_ENVIRONMENT_KDE3: |
| 470 case base::nix::DESKTOP_ENVIRONMENT_OTHER: | 469 case base::nix::DESKTOP_ENVIRONMENT_OTHER: |
| 471 // Not supported. | 470 // Not supported. |
| 472 break; | 471 break; |
| 473 } | 472 } |
| 474 return NO_API; | 473 return NO_API; |
| 475 } | 474 } |
| 476 | 475 |
| 477 PowerSaveBlockerImpl::PowerSaveBlockerImpl( | 476 PowerSaveBlocker::PowerSaveBlocker( |
| 478 PowerSaveBlockerType type, | 477 PowerSaveBlockerType type, |
| 479 Reason reason, | 478 Reason reason, |
| 480 const std::string& description, | 479 const std::string& description, |
| 481 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 480 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 482 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner) | 481 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner) |
| 483 : delegate_(new Delegate(type, | 482 : delegate_(new Delegate(type, |
| 484 description, | 483 description, |
| 485 false /* freedesktop_only */, | 484 false /* freedesktop_only */, |
| 486 ui_task_runner, | 485 ui_task_runner, |
| 487 blocking_task_runner)), | 486 blocking_task_runner)), |
| 488 ui_task_runner_(ui_task_runner), | 487 ui_task_runner_(ui_task_runner), |
| 489 blocking_task_runner_(blocking_task_runner) { | 488 blocking_task_runner_(blocking_task_runner) { |
| 490 delegate_->Init(); | 489 delegate_->Init(); |
| 491 | 490 |
| 492 if (type == kPowerSaveBlockPreventDisplaySleep) { | 491 if (type == kPowerSaveBlockPreventDisplaySleep) { |
| 493 freedesktop_suspend_delegate_ = new Delegate( | 492 freedesktop_suspend_delegate_ = new Delegate( |
| 494 kPowerSaveBlockPreventAppSuspension, description, | 493 kPowerSaveBlockPreventAppSuspension, description, |
| 495 true /* freedesktop_only */, ui_task_runner, blocking_task_runner); | 494 true /* freedesktop_only */, ui_task_runner, blocking_task_runner); |
| 496 freedesktop_suspend_delegate_->Init(); | 495 freedesktop_suspend_delegate_->Init(); |
| 497 } | 496 } |
| 498 } | 497 } |
| 499 | 498 |
| 500 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { | 499 PowerSaveBlocker::~PowerSaveBlocker() { |
| 501 delegate_->CleanUp(); | 500 delegate_->CleanUp(); |
| 502 if (freedesktop_suspend_delegate_) | 501 if (freedesktop_suspend_delegate_) |
| 503 freedesktop_suspend_delegate_->CleanUp(); | 502 freedesktop_suspend_delegate_->CleanUp(); |
| 504 } | 503 } |
| 505 | 504 |
| 506 } // namespace device | 505 } // namespace device |
| OLD | NEW |