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

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

Issue 2236713002: chromeos: Don't spam logs with tlsdate D-Bus errors at boot. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« 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
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "dbus/bus.h" 12 #include "dbus/bus.h"
13 #include "dbus/message.h" 13 #include "dbus/message.h"
14 #include "dbus/object_path.h" 14 #include "dbus/object_path.h"
15 #include "dbus/object_proxy.h" 15 #include "dbus/object_proxy.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h" 16 #include "third_party/cros_system_api/dbus/service_constants.h"
17 17
18 namespace chromeos { 18 namespace chromeos {
19 19
20 // The SystemClockClient implementation used in production. 20 // The SystemClockClient implementation used in production.
21 class SystemClockClientImpl : public SystemClockClient { 21 class SystemClockClientImpl : public SystemClockClient {
22 public: 22 public:
23 SystemClockClientImpl() 23 SystemClockClientImpl()
24 : can_set_time_(false), 24 : can_set_time_(false),
25 can_set_time_initialized_(false), 25 system_clock_proxy_(nullptr),
26 system_clock_proxy_(NULL),
27 weak_ptr_factory_(this) {} 26 weak_ptr_factory_(this) {}
28 27
29 ~SystemClockClientImpl() override {} 28 ~SystemClockClientImpl() override {}
30 29
31 void AddObserver(Observer* observer) override { 30 void AddObserver(Observer* observer) override {
32 observers_.AddObserver(observer); 31 observers_.AddObserver(observer);
33 } 32 }
34 33
35 void RemoveObserver(Observer* observer) override { 34 void RemoveObserver(Observer* observer) override {
36 observers_.RemoveObserver(observer); 35 observers_.RemoveObserver(observer);
(...skipping 14 matching lines...) Expand all
51 dbus::ObjectProxy::EmptyResponseCallback()); 50 dbus::ObjectProxy::EmptyResponseCallback());
52 } 51 }
53 52
54 bool CanSetTime() override { return can_set_time_; } 53 bool CanSetTime() override { return can_set_time_; }
55 54
56 protected: 55 protected:
57 void Init(dbus::Bus* bus) override { 56 void Init(dbus::Bus* bus) override {
58 system_clock_proxy_ = bus->GetObjectProxy( 57 system_clock_proxy_ = bus->GetObjectProxy(
59 system_clock::kSystemClockServiceName, 58 system_clock::kSystemClockServiceName,
60 dbus::ObjectPath(system_clock::kSystemClockServicePath)); 59 dbus::ObjectPath(system_clock::kSystemClockServicePath));
61
62 // Check whether the system clock can be set.
63 GetCanSet();
64
65 // Monitor the D-Bus signal for TimeUpdated changes.
66 system_clock_proxy_->ConnectToSignal( 60 system_clock_proxy_->ConnectToSignal(
67 system_clock::kSystemClockInterface, 61 system_clock::kSystemClockInterface,
68 system_clock::kSystemClockUpdated, 62 system_clock::kSystemClockUpdated,
69 base::Bind(&SystemClockClientImpl::TimeUpdatedReceived, 63 base::Bind(&SystemClockClientImpl::TimeUpdatedReceived,
70 weak_ptr_factory_.GetWeakPtr()), 64 weak_ptr_factory_.GetWeakPtr()),
71 base::Bind(&SystemClockClientImpl::TimeUpdatedConnected, 65 base::Bind(&SystemClockClientImpl::TimeUpdatedConnected,
72 weak_ptr_factory_.GetWeakPtr())); 66 weak_ptr_factory_.GetWeakPtr()));
67 system_clock_proxy_->WaitForServiceToBeAvailable(
68 base::Bind(&SystemClockClientImpl::ProxyAvailabilityChanged,
69 weak_ptr_factory_.GetWeakPtr()));
73 } 70 }
74 71
75 private: 72 private:
73 void ProxyAvailabilityChanged(bool service_is_available) {
Daniel Erat 2016/08/11 01:15:46 i should rename this and change the code. this is
michaelpg 2016/08/11 03:21:08 what would make the service unavailable after the
74 VLOG(1) << "D-Bus proxy is " << (service_is_available ? "" : "un")
75 << "available";
76
77 if (service_is_available) {
78 GetCanSet();
79 } else if (can_set_time_) {
80 can_set_time_ = false;
81 FOR_EACH_OBSERVER(Observer, observers_,
82 SystemClockCanSetTimeChanged(can_set_time_));
83 }
84 }
85
76 // Called when a TimeUpdated signal is received. 86 // Called when a TimeUpdated signal is received.
77 void TimeUpdatedReceived(dbus::Signal* signal) { 87 void TimeUpdatedReceived(dbus::Signal* signal) {
78 VLOG(1) << "TimeUpdated signal received: " << signal->ToString(); 88 VLOG(1) << "TimeUpdated signal received: " << signal->ToString();
79 dbus::MessageReader reader(signal); 89 dbus::MessageReader reader(signal);
80 FOR_EACH_OBSERVER(Observer, observers_, SystemClockUpdated()); 90 FOR_EACH_OBSERVER(Observer, observers_, SystemClockUpdated());
81 91
82 // Check if the system clock can be changed now. 92 // Check if the system clock can be changed now.
83 GetCanSet(); 93 GetCanSet();
84 } 94 }
85 95
(...skipping 12 matching lines...) Expand all
98 return; 108 return;
99 } 109 }
100 110
101 dbus::MessageReader reader(response); 111 dbus::MessageReader reader(response);
102 bool can_set_time; 112 bool can_set_time;
103 if (!reader.PopBool(&can_set_time)) { 113 if (!reader.PopBool(&can_set_time)) {
104 LOG(ERROR) << "CanSetTime response invalid: " << response->ToString(); 114 LOG(ERROR) << "CanSetTime response invalid: " << response->ToString();
105 return; 115 return;
106 } 116 }
107 117
108 // Nothing to do if the CanSetTime response hasn't changed. 118 if (can_set_time_ != can_set_time) {
109 if (can_set_time_initialized_ && can_set_time_ == can_set_time) 119 can_set_time_ = can_set_time;
110 return; 120 FOR_EACH_OBSERVER(Observer, observers_,
111 121 SystemClockCanSetTimeChanged(can_set_time));
112 can_set_time_initialized_ = true; 122 }
113 can_set_time_ = can_set_time;
114
115 FOR_EACH_OBSERVER(
116 Observer, observers_, SystemClockCanSetTimeChanged(can_set_time));
117 } 123 }
118 124
119 // Check whether the time can be set. 125 // Check whether the time can be set.
120 void GetCanSet() { 126 void GetCanSet() {
121 dbus::MethodCall method_call(system_clock::kSystemClockInterface, 127 dbus::MethodCall method_call(system_clock::kSystemClockInterface,
122 system_clock::kSystemClockCanSet); 128 system_clock::kSystemClockCanSet);
123 dbus::MessageWriter writer(&method_call); 129 dbus::MessageWriter writer(&method_call);
124 system_clock_proxy_->CallMethod( 130 system_clock_proxy_->CallMethod(
125 &method_call, 131 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
126 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
127 base::Bind(&SystemClockClientImpl::OnGetCanSet, 132 base::Bind(&SystemClockClientImpl::OnGetCanSet,
128 weak_ptr_factory_.GetWeakPtr())); 133 weak_ptr_factory_.GetWeakPtr()));
129 } 134 }
130 135
131 // Whether the time can be set. Value is false until the first 136 // Whether the time can be set. Value is false until the first
132 // CanSetTime response is received. 137 // CanSetTime response is received.
133 bool can_set_time_; 138 bool can_set_time_;
134 bool can_set_time_initialized_;
135 dbus::ObjectProxy* system_clock_proxy_; 139 dbus::ObjectProxy* system_clock_proxy_;
136 base::ObserverList<Observer> observers_; 140 base::ObserverList<Observer> observers_;
137 141
138 base::WeakPtrFactory<SystemClockClientImpl> weak_ptr_factory_; 142 base::WeakPtrFactory<SystemClockClientImpl> weak_ptr_factory_;
139 143
140 DISALLOW_COPY_AND_ASSIGN(SystemClockClientImpl); 144 DISALLOW_COPY_AND_ASSIGN(SystemClockClientImpl);
141 }; 145 };
142 146
143 void SystemClockClient::Observer::SystemClockUpdated() {
144 }
145
146 void SystemClockClient::Observer::SystemClockCanSetTimeChanged(
147 bool can_set_time) {
148 }
149
150 SystemClockClient::SystemClockClient() {
151 }
152
153 SystemClockClient::~SystemClockClient() {
154 }
155
156 // static 147 // static
157 SystemClockClient* SystemClockClient::Create() { 148 SystemClockClient* SystemClockClient::Create() {
158 return new SystemClockClientImpl(); 149 return new SystemClockClientImpl();
159 } 150 }
160 151
152 SystemClockClient::SystemClockClient() {}
153
161 } // namespace chromeos 154 } // 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