| 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/brightness_library.h" | 5 #include "chrome/browser/chromeos/cros/brightness_library.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 10 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 11 #include "chrome/browser/chromeos/cros/cros_library.h" | 12 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 12 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
| 13 #include "third_party/cros/chromeos_brightness.h" | 14 #include "third_party/cros/chromeos_brightness.h" |
| 14 | 15 |
| 15 namespace chromeos { | 16 namespace chromeos { |
| 16 | 17 |
| 17 class BrightnessLibraryImpl : public BrightnessLibrary { | 18 class BrightnessLibraryImpl : public BrightnessLibrary { |
| 18 public: | 19 public: |
| 19 BrightnessLibraryImpl() : brightness_connection_(NULL) {} | 20 BrightnessLibraryImpl() : brightness_connection_(NULL) {} |
| 20 | 21 |
| 21 ~BrightnessLibraryImpl() { | 22 virtual ~BrightnessLibraryImpl() { |
| 22 if (brightness_connection_) { | 23 if (brightness_connection_) { |
| 23 chromeos::DisconnectBrightness(brightness_connection_); | 24 chromeos::DisconnectBrightness(brightness_connection_); |
| 24 brightness_connection_ = NULL; | 25 brightness_connection_ = NULL; |
| 25 } | 26 } |
| 26 } | 27 } |
| 27 | 28 |
| 28 void Init() { | 29 // Begin BrightnessLibrary implementation. |
| 30 virtual void Init() OVERRIDE { |
| 29 if (CrosLibrary::Get()->EnsureLoaded()) { | 31 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 30 CHECK(!brightness_connection_) << "Already intialized"; | 32 CHECK(!brightness_connection_) << "Already intialized"; |
| 31 brightness_connection_ = | 33 brightness_connection_ = |
| 32 chromeos::MonitorBrightnessV2(&BrightnessChangedHandler, this); | 34 chromeos::MonitorBrightnessV2(&BrightnessChangedHandler, this); |
| 33 } | 35 } |
| 34 } | 36 } |
| 35 | 37 |
| 36 void AddObserver(Observer* observer) { | 38 virtual void AddObserver(Observer* observer) OVERRIDE { |
| 37 observers_.AddObserver(observer); | 39 observers_.AddObserver(observer); |
| 38 } | 40 } |
| 39 | 41 |
| 40 void RemoveObserver(Observer* observer) { | 42 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
| 41 observers_.RemoveObserver(observer); | 43 observers_.RemoveObserver(observer); |
| 42 } | 44 } |
| 43 | 45 |
| 44 void DecreaseScreenBrightness(bool allow_off) { | 46 virtual void DecreaseScreenBrightness(bool allow_off) OVERRIDE { |
| 45 if (chromeos::DecreaseScreenBrightness) | 47 if (chromeos::DecreaseScreenBrightness) |
| 46 chromeos::DecreaseScreenBrightness(allow_off); | 48 chromeos::DecreaseScreenBrightness(allow_off); |
| 47 } | 49 } |
| 48 | 50 |
| 49 void IncreaseScreenBrightness() { | 51 virtual void IncreaseScreenBrightness() OVERRIDE { |
| 50 if (chromeos::IncreaseScreenBrightness) | 52 if (chromeos::IncreaseScreenBrightness) |
| 51 chromeos::IncreaseScreenBrightness(); | 53 chromeos::IncreaseScreenBrightness(); |
| 52 } | 54 } |
| 55 // End BrightnessLibrary implementation. |
| 53 | 56 |
| 54 private: | 57 private: |
| 55 static void BrightnessChangedHandler(void* object, | 58 static void BrightnessChangedHandler(void* object, |
| 56 int brightness_level, | 59 int brightness_level, |
| 57 bool user_initiated) { | 60 bool user_initiated) { |
| 58 BrightnessLibraryImpl* self = static_cast<BrightnessLibraryImpl*>(object); | 61 BrightnessLibraryImpl* self = static_cast<BrightnessLibraryImpl*>(object); |
| 59 self->OnBrightnessChanged(brightness_level, user_initiated); | 62 self->OnBrightnessChanged(brightness_level, user_initiated); |
| 60 } | 63 } |
| 61 | 64 |
| 62 void OnBrightnessChanged(int brightness_level, bool user_initiated) { | 65 void OnBrightnessChanged(int brightness_level, bool user_initiated) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 79 chromeos::BrightnessConnection brightness_connection_; | 82 chromeos::BrightnessConnection brightness_connection_; |
| 80 | 83 |
| 81 ObserverList<Observer> observers_; | 84 ObserverList<Observer> observers_; |
| 82 | 85 |
| 83 DISALLOW_COPY_AND_ASSIGN(BrightnessLibraryImpl); | 86 DISALLOW_COPY_AND_ASSIGN(BrightnessLibraryImpl); |
| 84 }; | 87 }; |
| 85 | 88 |
| 86 class BrightnessLibraryStubImpl : public BrightnessLibrary { | 89 class BrightnessLibraryStubImpl : public BrightnessLibrary { |
| 87 public: | 90 public: |
| 88 BrightnessLibraryStubImpl() {} | 91 BrightnessLibraryStubImpl() {} |
| 89 ~BrightnessLibraryStubImpl() {} | 92 virtual ~BrightnessLibraryStubImpl() {} |
| 90 void Init() {} | 93 virtual void Init() OVERRIDE {} |
| 91 void AddObserver(Observer* observer) {} | 94 virtual void AddObserver(Observer* observer) OVERRIDE {} |
| 92 void RemoveObserver(Observer* observer) {} | 95 virtual void RemoveObserver(Observer* observer) OVERRIDE {} |
| 93 void DecreaseScreenBrightness(bool allow_off) {} | 96 virtual void DecreaseScreenBrightness(bool allow_off) OVERRIDE {} |
| 94 void IncreaseScreenBrightness() {} | 97 virtual void IncreaseScreenBrightness() OVERRIDE {} |
| 95 }; | 98 }; |
| 96 | 99 |
| 97 // static | 100 // static |
| 98 BrightnessLibrary* BrightnessLibrary::GetImpl(bool stub) { | 101 BrightnessLibrary* BrightnessLibrary::GetImpl(bool stub) { |
| 99 BrightnessLibrary* impl; | 102 BrightnessLibrary* impl; |
| 100 if (stub) | 103 if (stub) |
| 101 impl = new BrightnessLibraryStubImpl(); | 104 impl = new BrightnessLibraryStubImpl(); |
| 102 else | 105 else |
| 103 impl = new BrightnessLibraryImpl(); | 106 impl = new BrightnessLibraryImpl(); |
| 104 impl->Init(); | 107 impl->Init(); |
| 105 return impl; | 108 return impl; |
| 106 } | 109 } |
| 107 | 110 |
| 108 } // namespace chromeos | 111 } // namespace chromeos |
| 109 | 112 |
| 110 // Needed for NewRunnableMethod() call above. | 113 // Needed for NewRunnableMethod() call above. |
| 111 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::BrightnessLibraryImpl); | 114 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::BrightnessLibraryImpl); |
| OLD | NEW |