Chromium Code Reviews| Index: chrome/browser/chromeos/cros/brightness_library.cc |
| diff --git a/chrome/browser/chromeos/cros/brightness_library.cc b/chrome/browser/chromeos/cros/brightness_library.cc |
| index ba8066352cf9a0dd73595910effd63eeb66ef371..13285603e336c1d3a33bf7fbec93b2c5262eddfb 100644 |
| --- a/chrome/browser/chromeos/cros/brightness_library.cc |
| +++ b/chrome/browser/chromeos/cros/brightness_library.cc |
| @@ -16,18 +16,29 @@ namespace chromeos { |
| class BrightnessLibraryImpl : public BrightnessLibrary { |
| public: |
| - BrightnessLibraryImpl() : brightness_connection_(NULL) { |
| - if (CrosLibrary::Get()->EnsureLoaded()) |
| - Init(); |
| - } |
| + BrightnessLibraryImpl() {} |
|
stevenjb
2011/07/29 19:19:15
Still need to initialize brightness_connection_ to
tfarina
2011/07/29 19:44:22
Like in ScreenLockLibraryImpl, we didn't need this
|
| ~BrightnessLibraryImpl() { |
| - if (brightness_connection_) { |
| + if (brightness_connection_) |
| chromeos::DisconnectBrightness(brightness_connection_); |
| - brightness_connection_ = NULL; |
| + } |
| + |
| + void Init() { |
| + if (CrosLibrary::Get()->EnsureLoaded()) { |
| + DCHECK(!brightness_connection_) << "Already intialized"; |
|
stevenjb
2011/07/29 19:19:15
This should either be a CHECK, or we should call D
tfarina
2011/07/29 19:44:22
Changed to CHECK.
|
| + brightness_connection_ = |
| + chromeos::MonitorBrightnessV2(&BrightnessChangedHandler, this); |
| } |
| } |
| + void AddObserver(Observer* observer) { |
| + observers_.AddObserver(observer); |
| + } |
| + |
| + void RemoveObserver(Observer* observer) { |
| + observers_.RemoveObserver(observer); |
| + } |
| + |
| void DecreaseScreenBrightness(bool allow_off) { |
| if (chromeos::DecreaseScreenBrightness) |
| chromeos::DecreaseScreenBrightness(allow_off); |
| @@ -38,14 +49,6 @@ class BrightnessLibraryImpl : public BrightnessLibrary { |
| chromeos::IncreaseScreenBrightness(); |
| } |
| - void AddObserver(Observer* observer) { |
| - observers_.AddObserver(observer); |
| - } |
| - |
| - void RemoveObserver(Observer* observer) { |
| - observers_.RemoveObserver(observer); |
| - } |
| - |
| private: |
| static void BrightnessChangedHandler(void* object, |
| int brightness_level, |
| @@ -54,12 +57,6 @@ class BrightnessLibraryImpl : public BrightnessLibrary { |
| self->OnBrightnessChanged(brightness_level, user_initiated); |
| } |
| - void Init() { |
| - DCHECK(!brightness_connection_) << "Already intialized"; |
| - brightness_connection_ = |
| - chromeos::MonitorBrightnessV2(&BrightnessChangedHandler, this); |
| - } |
| - |
| void OnBrightnessChanged(int brightness_level, bool user_initiated) { |
| // Make sure we run on the UI thread. |
| if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| @@ -88,18 +85,22 @@ class BrightnessLibraryStubImpl : public BrightnessLibrary { |
| public: |
| BrightnessLibraryStubImpl() {} |
| ~BrightnessLibraryStubImpl() {} |
| - void DecreaseScreenBrightness(bool allow_off) {} |
| - void IncreaseScreenBrightness() {} |
| + void Init() {} |
| void AddObserver(Observer* observer) {} |
| void RemoveObserver(Observer* observer) {} |
| + void DecreaseScreenBrightness(bool allow_off) {} |
| + void IncreaseScreenBrightness() {} |
| }; |
| // static |
| BrightnessLibrary* BrightnessLibrary::GetImpl(bool stub) { |
| + BrightnessLibrary* impl; |
| if (stub) |
| - return new BrightnessLibraryStubImpl(); |
| + impl = new BrightnessLibraryStubImpl(); |
| else |
| - return new BrightnessLibraryImpl(); |
| + impl = new BrightnessLibraryImpl(); |
| + impl->Init(); |
| + return impl; |
| } |
| } // namespace chromeos |