Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(555)

Unified Diff: chrome/browser/chromeos/cros/brightness_library.cc

Issue 7493061: cros: Apply the Init() model to BrightnessLibrary API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: brightness_connection_ is a typedef to a pointer allocated on the heap Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/cros/brightness_library.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..3e3e98edd6f5026803f61aff4454c97efa072a2a 100644
--- a/chrome/browser/chromeos/cros/brightness_library.cc
+++ b/chrome/browser/chromeos/cros/brightness_library.cc
@@ -16,10 +16,7 @@ namespace chromeos {
class BrightnessLibraryImpl : public BrightnessLibrary {
public:
- BrightnessLibraryImpl() : brightness_connection_(NULL) {
- if (CrosLibrary::Get()->EnsureLoaded())
- Init();
- }
+ BrightnessLibraryImpl() : brightness_connection_(NULL) {}
~BrightnessLibraryImpl() {
if (brightness_connection_) {
@@ -28,14 +25,12 @@ class BrightnessLibraryImpl : public BrightnessLibrary {
}
}
- void DecreaseScreenBrightness(bool allow_off) {
- if (chromeos::DecreaseScreenBrightness)
- chromeos::DecreaseScreenBrightness(allow_off);
- }
-
- void IncreaseScreenBrightness() {
- if (chromeos::IncreaseScreenBrightness)
- chromeos::IncreaseScreenBrightness();
+ void Init() {
+ if (CrosLibrary::Get()->EnsureLoaded()) {
+ CHECK(!brightness_connection_) << "Already intialized";
+ brightness_connection_ =
+ chromeos::MonitorBrightnessV2(&BrightnessChangedHandler, this);
+ }
}
void AddObserver(Observer* observer) {
@@ -46,6 +41,16 @@ class BrightnessLibraryImpl : public BrightnessLibrary {
observers_.RemoveObserver(observer);
}
+ void DecreaseScreenBrightness(bool allow_off) {
+ if (chromeos::DecreaseScreenBrightness)
+ chromeos::DecreaseScreenBrightness(allow_off);
+ }
+
+ void IncreaseScreenBrightness() {
+ if (chromeos::IncreaseScreenBrightness)
+ chromeos::IncreaseScreenBrightness();
+ }
+
private:
static void BrightnessChangedHandler(void* object,
int brightness_level,
@@ -54,12 +59,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 +87,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
« no previous file with comments | « chrome/browser/chromeos/cros/brightness_library.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698