OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/users/supervised_user_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/users/supervised_user_manager_impl.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/chromeos/login/supervised/supervised_user_authenticatio
n.h" | 16 #include "chrome/browser/chromeos/login/supervised/supervised_user_authenticatio
n.h" |
17 #include "chrome/browser/chromeos/login/supervised/supervised_user_constants.h" | 17 #include "chrome/browser/chromeos/login/supervised/supervised_user_constants.h" |
18 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h" | 18 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h" |
19 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 19 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
20 #include "chrome/browser/supervised_user/supervised_user_service.h" | 20 #include "chrome/browser/supervised_user/supervised_user_service.h" |
21 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 21 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
22 #include "chromeos/login/user_names.h" | |
23 #include "chromeos/settings/cros_settings_names.h" | 22 #include "chromeos/settings/cros_settings_names.h" |
24 #include "components/prefs/pref_registry_simple.h" | 23 #include "components/prefs/pref_registry_simple.h" |
25 #include "components/prefs/pref_service.h" | 24 #include "components/prefs/pref_service.h" |
26 #include "components/prefs/scoped_user_pref_update.h" | 25 #include "components/prefs/scoped_user_pref_update.h" |
| 26 #include "components/user_manager/user_names.h" |
27 #include "components/user_manager/user_type.h" | 27 #include "components/user_manager/user_type.h" |
28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
29 #include "google_apis/gaia/gaia_auth_util.h" | 29 #include "google_apis/gaia/gaia_auth_util.h" |
30 | 30 |
31 using content::BrowserThread; | 31 using content::BrowserThread; |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 // Names for pref keys in Local State. | 35 // Names for pref keys in Local State. |
36 // A map from supervised user local user id to sync user id. | 36 // A map from supervised user local user id to sync user id. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 SupervisedUserManagerImpl::~SupervisedUserManagerImpl() { | 141 SupervisedUserManagerImpl::~SupervisedUserManagerImpl() { |
142 } | 142 } |
143 | 143 |
144 std::string SupervisedUserManagerImpl::GenerateUserId() { | 144 std::string SupervisedUserManagerImpl::GenerateUserId() { |
145 int counter = g_browser_process->local_state()-> | 145 int counter = g_browser_process->local_state()-> |
146 GetInteger(kSupervisedUsersNextId); | 146 GetInteger(kSupervisedUsersNextId); |
147 std::string id; | 147 std::string id; |
148 bool user_exists; | 148 bool user_exists; |
149 do { | 149 do { |
150 id = base::StringPrintf( | 150 id = base::StringPrintf("%d@%s", counter, |
151 "%d@%s", counter, chromeos::login::kSupervisedUserDomain); | 151 user_manager::kSupervisedUserDomain); |
152 counter++; | 152 counter++; |
153 user_exists = (nullptr != owner_->FindUser(AccountId::FromUserEmail(id))); | 153 user_exists = (nullptr != owner_->FindUser(AccountId::FromUserEmail(id))); |
154 DCHECK(!user_exists); | 154 DCHECK(!user_exists); |
155 if (user_exists) { | 155 if (user_exists) { |
156 LOG(ERROR) << "Supervised user with id " << id << " already exists."; | 156 LOG(ERROR) << "Supervised user with id " << id << " already exists."; |
157 } | 157 } |
158 } while (user_exists); | 158 } while (user_exists); |
159 | 159 |
160 g_browser_process->local_state()-> | 160 g_browser_process->local_state()-> |
161 SetInteger(kSupervisedUsersNextId, counter); | 161 SetInteger(kSupervisedUsersNextId, counter); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 LOG(WARNING) << "Cleaning up transaction for " | 430 LOG(WARNING) << "Cleaning up transaction for " |
431 << display_name << "/" << user_id; | 431 << display_name << "/" << user_id; |
432 | 432 |
433 if (user_id.empty()) { | 433 if (user_id.empty()) { |
434 // Not much to do - just remove transaction. | 434 // Not much to do - just remove transaction. |
435 prefs->ClearPref(kSupervisedUserCreationTransactionDisplayName); | 435 prefs->ClearPref(kSupervisedUserCreationTransactionDisplayName); |
436 prefs->CommitPendingWrite(); | 436 prefs->CommitPendingWrite(); |
437 return; | 437 return; |
438 } | 438 } |
439 | 439 |
440 if (gaia::ExtractDomainName(user_id) != | 440 if (gaia::ExtractDomainName(user_id) != user_manager::kSupervisedUserDomain) { |
441 chromeos::login::kSupervisedUserDomain) { | |
442 LOG(WARNING) << "Clean up transaction for non-supervised user found :" | 441 LOG(WARNING) << "Clean up transaction for non-supervised user found :" |
443 << user_id << ", will not remove data"; | 442 << user_id << ", will not remove data"; |
444 prefs->ClearPref(kSupervisedUserCreationTransactionDisplayName); | 443 prefs->ClearPref(kSupervisedUserCreationTransactionDisplayName); |
445 prefs->ClearPref(kSupervisedUserCreationTransactionUserId); | 444 prefs->ClearPref(kSupervisedUserCreationTransactionUserId); |
446 prefs->CommitPendingWrite(); | 445 prefs->CommitPendingWrite(); |
447 return; | 446 return; |
448 } | 447 } |
449 owner_->RemoveNonOwnerUserInternal(AccountId::FromUserEmail(user_id), | 448 owner_->RemoveNonOwnerUserInternal(AccountId::FromUserEmail(user_id), |
450 nullptr); | 449 nullptr); |
451 | 450 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 } | 524 } |
526 | 525 |
527 void SupervisedUserManagerImpl::ConfigureSyncWithToken( | 526 void SupervisedUserManagerImpl::ConfigureSyncWithToken( |
528 Profile* profile, | 527 Profile* profile, |
529 const std::string& token) { | 528 const std::string& token) { |
530 if (!token.empty()) | 529 if (!token.empty()) |
531 SupervisedUserServiceFactory::GetForProfile(profile)->InitSync(token); | 530 SupervisedUserServiceFactory::GetForProfile(profile)->InitSync(token); |
532 } | 531 } |
533 | 532 |
534 } // namespace chromeos | 533 } // namespace chromeos |
OLD | NEW |