Home | History | Annotate | Download | only in dbus
      1 // Copyright 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/fake_session_manager_client.h"
      6 
      7 #include "base/bind.h"
      8 #include "base/location.h"
      9 #include "base/message_loop/message_loop.h"
     10 #include "base/strings/string_util.h"
     11 #include "chromeos/dbus/cryptohome_client.h"
     12 
     13 namespace chromeos {
     14 
     15 FakeSessionManagerClient::FakeSessionManagerClient()
     16     : emit_login_prompt_ready_call_count_(0),
     17       start_device_wipe_call_count_(0),
     18       notify_lock_screen_shown_call_count_(0),
     19       notify_lock_screen_dismissed_call_count_(0) {
     20 }
     21 
     22 FakeSessionManagerClient::~FakeSessionManagerClient() {
     23 }
     24 
     25 void FakeSessionManagerClient::Init(dbus::Bus* bus) {
     26 }
     27 
     28 void FakeSessionManagerClient::AddObserver(Observer* observer) {
     29   observers_.AddObserver(observer);
     30 }
     31 
     32 void FakeSessionManagerClient::RemoveObserver(Observer* observer) {
     33   observers_.RemoveObserver(observer);
     34 }
     35 
     36 bool FakeSessionManagerClient::HasObserver(Observer* observer) {
     37   return observers_.HasObserver(observer);
     38 }
     39 
     40 void FakeSessionManagerClient::EmitLoginPromptReady() {
     41   emit_login_prompt_ready_call_count_++;
     42 }
     43 
     44 void FakeSessionManagerClient::EmitLoginPromptVisible() {
     45 }
     46 
     47 void FakeSessionManagerClient::RestartJob(int pid,
     48                                           const std::string& command_line) {
     49 }
     50 
     51 void FakeSessionManagerClient::StartSession(const std::string& user_email) {
     52   DCHECK_EQ(0UL, user_sessions_.count(user_email));
     53   std::string user_id_hash =
     54       CryptohomeClient::GetStubSanitizedUsername(user_email);
     55   user_sessions_[user_email] = user_id_hash;
     56 }
     57 
     58 void FakeSessionManagerClient::StopSession() {
     59 }
     60 
     61 void FakeSessionManagerClient::StartDeviceWipe() {
     62   start_device_wipe_call_count_++;
     63 }
     64 
     65 void FakeSessionManagerClient::RequestLockScreen() {
     66 }
     67 
     68 void FakeSessionManagerClient::NotifyLockScreenShown() {
     69   notify_lock_screen_shown_call_count_++;
     70 }
     71 
     72 void FakeSessionManagerClient::NotifyLockScreenDismissed() {
     73   notify_lock_screen_dismissed_call_count_++;
     74 }
     75 
     76 void FakeSessionManagerClient::RetrieveActiveSessions(
     77       const ActiveSessionsCallback& callback) {
     78   base::MessageLoop::current()->PostTask(
     79       FROM_HERE, base::Bind(callback, user_sessions_, true));
     80 }
     81 
     82 void FakeSessionManagerClient::RetrieveDevicePolicy(
     83     const RetrievePolicyCallback& callback) {
     84   base::MessageLoop::current()->PostTask(FROM_HERE,
     85                                          base::Bind(callback, device_policy_));
     86 }
     87 
     88 void FakeSessionManagerClient::RetrievePolicyForUser(
     89     const std::string& username,
     90     const RetrievePolicyCallback& callback) {
     91   base::MessageLoop::current()->PostTask(
     92       FROM_HERE, base::Bind(callback, user_policies_[username]));
     93 }
     94 
     95 std::string FakeSessionManagerClient::BlockingRetrievePolicyForUser(
     96     const std::string& username) {
     97   return user_policies_[username];
     98 }
     99 
    100 void FakeSessionManagerClient::RetrieveDeviceLocalAccountPolicy(
    101     const std::string& account_id,
    102     const RetrievePolicyCallback& callback) {
    103   base::MessageLoop::current()->PostTask(
    104       FROM_HERE,
    105       base::Bind(callback, device_local_account_policy_[account_id]));
    106 }
    107 
    108 void FakeSessionManagerClient::StoreDevicePolicy(
    109     const std::string& policy_blob,
    110     const StorePolicyCallback& callback) {
    111   device_policy_ = policy_blob;
    112   base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
    113   FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(true));
    114 }
    115 
    116 void FakeSessionManagerClient::StorePolicyForUser(
    117     const std::string& username,
    118     const std::string& policy_blob,
    119     const std::string& policy_key,
    120     const StorePolicyCallback& callback) {
    121   user_policies_[username] = policy_blob;
    122   base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
    123 }
    124 
    125 void FakeSessionManagerClient::StoreDeviceLocalAccountPolicy(
    126     const std::string& account_id,
    127     const std::string& policy_blob,
    128     const StorePolicyCallback& callback) {
    129   device_local_account_policy_[account_id] = policy_blob;
    130   base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
    131 }
    132 
    133 void FakeSessionManagerClient::SetFlagsForUser(
    134     const std::string& username,
    135     const std::vector<std::string>& flags) {
    136 }
    137 
    138 const std::string& FakeSessionManagerClient::device_policy() const {
    139   return device_policy_;
    140 }
    141 
    142 void FakeSessionManagerClient::set_device_policy(
    143     const std::string& policy_blob) {
    144   device_policy_ = policy_blob;
    145 }
    146 
    147 const std::string& FakeSessionManagerClient::user_policy(
    148     const std::string& username) const {
    149   std::map<std::string, std::string>::const_iterator it =
    150       user_policies_.find(username);
    151   return it == user_policies_.end() ? base::EmptyString() : it->second;
    152 }
    153 
    154 void FakeSessionManagerClient::set_user_policy(const std::string& username,
    155                                                const std::string& policy_blob) {
    156   user_policies_[username] = policy_blob;
    157 }
    158 
    159 const std::string& FakeSessionManagerClient::device_local_account_policy(
    160     const std::string& account_id) const {
    161   std::map<std::string, std::string>::const_iterator entry =
    162       device_local_account_policy_.find(account_id);
    163   return entry != device_local_account_policy_.end() ? entry->second
    164                                                      : base::EmptyString();
    165 }
    166 
    167 void FakeSessionManagerClient::set_device_local_account_policy(
    168     const std::string& account_id,
    169     const std::string& policy_blob) {
    170   device_local_account_policy_[account_id] = policy_blob;
    171 }
    172 
    173 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) {
    174   FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(success));
    175 }
    176 
    177 }  // namespace chromeos
    178