| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/chromeos/login/supervised_user_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/supervised_user_manager_impl.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_registry_simple.h" | 7 #include "base/prefs/pref_registry_simple.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 SetInteger(kLocallyManagedUsersNextId, counter); | 101 SetInteger(kLocallyManagedUsersNextId, counter); |
| 102 | 102 |
| 103 g_browser_process->local_state()->CommitPendingWrite(); | 103 g_browser_process->local_state()->CommitPendingWrite(); |
| 104 return id; | 104 return id; |
| 105 } | 105 } |
| 106 | 106 |
| 107 const User* SupervisedUserManagerImpl::CreateUserRecord( | 107 const User* SupervisedUserManagerImpl::CreateUserRecord( |
| 108 const std::string& manager_id, | 108 const std::string& manager_id, |
| 109 const std::string& local_user_id, | 109 const std::string& local_user_id, |
| 110 const std::string& sync_user_id, | 110 const std::string& sync_user_id, |
| 111 const string16& display_name) { | 111 const base::string16& display_name) { |
| 112 const User* user = FindByDisplayName(display_name); | 112 const User* user = FindByDisplayName(display_name); |
| 113 DCHECK(!user); | 113 DCHECK(!user); |
| 114 if (user) | 114 if (user) |
| 115 return user; | 115 return user; |
| 116 const User* manager = owner_->FindUser(manager_id); | 116 const User* manager = owner_->FindUser(manager_id); |
| 117 CHECK(manager); | 117 CHECK(manager); |
| 118 | 118 |
| 119 PrefService* local_state = g_browser_process->local_state(); | 119 PrefService* local_state = g_browser_process->local_state(); |
| 120 | 120 |
| 121 User* new_user = User::CreateLocallyManagedUser(local_user_id); | 121 User* new_user = User::CreateLocallyManagedUser(local_user_id); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 std::string result; | 156 std::string result; |
| 157 sync_ids->GetStringWithoutPathExpansion(user_id, &result); | 157 sync_ids->GetStringWithoutPathExpansion(user_id, &result); |
| 158 return result; | 158 return result; |
| 159 } | 159 } |
| 160 | 160 |
| 161 string16 SupervisedUserManagerImpl::GetManagerDisplayName( | 161 string16 SupervisedUserManagerImpl::GetManagerDisplayName( |
| 162 const std::string& user_id) const { | 162 const std::string& user_id) const { |
| 163 PrefService* local_state = g_browser_process->local_state(); | 163 PrefService* local_state = g_browser_process->local_state(); |
| 164 const DictionaryValue* manager_names = | 164 const DictionaryValue* manager_names = |
| 165 local_state->GetDictionary(kManagedUserManagerNames); | 165 local_state->GetDictionary(kManagedUserManagerNames); |
| 166 string16 result; | 166 base::string16 result; |
| 167 if (manager_names->GetStringWithoutPathExpansion(user_id, &result) && | 167 if (manager_names->GetStringWithoutPathExpansion(user_id, &result) && |
| 168 !result.empty()) | 168 !result.empty()) |
| 169 return result; | 169 return result; |
| 170 return UTF8ToUTF16(GetManagerDisplayEmail(user_id)); | 170 return UTF8ToUTF16(GetManagerDisplayEmail(user_id)); |
| 171 } | 171 } |
| 172 | 172 |
| 173 std::string SupervisedUserManagerImpl::GetManagerUserId( | 173 std::string SupervisedUserManagerImpl::GetManagerUserId( |
| 174 const std::string& user_id) const { | 174 const std::string& user_id) const { |
| 175 PrefService* local_state = g_browser_process->local_state(); | 175 PrefService* local_state = g_browser_process->local_state(); |
| 176 const DictionaryValue* manager_ids = | 176 const DictionaryValue* manager_ids = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 187 local_state->GetDictionary(kManagedUserManagerDisplayEmails); | 187 local_state->GetDictionary(kManagedUserManagerDisplayEmails); |
| 188 std::string result; | 188 std::string result; |
| 189 if (manager_mails->GetStringWithoutPathExpansion(user_id, &result) && | 189 if (manager_mails->GetStringWithoutPathExpansion(user_id, &result) && |
| 190 !result.empty()) { | 190 !result.empty()) { |
| 191 return result; | 191 return result; |
| 192 } | 192 } |
| 193 return GetManagerUserId(user_id); | 193 return GetManagerUserId(user_id); |
| 194 } | 194 } |
| 195 | 195 |
| 196 const User* SupervisedUserManagerImpl::FindByDisplayName( | 196 const User* SupervisedUserManagerImpl::FindByDisplayName( |
| 197 const string16& display_name) const { | 197 const base::string16& display_name) const { |
| 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 199 const UserList& users = owner_->GetUsers(); | 199 const UserList& users = owner_->GetUsers(); |
| 200 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 200 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
| 201 if (((*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) && | 201 if (((*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) && |
| 202 ((*it)->display_name() == display_name)) { | 202 ((*it)->display_name() == display_name)) { |
| 203 return *it; | 203 return *it; |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 return NULL; | 206 return NULL; |
| 207 } | 207 } |
| 208 | 208 |
| 209 const User* SupervisedUserManagerImpl::FindBySyncId( | 209 const User* SupervisedUserManagerImpl::FindBySyncId( |
| 210 const std::string& sync_id) const { | 210 const std::string& sync_id) const { |
| 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 212 const UserList& users = owner_->GetUsers(); | 212 const UserList& users = owner_->GetUsers(); |
| 213 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 213 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
| 214 if (((*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) && | 214 if (((*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) && |
| 215 (GetUserSyncId((*it)->email()) == sync_id)) { | 215 (GetUserSyncId((*it)->email()) == sync_id)) { |
| 216 return *it; | 216 return *it; |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 return NULL; | 219 return NULL; |
| 220 } | 220 } |
| 221 | 221 |
| 222 void SupervisedUserManagerImpl::StartCreationTransaction( | 222 void SupervisedUserManagerImpl::StartCreationTransaction( |
| 223 const string16& display_name) { | 223 const base::string16& display_name) { |
| 224 g_browser_process->local_state()-> | 224 g_browser_process->local_state()-> |
| 225 SetString(kLocallyManagedUserCreationTransactionDisplayName, | 225 SetString(kLocallyManagedUserCreationTransactionDisplayName, |
| 226 UTF16ToASCII(display_name)); | 226 UTF16ToASCII(display_name)); |
| 227 g_browser_process->local_state()->CommitPendingWrite(); | 227 g_browser_process->local_state()->CommitPendingWrite(); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void SupervisedUserManagerImpl::SetCreationTransactionUserId( | 230 void SupervisedUserManagerImpl::SetCreationTransactionUserId( |
| 231 const std::string& email) { | 231 const std::string& email) { |
| 232 g_browser_process->local_state()-> | 232 g_browser_process->local_state()-> |
| 233 SetString(kLocallyManagedUserCreationTransactionUserId, | 233 SetString(kLocallyManagedUserCreationTransactionUserId, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 manager_emails_update->RemoveWithoutPathExpansion(user_id, NULL); | 304 manager_emails_update->RemoveWithoutPathExpansion(user_id, NULL); |
| 305 } | 305 } |
| 306 | 306 |
| 307 bool SupervisedUserManagerImpl::CheckForFirstRun(const std::string& user_id) { | 307 bool SupervisedUserManagerImpl::CheckForFirstRun(const std::string& user_id) { |
| 308 ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(), | 308 ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(), |
| 309 kLocallyManagedUsersFirstRun); | 309 kLocallyManagedUsersFirstRun); |
| 310 return prefs_new_users_update->Remove(base::StringValue(user_id), NULL); | 310 return prefs_new_users_update->Remove(base::StringValue(user_id), NULL); |
| 311 } | 311 } |
| 312 | 312 |
| 313 void SupervisedUserManagerImpl::UpdateManagerName(const std::string& manager_id, | 313 void SupervisedUserManagerImpl::UpdateManagerName(const std::string& manager_id, |
| 314 const string16& new_display_name) { | 314 const base::string16& new_display_name) { |
| 315 PrefService* local_state = g_browser_process->local_state(); | 315 PrefService* local_state = g_browser_process->local_state(); |
| 316 | 316 |
| 317 const DictionaryValue* manager_ids = | 317 const DictionaryValue* manager_ids = |
| 318 local_state->GetDictionary(kManagedUserManagers); | 318 local_state->GetDictionary(kManagedUserManagers); |
| 319 | 319 |
| 320 DictionaryPrefUpdate manager_name_update(local_state, | 320 DictionaryPrefUpdate manager_name_update(local_state, |
| 321 kManagedUserManagerNames); | 321 kManagedUserManagerNames); |
| 322 for (DictionaryValue::Iterator it(*manager_ids); !it.IsAtEnd(); | 322 for (DictionaryValue::Iterator it(*manager_ids); !it.IsAtEnd(); |
| 323 it.Advance()) { | 323 it.Advance()) { |
| 324 std::string user_id; | 324 std::string user_id; |
| 325 bool has_manager_id = it.value().GetAsString(&user_id); | 325 bool has_manager_id = it.value().GetAsString(&user_id); |
| 326 DCHECK(has_manager_id); | 326 DCHECK(has_manager_id); |
| 327 if (user_id == manager_id) { | 327 if (user_id == manager_id) { |
| 328 manager_name_update->SetWithoutPathExpansion( | 328 manager_name_update->SetWithoutPathExpansion( |
| 329 it.key(), | 329 it.key(), |
| 330 new base::StringValue(new_display_name)); | 330 new base::StringValue(new_display_name)); |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 } | 333 } |
| 334 | 334 |
| 335 | 335 |
| 336 } // namespace chromeos | 336 } // namespace chromeos |
| OLD | NEW |