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

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 browser_tests by adding MockSystemClockClient. 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
« no previous file with comments | « chromeos/dbus/system_clock_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
Dan Beam 2016/11/28 21:42:50 is |signal| guaranteed to be non-null here?
stevenjb 2016/11/28 21:58:32 Yes. ObjectProxy::HandleMessage calls RunMethod wi
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(ERROR, !success)
65 << "Failed to connect to TimeUpdated signal.";
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 {
81 public:
82 SystemClockClientStubImpl() {}
83 ~SystemClockClientStubImpl() {}
84
85 // SystemClockClient overrides:
86 virtual void AddObserver(Observer* observer) OVERRIDE {}
87 virtual void RemoveObserver(Observer* observer) OVERRIDE {}
88 virtual bool HasObserver(Observer* observer) OVERRIDE { return false; }
89
90 private:
91 DISALLOW_COPY_AND_ASSIGN(SystemClockClientStubImpl);
92 };
93
94 SystemClockClient::SystemClockClient() {
95 }
96
97 SystemClockClient::~SystemClockClient() {
98 }
99
100 // static
101 SystemClockClient* SystemClockClient::Create(
102 DBusClientImplementationType type,
103 dbus::Bus* bus) {
104 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) {
105 return new SystemClockClientImpl(bus);
106 }
107 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
108 return new SystemClockClientStubImpl();
109 }
110
111 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/system_clock_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698