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 <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 class SessionManagerClientImpl : public SessionManagerClient { | 29 class SessionManagerClientImpl : public SessionManagerClient { |
30 public: | 30 public: |
31 SessionManagerClientImpl() | 31 SessionManagerClientImpl() |
32 : session_manager_proxy_(NULL), | 32 : session_manager_proxy_(NULL), |
33 weak_ptr_factory_(this) {} | 33 weak_ptr_factory_(this) {} |
34 | 34 |
35 virtual ~SessionManagerClientImpl() { | 35 virtual ~SessionManagerClientImpl() { |
36 } | 36 } |
37 | 37 |
38 // SessionManagerClient overrides: | 38 // SessionManagerClient overrides: |
| 39 virtual void SetStubDelegate(StubDelegate* delegate) OVERRIDE { |
| 40 // Do nothing; this isn't a stub implementation. |
| 41 } |
| 42 |
39 virtual void AddObserver(Observer* observer) OVERRIDE { | 43 virtual void AddObserver(Observer* observer) OVERRIDE { |
40 observers_.AddObserver(observer); | 44 observers_.AddObserver(observer); |
41 } | 45 } |
42 | 46 |
43 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 47 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
44 observers_.RemoveObserver(observer); | 48 observers_.RemoveObserver(observer); |
45 } | 49 } |
46 | 50 |
47 virtual bool HasObserver(Observer* observer) OVERRIDE { | 51 virtual bool HasObserver(Observer* observer) OVERRIDE { |
48 return observers_.HasObserver(observer); | 52 return observers_.HasObserver(observer); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 235 } |
232 | 236 |
233 protected: | 237 protected: |
234 virtual void Init(dbus::Bus* bus) OVERRIDE { | 238 virtual void Init(dbus::Bus* bus) OVERRIDE { |
235 session_manager_proxy_ = bus->GetObjectProxy( | 239 session_manager_proxy_ = bus->GetObjectProxy( |
236 login_manager::kSessionManagerServiceName, | 240 login_manager::kSessionManagerServiceName, |
237 dbus::ObjectPath(login_manager::kSessionManagerServicePath)); | 241 dbus::ObjectPath(login_manager::kSessionManagerServicePath)); |
238 blocking_method_caller_.reset( | 242 blocking_method_caller_.reset( |
239 new BlockingMethodCaller(bus, session_manager_proxy_)); | 243 new BlockingMethodCaller(bus, session_manager_proxy_)); |
240 | 244 |
241 // Signals emitted on Chromium's interface. Many of these ought to be | |
242 // method calls instead. | |
243 session_manager_proxy_->ConnectToSignal( | |
244 chromium::kChromiumInterface, | |
245 chromium::kLockScreenSignal, | |
246 base::Bind(&SessionManagerClientImpl::ScreenLockReceived, | |
247 weak_ptr_factory_.GetWeakPtr()), | |
248 base::Bind(&SessionManagerClientImpl::SignalConnected, | |
249 weak_ptr_factory_.GetWeakPtr())); | |
250 | |
251 // Signals emitted on the session manager's interface. | 245 // Signals emitted on the session manager's interface. |
252 session_manager_proxy_->ConnectToSignal( | 246 session_manager_proxy_->ConnectToSignal( |
253 login_manager::kSessionManagerInterface, | 247 login_manager::kSessionManagerInterface, |
254 login_manager::kOwnerKeySetSignal, | 248 login_manager::kOwnerKeySetSignal, |
255 base::Bind(&SessionManagerClientImpl::OwnerKeySetReceived, | 249 base::Bind(&SessionManagerClientImpl::OwnerKeySetReceived, |
256 weak_ptr_factory_.GetWeakPtr()), | 250 weak_ptr_factory_.GetWeakPtr()), |
257 base::Bind(&SessionManagerClientImpl::SignalConnected, | 251 base::Bind(&SessionManagerClientImpl::SignalConnected, |
258 weak_ptr_factory_.GetWeakPtr())); | 252 weak_ptr_factory_.GetWeakPtr())); |
259 session_manager_proxy_->ConnectToSignal( | 253 session_manager_proxy_->ConnectToSignal( |
260 login_manager::kSessionManagerInterface, | 254 login_manager::kSessionManagerInterface, |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 dbus::MessageReader reader(signal); | 450 dbus::MessageReader reader(signal); |
457 std::string result_string; | 451 std::string result_string; |
458 if (!reader.PopString(&result_string)) { | 452 if (!reader.PopString(&result_string)) { |
459 LOG(ERROR) << "Invalid signal: " << signal->ToString(); | 453 LOG(ERROR) << "Invalid signal: " << signal->ToString(); |
460 return; | 454 return; |
461 } | 455 } |
462 const bool success = StartsWithASCII(result_string, "success", false); | 456 const bool success = StartsWithASCII(result_string, "success", false); |
463 FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(success)); | 457 FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(success)); |
464 } | 458 } |
465 | 459 |
466 void ScreenLockReceived(dbus::Signal* signal) { | |
467 FOR_EACH_OBSERVER(Observer, observers_, LockScreen()); | |
468 } | |
469 | |
470 void ScreenIsLockedReceived(dbus::Signal* signal) { | 460 void ScreenIsLockedReceived(dbus::Signal* signal) { |
471 FOR_EACH_OBSERVER(Observer, observers_, ScreenIsLocked()); | 461 FOR_EACH_OBSERVER(Observer, observers_, ScreenIsLocked()); |
472 } | 462 } |
473 | 463 |
474 void ScreenIsUnlockedReceived(dbus::Signal* signal) { | 464 void ScreenIsUnlockedReceived(dbus::Signal* signal) { |
475 FOR_EACH_OBSERVER(Observer, observers_, ScreenIsUnlocked()); | 465 FOR_EACH_OBSERVER(Observer, observers_, ScreenIsUnlocked()); |
476 } | 466 } |
477 | 467 |
478 // Called when the object is connected to the signal. | 468 // Called when the object is connected to the signal. |
479 void SignalConnected(const std::string& interface_name, | 469 void SignalConnected(const std::string& interface_name, |
(...skipping 10 matching lines...) Expand all Loading... |
490 // invalidate its weak pointers before any other members are destroyed. | 480 // invalidate its weak pointers before any other members are destroyed. |
491 base::WeakPtrFactory<SessionManagerClientImpl> weak_ptr_factory_; | 481 base::WeakPtrFactory<SessionManagerClientImpl> weak_ptr_factory_; |
492 | 482 |
493 DISALLOW_COPY_AND_ASSIGN(SessionManagerClientImpl); | 483 DISALLOW_COPY_AND_ASSIGN(SessionManagerClientImpl); |
494 }; | 484 }; |
495 | 485 |
496 // The SessionManagerClient implementation used on Linux desktop, | 486 // The SessionManagerClient implementation used on Linux desktop, |
497 // which does nothing. | 487 // which does nothing. |
498 class SessionManagerClientStubImpl : public SessionManagerClient { | 488 class SessionManagerClientStubImpl : public SessionManagerClient { |
499 public: | 489 public: |
500 SessionManagerClientStubImpl() {} | 490 SessionManagerClientStubImpl() : delegate_(NULL) {} |
501 virtual ~SessionManagerClientStubImpl() {} | 491 virtual ~SessionManagerClientStubImpl() {} |
502 | 492 |
503 // SessionManagerClient overrides | 493 // SessionManagerClient overrides |
504 virtual void Init(dbus::Bus* bus) OVERRIDE { | 494 virtual void Init(dbus::Bus* bus) OVERRIDE { |
505 // Make sure that there are no keys left over from a previous browser run. | 495 // Make sure that there are no keys left over from a previous browser run. |
506 base::FilePath user_policy_key_dir; | 496 base::FilePath user_policy_key_dir; |
507 if (PathService::Get(chromeos::DIR_USER_POLICY_KEYS, | 497 if (PathService::Get(chromeos::DIR_USER_POLICY_KEYS, |
508 &user_policy_key_dir)) { | 498 &user_policy_key_dir)) { |
509 base::WorkerPool::PostTask( | 499 base::WorkerPool::PostTask( |
510 FROM_HERE, | 500 FROM_HERE, |
511 base::Bind(base::IgnoreResult(&base::DeleteFile), | 501 base::Bind(base::IgnoreResult(&base::DeleteFile), |
512 user_policy_key_dir, true), | 502 user_policy_key_dir, true), |
513 false); | 503 false); |
514 } | 504 } |
515 } | 505 } |
516 | 506 |
| 507 virtual void SetStubDelegate(StubDelegate* delegate) OVERRIDE { |
| 508 delegate_ = delegate; |
| 509 } |
517 virtual void AddObserver(Observer* observer) OVERRIDE { | 510 virtual void AddObserver(Observer* observer) OVERRIDE { |
518 observers_.AddObserver(observer); | 511 observers_.AddObserver(observer); |
519 } | 512 } |
520 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 513 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
521 observers_.RemoveObserver(observer); | 514 observers_.RemoveObserver(observer); |
522 } | 515 } |
523 virtual bool HasObserver(Observer* observer) OVERRIDE { | 516 virtual bool HasObserver(Observer* observer) OVERRIDE { |
524 return observers_.HasObserver(observer); | 517 return observers_.HasObserver(observer); |
525 } | 518 } |
526 virtual void EmitLoginPromptVisible() OVERRIDE {} | 519 virtual void EmitLoginPromptVisible() OVERRIDE {} |
527 virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE {} | 520 virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE {} |
528 virtual void StartSession(const std::string& user_email) OVERRIDE {} | 521 virtual void StartSession(const std::string& user_email) OVERRIDE {} |
529 virtual void StopSession() OVERRIDE {} | 522 virtual void StopSession() OVERRIDE {} |
530 virtual void StartDeviceWipe() OVERRIDE {} | 523 virtual void StartDeviceWipe() OVERRIDE {} |
531 virtual void RequestLockScreen() OVERRIDE { | 524 virtual void RequestLockScreen() OVERRIDE { |
532 FOR_EACH_OBSERVER(Observer, observers_, LockScreen()); | 525 if (delegate_) |
| 526 delegate_->LockScreenForStub(); |
533 } | 527 } |
534 virtual void NotifyLockScreenShown() OVERRIDE { | 528 virtual void NotifyLockScreenShown() OVERRIDE { |
535 FOR_EACH_OBSERVER(Observer, observers_, ScreenIsLocked()); | 529 FOR_EACH_OBSERVER(Observer, observers_, ScreenIsLocked()); |
536 } | 530 } |
537 virtual void NotifyLockScreenDismissed() OVERRIDE { | 531 virtual void NotifyLockScreenDismissed() OVERRIDE { |
538 FOR_EACH_OBSERVER(Observer, observers_, ScreenIsUnlocked()); | 532 FOR_EACH_OBSERVER(Observer, observers_, ScreenIsUnlocked()); |
539 } | 533 } |
540 virtual void RetrieveActiveSessions( | 534 virtual void RetrieveActiveSessions( |
541 const ActiveSessionsCallback& callback) OVERRIDE {} | 535 const ActiveSessionsCallback& callback) OVERRIDE {} |
542 virtual void RetrieveDevicePolicy( | 536 virtual void RetrieveDevicePolicy( |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 static void StoreFileInBackground(const base::FilePath& path, | 604 static void StoreFileInBackground(const base::FilePath& path, |
611 const std::string& data) { | 605 const std::string& data) { |
612 const int size = static_cast<int>(data.size()); | 606 const int size = static_cast<int>(data.size()); |
613 if (!base::CreateDirectory(path.DirName()) || | 607 if (!base::CreateDirectory(path.DirName()) || |
614 base::WriteFile(path, data.data(), size) != size) { | 608 base::WriteFile(path, data.data(), size) != size) { |
615 LOG(WARNING) << "Failed to write policy key to " << path.value(); | 609 LOG(WARNING) << "Failed to write policy key to " << path.value(); |
616 } | 610 } |
617 } | 611 } |
618 | 612 |
619 private: | 613 private: |
| 614 StubDelegate* delegate_; // Weak pointer; may be NULL. |
620 ObserverList<Observer> observers_; | 615 ObserverList<Observer> observers_; |
621 std::string device_policy_; | 616 std::string device_policy_; |
622 std::map<std::string, std::string> user_policies_; | 617 std::map<std::string, std::string> user_policies_; |
623 | 618 |
624 DISALLOW_COPY_AND_ASSIGN(SessionManagerClientStubImpl); | 619 DISALLOW_COPY_AND_ASSIGN(SessionManagerClientStubImpl); |
625 }; | 620 }; |
626 | 621 |
627 SessionManagerClient::SessionManagerClient() { | 622 SessionManagerClient::SessionManagerClient() { |
628 } | 623 } |
629 | 624 |
630 SessionManagerClient::~SessionManagerClient() { | 625 SessionManagerClient::~SessionManagerClient() { |
631 } | 626 } |
632 | 627 |
633 SessionManagerClient* SessionManagerClient::Create( | 628 SessionManagerClient* SessionManagerClient::Create( |
634 DBusClientImplementationType type) { | 629 DBusClientImplementationType type) { |
635 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 630 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
636 return new SessionManagerClientImpl(); | 631 return new SessionManagerClientImpl(); |
637 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 632 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
638 return new SessionManagerClientStubImpl(); | 633 return new SessionManagerClientStubImpl(); |
639 } | 634 } |
640 | 635 |
641 } // namespace chromeos | 636 } // namespace chromeos |
OLD | NEW |