OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 | 42 |
43 virtual void AddObserver(Observer* observer) OVERRIDE { | 43 virtual void AddObserver(Observer* observer) OVERRIDE { |
44 observers_.AddObserver(observer); | 44 observers_.AddObserver(observer); |
45 } | 45 } |
46 | 46 |
47 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 47 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
48 observers_.RemoveObserver(observer); | 48 observers_.RemoveObserver(observer); |
49 } | 49 } |
50 | 50 |
51 virtual void EnableScreenLock(bool enable) OVERRIDE { | |
52 // Called when the screen preference is changed, which should always | |
53 // run on UI thread. | |
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
55 // Post the task to FILE thread as chromeos::EnableScreenLock | |
56 // would write power manager config file to disk. | |
57 BrowserThread::PostTask( | |
58 BrowserThread::FILE, FROM_HERE, | |
59 base::Bind(&PowerLibraryImpl::DoEnableScreenLock, enable)); | |
60 } | |
61 | |
62 // End PowerLibrary implementation. | 51 // End PowerLibrary implementation. |
63 | 52 |
64 private: | 53 private: |
65 static void DoEnableScreenLock(bool enable) { | |
66 chromeos::EnableScreenLock(enable); | |
67 } | |
68 | 54 |
69 static void SystemResumedHandler(void* object) { | 55 static void SystemResumedHandler(void* object) { |
70 PowerLibraryImpl* power = static_cast<PowerLibraryImpl*>(object); | 56 PowerLibraryImpl* power = static_cast<PowerLibraryImpl*>(object); |
71 power->SystemResumed(); | 57 power->SystemResumed(); |
72 } | 58 } |
73 | 59 |
74 void SystemResumed() { | 60 void SystemResumed() { |
75 // Called from SystemResumedHandler, a libcros callback which should | 61 // Called from SystemResumedHandler, a libcros callback which should |
76 // always run on UI thread. | 62 // always run on UI thread. |
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 20 matching lines...) Expand all Loading... |
98 // Begin PowerLibrary implementation. | 84 // Begin PowerLibrary implementation. |
99 virtual void Init() OVERRIDE {} | 85 virtual void Init() OVERRIDE {} |
100 virtual void AddObserver(Observer* observer) OVERRIDE { | 86 virtual void AddObserver(Observer* observer) OVERRIDE { |
101 observers_.AddObserver(observer); | 87 observers_.AddObserver(observer); |
102 } | 88 } |
103 | 89 |
104 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 90 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
105 observers_.RemoveObserver(observer); | 91 observers_.RemoveObserver(observer); |
106 } | 92 } |
107 | 93 |
108 virtual void EnableScreenLock(bool enable) OVERRIDE {} | |
109 | |
110 // End PowerLibrary implementation. | 94 // End PowerLibrary implementation. |
111 private: | 95 private: |
112 ObserverList<Observer> observers_; | 96 ObserverList<Observer> observers_; |
113 }; | 97 }; |
114 | 98 |
115 // static | 99 // static |
116 PowerLibrary* PowerLibrary::GetImpl(bool stub) { | 100 PowerLibrary* PowerLibrary::GetImpl(bool stub) { |
117 PowerLibrary* impl; | 101 PowerLibrary* impl; |
118 if (stub) | 102 if (stub) |
119 impl = new PowerLibraryStubImpl(); | 103 impl = new PowerLibraryStubImpl(); |
120 else | 104 else |
121 impl = new PowerLibraryImpl(); | 105 impl = new PowerLibraryImpl(); |
122 impl->Init(); | 106 impl->Init(); |
123 return impl; | 107 return impl; |
124 } | 108 } |
125 | 109 |
126 } // namespace chromeos | 110 } // namespace chromeos |
OLD | NEW |