OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/dbus/system_clock_client.h" | 5 #include "chromeos/dbus/system_clock_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "dbus/bus.h" | 10 #include "dbus/bus.h" |
11 #include "dbus/message.h" | 11 #include "dbus/message.h" |
12 #include "dbus/object_path.h" | 12 #include "dbus/object_path.h" |
13 #include "dbus/object_proxy.h" | 13 #include "dbus/object_proxy.h" |
14 #include "third_party/cros_system_api/dbus/service_constants.h" | 14 #include "third_party/cros_system_api/dbus/service_constants.h" |
15 | 15 |
16 namespace chromeos { | 16 namespace chromeos { |
17 | 17 |
18 // The SystemClockClient implementation used in production. | 18 // The SystemClockClient implementation used in production. |
19 class SystemClockClientImpl : public SystemClockClient { | 19 class SystemClockClientImpl : public SystemClockClient { |
20 public: | 20 public: |
21 SystemClockClientImpl() | 21 SystemClockClientImpl() |
22 : can_set_time_(false), | 22 : can_set_time_(false), |
23 can_set_time_initialized_(false), | 23 can_set_time_initialized_(false), |
24 system_clock_proxy_(NULL), | 24 system_clock_proxy_(NULL), |
25 weak_ptr_factory_(this) {} | 25 weak_ptr_factory_(this) {} |
26 | 26 |
27 virtual ~SystemClockClientImpl() { | 27 virtual ~SystemClockClientImpl() { |
28 } | 28 } |
29 | 29 |
30 virtual void AddObserver(Observer* observer) OVERRIDE { | 30 virtual void AddObserver(Observer* observer) override { |
31 observers_.AddObserver(observer); | 31 observers_.AddObserver(observer); |
32 } | 32 } |
33 | 33 |
34 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 34 virtual void RemoveObserver(Observer* observer) override { |
35 observers_.RemoveObserver(observer); | 35 observers_.RemoveObserver(observer); |
36 } | 36 } |
37 | 37 |
38 virtual bool HasObserver(Observer* observer) OVERRIDE { | 38 virtual bool HasObserver(Observer* observer) override { |
39 return observers_.HasObserver(observer); | 39 return observers_.HasObserver(observer); |
40 } | 40 } |
41 | 41 |
42 virtual void SetTime(int64 time_in_seconds) OVERRIDE { | 42 virtual void SetTime(int64 time_in_seconds) override { |
43 // Always try to set the time, because |can_set_time_| may be stale. | 43 // Always try to set the time, because |can_set_time_| may be stale. |
44 dbus::MethodCall method_call(system_clock::kSystemClockInterface, | 44 dbus::MethodCall method_call(system_clock::kSystemClockInterface, |
45 system_clock::kSystemClockSet); | 45 system_clock::kSystemClockSet); |
46 dbus::MessageWriter writer(&method_call); | 46 dbus::MessageWriter writer(&method_call); |
47 writer.AppendInt64(time_in_seconds); | 47 writer.AppendInt64(time_in_seconds); |
48 system_clock_proxy_->CallMethod(&method_call, | 48 system_clock_proxy_->CallMethod(&method_call, |
49 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 49 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
50 dbus::ObjectProxy::EmptyResponseCallback()); | 50 dbus::ObjectProxy::EmptyResponseCallback()); |
51 } | 51 } |
52 | 52 |
53 virtual bool CanSetTime() OVERRIDE { return can_set_time_; } | 53 virtual bool CanSetTime() override { return can_set_time_; } |
54 | 54 |
55 protected: | 55 protected: |
56 virtual void Init(dbus::Bus* bus) OVERRIDE { | 56 virtual void Init(dbus::Bus* bus) override { |
57 system_clock_proxy_ = bus->GetObjectProxy( | 57 system_clock_proxy_ = bus->GetObjectProxy( |
58 system_clock::kSystemClockServiceName, | 58 system_clock::kSystemClockServiceName, |
59 dbus::ObjectPath(system_clock::kSystemClockServicePath)); | 59 dbus::ObjectPath(system_clock::kSystemClockServicePath)); |
60 | 60 |
61 // Check whether the system clock can be set. | 61 // Check whether the system clock can be set. |
62 GetCanSet(); | 62 GetCanSet(); |
63 | 63 |
64 // Monitor the D-Bus signal for TimeUpdated changes. | 64 // Monitor the D-Bus signal for TimeUpdated changes. |
65 system_clock_proxy_->ConnectToSignal( | 65 system_clock_proxy_->ConnectToSignal( |
66 system_clock::kSystemClockInterface, | 66 system_clock::kSystemClockInterface, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 151 |
152 SystemClockClient::~SystemClockClient() { | 152 SystemClockClient::~SystemClockClient() { |
153 } | 153 } |
154 | 154 |
155 // static | 155 // static |
156 SystemClockClient* SystemClockClient::Create() { | 156 SystemClockClient* SystemClockClient::Create() { |
157 return new SystemClockClientImpl(); | 157 return new SystemClockClientImpl(); |
158 } | 158 } |
159 | 159 |
160 } // namespace chromeos | 160 } // namespace chromeos |
OLD | NEW |