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

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

Issue 6486007: Introducing ResumeLibrary to track system resume signal (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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 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/resume_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/cros/cros_library.h"
11 #include "third_party/cros/chromeos_resume.h"
12
13 namespace chromeos {
14
15 class ResumeLibraryImpl : public ResumeLibrary {
16 public:
17 ResumeLibraryImpl() : connection_(NULL) {
18 if (CrosLibrary::Get()->EnsureLoaded())
19 Init();
20 }
21
22 ~ResumeLibraryImpl() {
23 if (connection_) {
24 chromeos::DisconnectResume(connection_);
25 connection_ = NULL;
26 }
27 }
28
29 void AddObserver(Observer* observer) {
30 observers_.AddObserver(observer);
31 }
32
33 void RemoveObserver(Observer* observer) {
34 observers_.RemoveObserver(observer);
35 }
36
37 private:
38 static void OnSystemResumedHandler(void* object) {
39 ResumeLibraryImpl* self = static_cast<ResumeLibraryImpl*>(object);
40 self->OnSystemResumed();
41 }
42
43 void Init() {
44 DCHECK(!connection_) << "Already intialized";
45 connection_ = chromeos::MonitorResume(&OnSystemResumedHandler, this);
46 }
47
48 void OnSystemResumed() {
49 // Make sure we run on the UI thread.
50 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
51 BrowserThread::PostTask(
52 BrowserThread::UI, FROM_HERE,
53 NewRunnableMethod(this,
54 &ResumeLibraryImpl::OnSystemResumed));
55 return;
56 }
57
58 FOR_EACH_OBSERVER(Observer,
Nikita (slow) 2011/02/11 11:54:51 nit: could fit into 1 line?
glotov 2011/02/11 18:20:56 Done.
59 observers_,
60 SystemResumed());
61 }
62
63 chromeos::ResumeConnection connection_;
64
65 ObserverList<Observer> observers_;
66
67 DISALLOW_COPY_AND_ASSIGN(ResumeLibraryImpl);
68 };
69
70 class ResumeLibraryStubImpl : public ResumeLibrary {
71 public:
72 ResumeLibraryStubImpl() {}
73 ~ResumeLibraryStubImpl() {}
74 void AddObserver(Observer* observer) {}
75 void RemoveObserver(Observer* observer) {}
76 };
77
78 // static
79 ResumeLibrary* ResumeLibrary::GetImpl(bool stub) {
80 if (stub)
81 return new ResumeLibraryStubImpl();
82 else
83 return new ResumeLibraryImpl();
84 }
85
86 } // namespace chromeos
87
88 // Needed for NewRunnableMethod() call above.
Nikita (slow) 2011/02/11 11:54:51 Should mention that this class is Singleton.
glotov 2011/02/11 18:20:56 Done.
89 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::ResumeLibraryImpl);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698