By moving the call to Load() up in SearchProvider::Start(), we are giving a chance...
[chromium-blink-merge.git] / content / browser / power_save_blocker_chromeos.cc
blob78954774baadaad4689bfcf6e252023a1c7a55b4
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
3 // found in the LICENSE file.
5 #include "content/browser/power_save_blocker_impl.h"
7 #include "base/basictypes.h"
8 #include "base/bind.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "chromeos/power/power_state_override.h"
12 #include "content/public/browser/browser_thread.h"
14 namespace content {
16 class PowerSaveBlockerImpl::Delegate
17 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> {
18 public:
19 Delegate(PowerSaveBlockerType type) : type_(type) {}
21 // Creates a PowerStateOverride object to override the default power
22 // management behavior.
23 void ApplyBlock() {
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
25 chromeos::PowerStateOverride::Mode mode =
26 chromeos::PowerStateOverride::BLOCK_SYSTEM_SUSPEND;
27 switch (type_) {
28 case kPowerSaveBlockPreventAppSuspension:
29 mode = chromeos::PowerStateOverride::BLOCK_SYSTEM_SUSPEND;
30 break;
31 case kPowerSaveBlockPreventDisplaySleep:
32 mode = chromeos::PowerStateOverride::BLOCK_DISPLAY_SLEEP;
33 break;
34 default:
35 NOTREACHED() << "Unhandled block type " << type_;
37 override_ = new chromeos::PowerStateOverride(mode);
40 // Resets the previously-created PowerStateOverride object.
41 void RemoveBlock() {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
43 override_ = NULL;
46 private:
47 friend class base::RefCountedThreadSafe<Delegate>;
48 virtual ~Delegate() {}
50 PowerSaveBlockerType type_;
52 scoped_refptr<chromeos::PowerStateOverride> override_;
54 DISALLOW_COPY_AND_ASSIGN(Delegate);
57 PowerSaveBlockerImpl::PowerSaveBlockerImpl(PowerSaveBlockerType type,
58 const std::string& reason)
59 : delegate_(new Delegate(type)) {
60 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
61 base::Bind(&Delegate::ApplyBlock, delegate_));
64 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() {
65 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
66 base::Bind(&Delegate::RemoveBlock, delegate_));
69 } // namespace content