Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/session_manager_client.h" | 5 #include "chromeos/dbus/session_manager_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/metrics/histogram.h" | |
| 9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 10 #include "dbus/bus.h" | 11 #include "dbus/bus.h" |
| 11 #include "dbus/message.h" | 12 #include "dbus/message.h" |
| 12 #include "dbus/object_path.h" | 13 #include "dbus/object_path.h" |
| 13 #include "dbus/object_proxy.h" | 14 #include "dbus/object_proxy.h" |
| 14 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 15 | 16 |
| 16 namespace chromeos { | 17 namespace chromeos { |
| 17 | 18 |
| 18 // The SessionManagerClient implementation used in production. | 19 // The SessionManagerClient implementation used in production. |
| 19 class SessionManagerClientImpl : public SessionManagerClient { | 20 class SessionManagerClientImpl : public SessionManagerClient { |
| 20 public: | 21 public: |
| 22 enum LockScreensState { | |
|
Daniel Erat
2012/07/03 22:44:27
Rob, are these metrics still useful? If not, I ca
flackr
2012/07/04 12:55:52
We still have to get lid and idle notifications fr
Daniel Erat
2012/07/09 16:01:42
Screen locking can be initiated by either Chrome o
flackr
2012/07/09 18:19:57
Thanks for clarifying, I don't think the current m
| |
| 23 LOCK_SCREEN_REQUESTED, // Lock screen is requested. | |
| 24 LOCK_SCREEN_REQUEST_SUCCEEDED, // Method call succeeded. | |
| 25 LOCK_SCREEN_REQUEST_FAILED, // Method call failed. | |
| 26 LOCK_SCREEN_FINISHED, // Signal is received. | |
| 27 NUM_LOCK_SCREEN_STATES | |
| 28 }; | |
| 29 | |
| 30 enum UnlockScreensState { | |
| 31 UNLOCK_SCREEN_REQUESTED, // Unlock screen is requested. | |
| 32 UNLOCK_SCREEN_REQUEST_SUCCEEDED, // Method call succeeded. | |
| 33 UNLOCK_SCREEN_REQUEST_FAILED, // Method call failed. | |
| 34 UNLOCK_SCREEN_FINISHED, // Signal is received. | |
| 35 NUM_UNLOCK_SCREEN_STATES | |
| 36 }; | |
| 37 | |
| 21 explicit SessionManagerClientImpl(dbus::Bus* bus) | 38 explicit SessionManagerClientImpl(dbus::Bus* bus) |
| 22 : session_manager_proxy_(NULL), | 39 : session_manager_proxy_(NULL), |
| 40 screen_locked_(false), | |
| 23 weak_ptr_factory_(this) { | 41 weak_ptr_factory_(this) { |
| 24 session_manager_proxy_ = bus->GetObjectProxy( | 42 session_manager_proxy_ = bus->GetObjectProxy( |
| 25 login_manager::kSessionManagerServiceName, | 43 login_manager::kSessionManagerServiceName, |
| 26 dbus::ObjectPath(login_manager::kSessionManagerServicePath)); | 44 dbus::ObjectPath(login_manager::kSessionManagerServicePath)); |
| 27 | 45 |
| 28 // Monitor the D-Bus signal for owner key changes. | |
| 29 session_manager_proxy_->ConnectToSignal( | 46 session_manager_proxy_->ConnectToSignal( |
| 30 chromium::kChromiumInterface, | 47 chromium::kChromiumInterface, |
| 31 chromium::kOwnerKeySetSignal, | 48 chromium::kOwnerKeySetSignal, |
| 32 base::Bind(&SessionManagerClientImpl::OwnerKeySetReceived, | 49 base::Bind(&SessionManagerClientImpl::OwnerKeySetReceived, |
| 33 weak_ptr_factory_.GetWeakPtr()), | 50 weak_ptr_factory_.GetWeakPtr()), |
| 34 base::Bind(&SessionManagerClientImpl::SignalConnected, | 51 base::Bind(&SessionManagerClientImpl::SignalConnected, |
| 35 weak_ptr_factory_.GetWeakPtr())); | 52 weak_ptr_factory_.GetWeakPtr())); |
| 36 | 53 |
| 37 // Monitor the D-Bus signal for property changes. | |
| 38 session_manager_proxy_->ConnectToSignal( | 54 session_manager_proxy_->ConnectToSignal( |
| 39 chromium::kChromiumInterface, | 55 chromium::kChromiumInterface, |
| 40 chromium::kPropertyChangeCompleteSignal, | 56 chromium::kPropertyChangeCompleteSignal, |
| 41 base::Bind(&SessionManagerClientImpl::PropertyChangeCompleteReceived, | 57 base::Bind(&SessionManagerClientImpl::PropertyChangeCompleteReceived, |
| 42 weak_ptr_factory_.GetWeakPtr()), | 58 weak_ptr_factory_.GetWeakPtr()), |
| 43 base::Bind(&SessionManagerClientImpl::SignalConnected, | 59 base::Bind(&SessionManagerClientImpl::SignalConnected, |
| 44 weak_ptr_factory_.GetWeakPtr())); | 60 weak_ptr_factory_.GetWeakPtr())); |
| 61 | |
| 62 session_manager_proxy_->ConnectToSignal( | |
| 63 chromium::kChromiumInterface, | |
| 64 chromium::kLockScreenSignal, | |
| 65 base::Bind(&SessionManagerClientImpl::ScreenLockReceived, | |
| 66 weak_ptr_factory_.GetWeakPtr()), | |
| 67 base::Bind(&SessionManagerClientImpl::SignalConnected, | |
| 68 weak_ptr_factory_.GetWeakPtr())); | |
| 69 | |
| 70 session_manager_proxy_->ConnectToSignal( | |
| 71 chromium::kChromiumInterface, | |
| 72 chromium::kUnlockScreenSignal, | |
| 73 base::Bind(&SessionManagerClientImpl::ScreenUnlockReceived, | |
| 74 weak_ptr_factory_.GetWeakPtr()), | |
| 75 base::Bind(&SessionManagerClientImpl::SignalConnected, | |
| 76 weak_ptr_factory_.GetWeakPtr())); | |
| 45 } | 77 } |
| 46 | 78 |
| 47 virtual ~SessionManagerClientImpl() { | 79 virtual ~SessionManagerClientImpl() { |
| 48 } | 80 } |
| 49 | 81 |
| 50 // SessionManagerClient override. | 82 // SessionManagerClient overrides: |
| 51 virtual void AddObserver(Observer* observer) OVERRIDE { | 83 virtual void AddObserver(Observer* observer) OVERRIDE { |
| 52 observers_.AddObserver(observer); | 84 observers_.AddObserver(observer); |
| 53 } | 85 } |
| 54 | 86 |
| 55 // SessionManagerClient override. | |
| 56 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 87 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
| 57 observers_.RemoveObserver(observer); | 88 observers_.RemoveObserver(observer); |
| 58 } | 89 } |
| 59 | 90 |
| 60 // SessionManagerClient override. | 91 virtual bool HasObserver(Observer* observer) OVERRIDE { |
| 61 virtual void EmitLoginPromptReady() OVERRIDE { | 92 return observers_.HasObserver(observer); |
| 62 dbus::MethodCall method_call( | |
| 63 login_manager::kSessionManagerInterface, | |
| 64 login_manager::kSessionManagerEmitLoginPromptReady); | |
| 65 session_manager_proxy_->CallMethod( | |
| 66 &method_call, | |
| 67 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 68 base::Bind(&SessionManagerClientImpl::OnEmitLoginPromptReady, | |
| 69 weak_ptr_factory_.GetWeakPtr())); | |
| 70 } | 93 } |
| 71 | 94 |
| 72 // SessionManagerClient override. | 95 virtual void EmitLoginPromptReady() OVERRIDE { |
| 73 virtual void EmitLoginPromptVisible() OVERRIDE { | 96 SimpleMethodCallToSessionManager( |
| 74 dbus::MethodCall method_call( | 97 login_manager::kSessionManagerEmitLoginPromptReady); |
| 75 login_manager::kSessionManagerInterface, | |
| 76 login_manager::kSessionManagerEmitLoginPromptVisible); | |
| 77 session_manager_proxy_->CallMethod( | |
| 78 &method_call, | |
| 79 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 80 base::Bind(&SessionManagerClientImpl::OnEmitLoginPromptVisible, | |
| 81 weak_ptr_factory_.GetWeakPtr())); | |
| 82 } | 98 } |
| 83 | 99 |
| 84 // SessionManagerClient override. | 100 virtual void EmitLoginPromptVisible() OVERRIDE { |
| 101 SimpleMethodCallToSessionManager( | |
| 102 login_manager::kSessionManagerEmitLoginPromptVisible); | |
| 103 } | |
| 104 | |
| 85 virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE { | 105 virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE { |
| 86 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 106 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 87 login_manager::kSessionManagerRestartJob); | 107 login_manager::kSessionManagerRestartJob); |
| 88 dbus::MessageWriter writer(&method_call); | 108 dbus::MessageWriter writer(&method_call); |
| 89 writer.AppendInt32(pid); | 109 writer.AppendInt32(pid); |
| 90 writer.AppendString(command_line); | 110 writer.AppendString(command_line); |
| 91 session_manager_proxy_->CallMethod( | 111 session_manager_proxy_->CallMethod( |
| 92 &method_call, | 112 &method_call, |
| 93 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 113 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 94 base::Bind(&SessionManagerClientImpl::OnRestartJob, | 114 base::Bind(&SessionManagerClientImpl::OnRestartJob, |
| 95 weak_ptr_factory_.GetWeakPtr())); | 115 weak_ptr_factory_.GetWeakPtr())); |
| 96 } | 116 } |
| 97 | 117 |
| 98 // SessionManagerClient override. | |
| 99 virtual void RestartEntd() OVERRIDE { | 118 virtual void RestartEntd() OVERRIDE { |
| 100 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 119 SimpleMethodCallToSessionManager(login_manager::kSessionManagerRestartEntd); |
| 101 login_manager::kSessionManagerRestartEntd); | |
| 102 session_manager_proxy_->CallMethod( | |
| 103 &method_call, | |
| 104 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 105 base::Bind(&SessionManagerClientImpl::OnRestartEntd, | |
| 106 weak_ptr_factory_.GetWeakPtr())); | |
| 107 } | 120 } |
| 108 | 121 |
| 109 // SessionManagerClient override. | |
| 110 virtual void StartSession(const std::string& user_email) OVERRIDE { | 122 virtual void StartSession(const std::string& user_email) OVERRIDE { |
| 111 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 123 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 112 login_manager::kSessionManagerStartSession); | 124 login_manager::kSessionManagerStartSession); |
| 113 dbus::MessageWriter writer(&method_call); | 125 dbus::MessageWriter writer(&method_call); |
| 114 writer.AppendString(user_email); | 126 writer.AppendString(user_email); |
| 115 writer.AppendString(""); // Unique ID is deprecated | 127 writer.AppendString(""); // Unique ID is deprecated |
| 116 session_manager_proxy_->CallMethod( | 128 session_manager_proxy_->CallMethod( |
| 117 &method_call, | 129 &method_call, |
| 118 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 130 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 119 base::Bind(&SessionManagerClientImpl::OnStartSession, | 131 base::Bind(&SessionManagerClientImpl::OnStartSession, |
| 120 weak_ptr_factory_.GetWeakPtr())); | 132 weak_ptr_factory_.GetWeakPtr())); |
| 121 } | 133 } |
| 122 | 134 |
| 123 // SessionManagerClient override. | |
| 124 virtual void StopSession() OVERRIDE { | 135 virtual void StopSession() OVERRIDE { |
| 125 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 136 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 126 login_manager::kSessionManagerStopSession); | 137 login_manager::kSessionManagerStopSession); |
| 127 dbus::MessageWriter writer(&method_call); | 138 dbus::MessageWriter writer(&method_call); |
| 128 writer.AppendString(""); // Unique ID is deprecated | 139 writer.AppendString(""); // Unique ID is deprecated |
| 129 session_manager_proxy_->CallMethod( | 140 session_manager_proxy_->CallMethod( |
| 130 &method_call, | 141 &method_call, |
| 131 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 142 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 132 base::Bind(&SessionManagerClientImpl::OnStopSession, | 143 base::Bind(&SessionManagerClientImpl::OnStopSession, |
| 133 weak_ptr_factory_.GetWeakPtr())); | 144 weak_ptr_factory_.GetWeakPtr())); |
| 134 } | 145 } |
| 135 | 146 |
| 136 // SessionManagerClient override. | 147 virtual void RequestLockScreen() OVERRIDE { |
| 148 UMA_HISTOGRAM_ENUMERATION("LockScreen.LockScreenPath", | |
| 149 LOCK_SCREEN_REQUESTED, | |
| 150 NUM_LOCK_SCREEN_STATES); | |
| 151 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | |
| 152 login_manager::kSessionManagerLockScreen); | |
| 153 session_manager_proxy_->CallMethodWithErrorCallback( | |
| 154 &method_call, | |
| 155 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 156 base::Bind(&SessionManagerClientImpl::OnRequestLockScreenSuccess, | |
| 157 weak_ptr_factory_.GetWeakPtr()), | |
| 158 base::Bind(&SessionManagerClientImpl::OnRequestLockScreenError, | |
| 159 weak_ptr_factory_.GetWeakPtr())); | |
| 160 } | |
| 161 | |
| 162 virtual void RequestUnlockScreen() OVERRIDE { | |
| 163 UMA_HISTOGRAM_ENUMERATION("LockScreen.UnlockScreenPath", | |
| 164 UNLOCK_SCREEN_REQUESTED, | |
| 165 NUM_UNLOCK_SCREEN_STATES); | |
| 166 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | |
| 167 login_manager::kSessionManagerUnlockScreen); | |
| 168 session_manager_proxy_->CallMethodWithErrorCallback( | |
| 169 &method_call, | |
| 170 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 171 base::Bind(&SessionManagerClientImpl::OnRequestUnlockScreenSuccess, | |
| 172 weak_ptr_factory_.GetWeakPtr()), | |
| 173 base::Bind(&SessionManagerClientImpl::OnRequestUnlockScreenError, | |
| 174 weak_ptr_factory_.GetWeakPtr())); | |
| 175 } | |
| 176 | |
| 177 virtual bool GetIsScreenLocked() OVERRIDE { | |
| 178 return screen_locked_; | |
| 179 } | |
| 180 | |
| 137 virtual void RetrieveDevicePolicy( | 181 virtual void RetrieveDevicePolicy( |
| 138 const RetrievePolicyCallback& callback) OVERRIDE { | 182 const RetrievePolicyCallback& callback) OVERRIDE { |
| 139 CallRetrievePolicy(login_manager::kSessionManagerRetrievePolicy, | 183 CallRetrievePolicy(login_manager::kSessionManagerRetrievePolicy, |
| 140 callback); | 184 callback); |
| 141 } | 185 } |
| 142 | 186 |
| 143 // SessionManagerClient override. | |
| 144 virtual void RetrieveUserPolicy( | 187 virtual void RetrieveUserPolicy( |
| 145 const RetrievePolicyCallback& callback) OVERRIDE { | 188 const RetrievePolicyCallback& callback) OVERRIDE { |
| 146 CallRetrievePolicy(login_manager::kSessionManagerRetrieveUserPolicy, | 189 CallRetrievePolicy(login_manager::kSessionManagerRetrieveUserPolicy, |
| 147 callback); | 190 callback); |
| 148 } | 191 } |
| 149 | 192 |
| 150 // SessionManagerClient override. | |
| 151 virtual void StoreDevicePolicy(const std::string& policy_blob, | 193 virtual void StoreDevicePolicy(const std::string& policy_blob, |
| 152 const StorePolicyCallback& callback) OVERRIDE { | 194 const StorePolicyCallback& callback) OVERRIDE { |
| 153 CallStorePolicy(login_manager::kSessionManagerStorePolicy, | 195 CallStorePolicy(login_manager::kSessionManagerStorePolicy, |
| 154 policy_blob, callback); | 196 policy_blob, callback); |
| 155 } | 197 } |
| 156 | 198 |
| 157 // SessionManagerClient override. | |
| 158 virtual void StoreUserPolicy(const std::string& policy_blob, | 199 virtual void StoreUserPolicy(const std::string& policy_blob, |
| 159 const StorePolicyCallback& callback) OVERRIDE { | 200 const StorePolicyCallback& callback) OVERRIDE { |
| 160 CallStorePolicy(login_manager::kSessionManagerStoreUserPolicy, | 201 CallStorePolicy(login_manager::kSessionManagerStoreUserPolicy, |
| 161 policy_blob, callback); | 202 policy_blob, callback); |
| 162 } | 203 } |
| 163 | 204 |
| 164 private: | 205 private: |
| 206 // Makes a method call to the session manager with no arguments and no | |
| 207 // response. | |
| 208 void SimpleMethodCallToSessionManager(const std::string& method_name) { | |
| 209 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | |
| 210 method_name); | |
| 211 session_manager_proxy_->CallMethod( | |
| 212 &method_call, | |
| 213 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 214 dbus::ObjectProxy::EmptyResponseCallback()); | |
| 215 } | |
| 216 | |
| 165 // Helper for Retrieve{User,Device}Policy. | 217 // Helper for Retrieve{User,Device}Policy. |
| 166 virtual void CallRetrievePolicy(const std::string& method_name, | 218 virtual void CallRetrievePolicy(const std::string& method_name, |
| 167 const RetrievePolicyCallback& callback) { | 219 const RetrievePolicyCallback& callback) { |
| 168 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 220 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 169 method_name); | 221 method_name); |
| 170 session_manager_proxy_->CallMethod( | 222 session_manager_proxy_->CallMethod( |
| 171 &method_call, | 223 &method_call, |
| 172 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 224 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 173 base::Bind(&SessionManagerClientImpl::OnRetrievePolicy, | 225 base::Bind(&SessionManagerClientImpl::OnRetrievePolicy, |
| 174 weak_ptr_factory_.GetWeakPtr(), | 226 weak_ptr_factory_.GetWeakPtr(), |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 188 reinterpret_cast<const uint8*>(policy_blob.data()), policy_blob.size()); | 240 reinterpret_cast<const uint8*>(policy_blob.data()), policy_blob.size()); |
| 189 session_manager_proxy_->CallMethod( | 241 session_manager_proxy_->CallMethod( |
| 190 &method_call, | 242 &method_call, |
| 191 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 243 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 192 base::Bind(&SessionManagerClientImpl::OnStorePolicy, | 244 base::Bind(&SessionManagerClientImpl::OnStorePolicy, |
| 193 weak_ptr_factory_.GetWeakPtr(), | 245 weak_ptr_factory_.GetWeakPtr(), |
| 194 method_name, | 246 method_name, |
| 195 callback)); | 247 callback)); |
| 196 } | 248 } |
| 197 | 249 |
| 198 // Called when kSessionManagerEmitLoginPromptReady method is complete. | |
| 199 void OnEmitLoginPromptReady(dbus::Response* response) { | |
| 200 LOG_IF(ERROR, !response) | |
| 201 << "Failed to call " | |
| 202 << login_manager::kSessionManagerEmitLoginPromptReady; | |
| 203 } | |
| 204 | |
| 205 // Called when kSessionManagerEmitLoginPromptVisible method is complete. | |
| 206 void OnEmitLoginPromptVisible(dbus::Response* response) { | |
| 207 LOG_IF(ERROR, !response) | |
| 208 << "Failed to call " | |
| 209 << login_manager::kSessionManagerEmitLoginPromptVisible; | |
| 210 } | |
| 211 | |
| 212 // Called when kSessionManagerRestartJob method is complete. | 250 // Called when kSessionManagerRestartJob method is complete. |
| 213 void OnRestartJob(dbus::Response* response) { | 251 void OnRestartJob(dbus::Response* response) { |
| 214 LOG_IF(ERROR, !response) | 252 LOG_IF(ERROR, !response) |
| 215 << "Failed to call " | 253 << "Failed to call " |
| 216 << login_manager::kSessionManagerRestartJob; | 254 << login_manager::kSessionManagerRestartJob; |
| 217 } | 255 } |
| 218 | 256 |
| 219 // Called when kSessionManagerRestartEntd method is complete. | |
| 220 void OnRestartEntd(dbus::Response* response) { | |
| 221 LOG_IF(ERROR, !response) | |
| 222 << "Failed to call " | |
| 223 << login_manager::kSessionManagerRestartEntd; | |
| 224 } | |
| 225 | |
| 226 // Called when kSessionManagerStartSession method is complete. | 257 // Called when kSessionManagerStartSession method is complete. |
| 227 void OnStartSession(dbus::Response* response) { | 258 void OnStartSession(dbus::Response* response) { |
| 228 LOG_IF(ERROR, !response) | 259 LOG_IF(ERROR, !response) |
| 229 << "Failed to call " | 260 << "Failed to call " |
| 230 << login_manager::kSessionManagerStartSession; | 261 << login_manager::kSessionManagerStartSession; |
| 231 } | 262 } |
| 232 | 263 |
| 233 // Called when kSessionManagerStopSession method is complete. | 264 // Called when kSessionManagerStopSession method is complete. |
| 234 void OnStopSession(dbus::Response* response) { | 265 void OnStopSession(dbus::Response* response) { |
| 235 LOG_IF(ERROR, !response) | 266 LOG_IF(ERROR, !response) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 dbus::MessageReader reader(signal); | 324 dbus::MessageReader reader(signal); |
| 294 std::string result_string; | 325 std::string result_string; |
| 295 if (!reader.PopString(&result_string)) { | 326 if (!reader.PopString(&result_string)) { |
| 296 LOG(ERROR) << "Invalid signal: " << signal->ToString(); | 327 LOG(ERROR) << "Invalid signal: " << signal->ToString(); |
| 297 return; | 328 return; |
| 298 } | 329 } |
| 299 const bool success = StartsWithASCII(result_string, "success", false); | 330 const bool success = StartsWithASCII(result_string, "success", false); |
| 300 FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(success)); | 331 FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(success)); |
| 301 } | 332 } |
| 302 | 333 |
| 334 void ScreenLockReceived(dbus::Signal* signal) { | |
| 335 // TODO(flackr): This warning is actually a signal that things are working | |
| 336 // as expected. As per http://crbug.com/126217, this will help determine | |
| 337 // if the problem is with dbus or in chrome. | |
| 338 LOG(WARNING) << "LockScreen signal received from session manager."; | |
| 339 screen_locked_ = true; | |
| 340 UMA_HISTOGRAM_ENUMERATION("LockScreen.LockScreenPath", | |
| 341 LOCK_SCREEN_FINISHED, | |
| 342 NUM_LOCK_SCREEN_STATES); | |
| 343 FOR_EACH_OBSERVER(Observer, observers_, LockScreen()); | |
| 344 } | |
| 345 | |
| 346 void ScreenUnlockReceived(dbus::Signal* signal) { | |
| 347 screen_locked_ = false; | |
| 348 UMA_HISTOGRAM_ENUMERATION("LockScreen.UnlockScreenPath", | |
| 349 UNLOCK_SCREEN_FINISHED, | |
| 350 NUM_UNLOCK_SCREEN_STATES); | |
| 351 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); | |
| 352 } | |
| 353 | |
| 354 | |
| 303 // Called when the object is connected to the signal. | 355 // Called when the object is connected to the signal. |
| 304 void SignalConnected(const std::string& interface_name, | 356 void SignalConnected(const std::string& interface_name, |
| 305 const std::string& signal_name, | 357 const std::string& signal_name, |
| 306 bool success) { | 358 bool success) { |
| 307 LOG_IF(ERROR, !success) << "Failed to connect to " << signal_name; | 359 LOG_IF(ERROR, !success) << "Failed to connect to " << signal_name; |
| 308 } | 360 } |
| 309 | 361 |
| 362 void OnRequestLockScreenSuccess(dbus::Response* response) { | |
| 363 UMA_HISTOGRAM_ENUMERATION("LockScreen.LockScreenPath", | |
| 364 LOCK_SCREEN_REQUEST_SUCCEEDED, | |
| 365 NUM_LOCK_SCREEN_STATES); | |
| 366 } | |
| 367 | |
| 368 void OnRequestLockScreenError(dbus::ErrorResponse* error_response) { | |
| 369 if (error_response) { | |
| 370 dbus::MessageReader reader(error_response); | |
| 371 std::string error_message; | |
| 372 reader.PopString(&error_message); | |
| 373 LOG(ERROR) << "Failed to call " | |
| 374 << login_manager::kSessionManagerLockScreen | |
| 375 << error_response->GetErrorName() | |
| 376 << ": " << error_message; | |
| 377 } | |
| 378 UMA_HISTOGRAM_ENUMERATION("LockScreen.LockScreenPath", | |
| 379 LOCK_SCREEN_REQUEST_FAILED, | |
| 380 NUM_LOCK_SCREEN_STATES); | |
| 381 } | |
| 382 | |
| 383 void OnRequestUnlockScreenSuccess(dbus::Response* response) { | |
| 384 UMA_HISTOGRAM_ENUMERATION("LockScreen.UnlockScreenPath", | |
| 385 UNLOCK_SCREEN_REQUEST_SUCCEEDED, | |
| 386 NUM_UNLOCK_SCREEN_STATES); | |
| 387 } | |
| 388 | |
| 389 void OnRequestUnlockScreenError(dbus::ErrorResponse* error_response) { | |
| 390 if (error_response) { | |
| 391 dbus::MessageReader reader(error_response); | |
| 392 std::string error_message; | |
| 393 reader.PopString(&error_message); | |
| 394 LOG(ERROR) << "Failed to call " | |
| 395 << login_manager::kSessionManagerUnlockScreen | |
| 396 << error_response->GetErrorName() | |
| 397 << ": " << error_message; | |
| 398 } | |
| 399 UMA_HISTOGRAM_ENUMERATION("LockScreen.UnlockScreenPath", | |
| 400 UNLOCK_SCREEN_REQUEST_FAILED, | |
| 401 NUM_UNLOCK_SCREEN_STATES); | |
| 402 } | |
| 403 | |
| 310 dbus::ObjectProxy* session_manager_proxy_; | 404 dbus::ObjectProxy* session_manager_proxy_; |
| 311 ObserverList<Observer> observers_; | 405 ObserverList<Observer> observers_; |
| 406 bool screen_locked_; | |
| 312 base::WeakPtrFactory<SessionManagerClientImpl> weak_ptr_factory_; | 407 base::WeakPtrFactory<SessionManagerClientImpl> weak_ptr_factory_; |
| 313 | 408 |
| 314 DISALLOW_COPY_AND_ASSIGN(SessionManagerClientImpl); | 409 DISALLOW_COPY_AND_ASSIGN(SessionManagerClientImpl); |
| 315 }; | 410 }; |
| 316 | 411 |
| 317 // The SessionManagerClient implementation used on Linux desktop, | 412 // The SessionManagerClient implementation used on Linux desktop, |
| 318 // which does nothing. | 413 // which does nothing. |
| 319 class SessionManagerClientStubImpl : public SessionManagerClient { | 414 class SessionManagerClientStubImpl : public SessionManagerClient { |
| 320 // SessionManagerClient overrides. | 415 // SessionManagerClient overrides. |
| 321 virtual void AddObserver(Observer* observer) OVERRIDE {} | 416 virtual void AddObserver(Observer* observer) OVERRIDE {} |
| 322 virtual void RemoveObserver(Observer* observer) OVERRIDE {} | 417 virtual void RemoveObserver(Observer* observer) OVERRIDE {} |
| 418 virtual bool HasObserver(Observer* observer) OVERRIDE { return false; } | |
| 323 virtual void EmitLoginPromptReady() OVERRIDE {} | 419 virtual void EmitLoginPromptReady() OVERRIDE {} |
| 324 virtual void EmitLoginPromptVisible() OVERRIDE {} | 420 virtual void EmitLoginPromptVisible() OVERRIDE {} |
| 325 virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE {} | 421 virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE {} |
| 326 virtual void RestartEntd() OVERRIDE {} | 422 virtual void RestartEntd() OVERRIDE {} |
| 327 virtual void StartSession(const std::string& user_email) OVERRIDE {} | 423 virtual void StartSession(const std::string& user_email) OVERRIDE {} |
| 328 virtual void StopSession() OVERRIDE {} | 424 virtual void StopSession() OVERRIDE {} |
| 425 virtual void RequestLockScreen() OVERRIDE {} | |
| 426 virtual void RequestUnlockScreen() OVERRIDE {} | |
| 427 virtual bool GetIsScreenLocked() OVERRIDE { return false; } | |
| 329 virtual void RetrieveDevicePolicy( | 428 virtual void RetrieveDevicePolicy( |
| 330 const RetrievePolicyCallback& callback) OVERRIDE { | 429 const RetrievePolicyCallback& callback) OVERRIDE { |
| 331 callback.Run(""); | 430 callback.Run(""); |
| 332 } | 431 } |
| 333 virtual void RetrieveUserPolicy( | 432 virtual void RetrieveUserPolicy( |
| 334 const RetrievePolicyCallback& callback) OVERRIDE { | 433 const RetrievePolicyCallback& callback) OVERRIDE { |
| 335 callback.Run(""); | 434 callback.Run(""); |
| 336 } | 435 } |
| 337 virtual void StoreDevicePolicy(const std::string& policy_blob, | 436 virtual void StoreDevicePolicy(const std::string& policy_blob, |
| 338 const StorePolicyCallback& callback) OVERRIDE { | 437 const StorePolicyCallback& callback) OVERRIDE { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 353 SessionManagerClient* SessionManagerClient::Create( | 452 SessionManagerClient* SessionManagerClient::Create( |
| 354 DBusClientImplementationType type, | 453 DBusClientImplementationType type, |
| 355 dbus::Bus* bus) { | 454 dbus::Bus* bus) { |
| 356 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 455 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 357 return new SessionManagerClientImpl(bus); | 456 return new SessionManagerClientImpl(bus); |
| 358 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 457 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 359 return new SessionManagerClientStubImpl(); | 458 return new SessionManagerClientStubImpl(); |
| 360 } | 459 } |
| 361 | 460 |
| 362 } // namespace chromeos | 461 } // namespace chromeos |
| OLD | NEW |