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

Side by Side Diff: chrome/browser/chromeos/cros/brightness_library.cc

Issue 5620004: chromeos: Show onscreen bubble when brightness changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser/chromeos
Patch Set: remove unnecessary includes Created 10 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 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.
4
5 #include "chrome/browser/chromeos/cros/brightness_library.h"
6
7 #include "base/message_loop.h"
8 #include "base/observer_list.h"
9 #include "chrome/browser/browser_thread.h"
10 #include "chrome/browser/chromeos/brightness_bubble.h"
11 #include "chrome/browser/chromeos/volume_bubble.h"
12 #include "chrome/browser/chromeos/cros/cros_library.h"
13
14 namespace chromeos {
15
16 class BrightnessLibraryImpl : public BrightnessLibrary {
17 public:
18 BrightnessLibraryImpl() : brightness_connection_(NULL) {
19 if (CrosLibrary::Get()->EnsureLoaded())
20 Init();
21 }
22
23 ~BrightnessLibraryImpl() {
24 if (brightness_connection_) {
25 chromeos::DisconnectBrightness(brightness_connection_);
26 brightness_connection_ = NULL;
27 }
28 }
29
30 void AddObserver(Observer* observer) {
31 observers_.AddObserver(observer);
32 }
33
34 void RemoveObserver(Observer* observer) {
35 observers_.RemoveObserver(observer);
36 }
37
38 private:
39 static void BrightnessChangedHandler(void* object,
40 int brightness_level) {
41 BrightnessLibraryImpl* self = static_cast<BrightnessLibraryImpl*>(object);
42 self->OnBrightnessChanged(brightness_level);
43 }
44
45 void Init() {
46 DCHECK(!brightness_connection_) << "Already intialized";
47 brightness_connection_ =
48 chromeos::MonitorBrightness(&BrightnessChangedHandler, this);
49 }
50
51 void OnBrightnessChanged(int brightness_level) {
52 // Make sure we run on the UI thread.
53 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
54 BrowserThread::PostTask(
55 BrowserThread::UI, FROM_HERE,
56 NewRunnableMethod(this,
57 &BrightnessLibraryImpl::OnBrightnessChanged,
58 brightness_level));
59 return;
60 }
61
62 FOR_EACH_OBSERVER(Observer,
63 observers_,
64 BrightnessChanged(brightness_level));
65 }
66
67 chromeos::BrightnessConnection brightness_connection_;
68
69 ObserverList<Observer> observers_;
70
71 DISALLOW_COPY_AND_ASSIGN(BrightnessLibraryImpl);
72 };
73
74 class BrightnessLibraryStubImpl : public BrightnessLibrary {
75 public:
76 BrightnessLibraryStubImpl() {}
77 ~BrightnessLibraryStubImpl() {}
78 void AddObserver(Observer* observer) {}
79 void RemoveObserver(Observer* observer) {}
80 };
81
82 // static
83 BrightnessLibrary* BrightnessLibrary::GetImpl(bool stub) {
84 if (stub)
85 return new BrightnessLibraryStubImpl();
86 else
87 return new BrightnessLibraryImpl();
88 }
89
90 } // namespace chromeos
91
92 // Allows InvokeLater without adding refcounting. This class is a Singleton and
glotov 2010/12/09 18:46:13 What is 'InvokeLater' here?
93 // won't be deleted until its last InvokeLater is run.
94 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::BrightnessLibraryImpl);
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/brightness_library.h ('k') | chrome/browser/chromeos/cros/cros_library.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698