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

Side by Side Diff: chromeos/dbus/system_clock_client.cc

Issue 12564007: Hook up system clock update dbus signal to chrome and ash tray ui. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix MockDBusThreadManagerWithoutGMock compiling issue. Created 7 years, 9 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) 2013 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 "chromeos/dbus/system_clock_client.h"
6
7 #include "base/bind.h"
8 #include "dbus/bus.h"
9 #include "dbus/message.h"
10 #include "dbus/object_path.h"
11 #include "dbus/object_proxy.h"
12 #include "third_party/cros_system_api/dbus/service_constants.h"
13
14 namespace chromeos {
15
16 // The SystemClockClient implementation used in production.
17 class SystemClockClientImpl : public SystemClockClient {
18 public:
19 explicit SystemClockClientImpl(dbus::Bus* bus)
20 : system_clock_proxy_(NULL),
21 weak_ptr_factory_(this) {
22 system_clock_proxy_ = bus->GetObjectProxy(
23 system_clock::kSystemClockServiceName,
24 dbus::ObjectPath(system_clock::kSystemClockServicePath));
25
26 // Monitor the D-Bus signal for TimeUpdated changes.
27 system_clock_proxy_->ConnectToSignal(
28 system_clock::kSystemClockInterface,
29 system_clock::kSystemClockUpdated,
30 base::Bind(&SystemClockClientImpl::TimeUpdatedReceived,
31 weak_ptr_factory_.GetWeakPtr()),
32 base::Bind(&SystemClockClientImpl::TimeUpdatedConnected,
33 weak_ptr_factory_.GetWeakPtr()));
34 }
35
36 virtual ~SystemClockClientImpl() {
37 }
38
39 // SystemClockClient overrides:
40 virtual void AddObserver(Observer* observer) OVERRIDE {
41 observers_.AddObserver(observer);
42 }
43
44 virtual void RemoveObserver(Observer* observer) OVERRIDE {
45 observers_.RemoveObserver(observer);
46 }
47
48 virtual bool HasObserver(Observer* observer) OVERRIDE {
49 return observers_.HasObserver(observer);
50 }
51
52 private:
53 // Called when a TimeUpdated signal is received.
54 void TimeUpdatedReceived(dbus::Signal* signal) {
55 VLOG(1) << "TimeUpdated signal received: " << signal->ToString();
56 dbus::MessageReader reader(signal);
57 FOR_EACH_OBSERVER(Observer, observers_, SystemClockUpdated());
58 }
59
60 // Called when the TimeUpdated signal is initially connected.
61 void TimeUpdatedConnected(const std::string& interface_name,
62 const std::string& signal_name,
63 bool success) {
64 LOG_IF(WARNING, !success)
stevenjb 2013/03/13 17:34:31 ERROR
jennyz 2013/03/13 19:14:02 Done.
65 << "Failed to connect to TimeUpdated signal.";
stevenjb 2013/03/13 17:34:31 DISALLOW...
jennyz 2013/03/13 19:14:02 which this refers to?
stevenjb 2013/03/13 19:22:39 Nevermind, I missed it below somehow.
66 }
67
68 dbus::ObjectProxy* system_clock_proxy_;
69 ObserverList<Observer> observers_;
70
71 // Note: This should remain the last member so it'll be destroyed and
72 // invalidate its weak pointers before any other members are destroyed.
73 base::WeakPtrFactory<SystemClockClientImpl> weak_ptr_factory_;
74
75 DISALLOW_COPY_AND_ASSIGN(SystemClockClientImpl);
76 };
77
78 // The SystemClockClient implementation used on Linux desktop,
79 // which does nothing.
80 class SystemClockClientStubImpl : public SystemClockClient {
stevenjb 2013/03/13 17:34:31 public destructor
jennyz 2013/03/13 19:14:02 Done.
81 // SystemClockClient overrides:
82 virtual void AddObserver(Observer* observer) OVERRIDE {}
83 virtual void RemoveObserver(Observer* observer) OVERRIDE {}
84 virtual bool HasObserver(Observer* observer) OVERRIDE { return false; }
stevenjb 2013/03/13 17:34:31 DISALLOW...
jennyz 2013/03/13 19:14:02 Done.
85 };
86
87 SystemClockClient::SystemClockClient() {
88 }
89
90 SystemClockClient::~SystemClockClient() {
91 }
92
93 // static
94 SystemClockClient* SystemClockClient::Create(
95 DBusClientImplementationType type,
96 dbus::Bus* bus) {
97 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) {
98 return new SystemClockClientImpl(bus);
99 }
100 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
101 return new SystemClockClientStubImpl();
102 }
103
104 } // namespace chromeos
OLDNEW
« chromeos/dbus/system_clock_client.h ('K') | « chromeos/dbus/system_clock_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698