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/file_util.h" | |
8 #include "base/files/file_path.h" | |
7 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
8 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/threading/sequenced_worker_pool.h" | |
13 #include "base/values.h" | 16 #include "base/values.h" |
14 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/chromeos/login/managed/locally_managed_user_constants.h " | |
15 #include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h " | 19 #include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h " |
16 #include "chrome/browser/chromeos/login/user_manager_impl.h" | 20 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
21 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
22 #include "chrome/browser/managed_mode/managed_user_service.h" | |
23 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | |
17 #include "chromeos/settings/cros_settings_names.h" | 24 #include "chromeos/settings/cros_settings_names.h" |
18 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
19 #include "google_apis/gaia/gaia_auth_util.h" | 26 #include "google_apis/gaia/gaia_auth_util.h" |
20 | 27 |
21 using content::BrowserThread; | 28 using content::BrowserThread; |
22 | 29 |
23 namespace { | 30 namespace { |
24 | 31 |
25 // Names for pref keys in Local State. | 32 // Names for pref keys in Local State. |
26 // A map from locally managed user local user id to sync user id. | 33 // A map from locally managed user local user id to sync user id. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 "SupervisedUserPasswordSchema"; | 67 "SupervisedUserPasswordSchema"; |
61 | 68 |
62 // A map from user id to password salt. | 69 // A map from user id to password salt. |
63 const char kSupervisedUserPasswordSalt[] = | 70 const char kSupervisedUserPasswordSalt[] = |
64 "SupervisedUserPasswordSalt"; | 71 "SupervisedUserPasswordSalt"; |
65 | 72 |
66 // A map from user id to password revision. | 73 // A map from user id to password revision. |
67 const char kSupervisedUserPasswordRevision[] = | 74 const char kSupervisedUserPasswordRevision[] = |
68 "SupervisedUserPasswordRevision"; | 75 "SupervisedUserPasswordRevision"; |
69 | 76 |
77 std::string LoadSyncToken(base::FilePath profile_dir) { | |
78 std::string token; | |
79 base::FilePath token_file = | |
80 profile_dir.Append(chromeos::kManagedUserTokenFilename); | |
81 VLOG(1) << "Loading" << token_file.value(); | |
82 if (!base::ReadFileToString(token_file, &token)) { | |
Nikita (slow)
2014/02/07 09:51:48
nit: Drop {}
| |
83 return std::string(); | |
84 } | |
85 return token; | |
86 } | |
87 | |
70 } // namespace | 88 } // namespace |
71 | 89 |
72 namespace chromeos { | 90 namespace chromeos { |
73 | 91 |
74 const char kSchemaVersion[] = "SchemaVersion"; | 92 const char kSchemaVersion[] = "SchemaVersion"; |
75 const char kPasswordRevision[] = "PasswordRevision"; | 93 const char kPasswordRevision[] = "PasswordRevision"; |
76 const char kSalt[] = "PasswordSalt"; | 94 const char kSalt[] = "PasswordSalt"; |
77 const char kEncryptedPassword[] = "EncryptedPassword"; | 95 const char kEncryptedPassword[] = "EncryptedPassword"; |
78 const int kMinPasswordRevision = 1; | 96 const int kMinPasswordRevision = 1; |
79 | 97 |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 it.key(), | 428 it.key(), |
411 new base::StringValue(new_display_name)); | 429 new base::StringValue(new_display_name)); |
412 } | 430 } |
413 } | 431 } |
414 } | 432 } |
415 | 433 |
416 SupervisedUserAuthentication* SupervisedUserManagerImpl::GetAuthentication() { | 434 SupervisedUserAuthentication* SupervisedUserManagerImpl::GetAuthentication() { |
417 return authentication_.get(); | 435 return authentication_.get(); |
418 } | 436 } |
419 | 437 |
438 void SupervisedUserManagerImpl::LoadSupervisedUserToken( | |
439 Profile* profile, | |
440 const LoadTokenCallback& callback) { | |
441 base::FilePath profile_dir = ProfileHelper::GetProfilePathByUserIdHash( | |
Nikita (slow)
2014/02/07 09:51:48
profile->GetPath() should work too.
| |
442 UserManager::Get()->GetUserByProfile(profile)->username_hash()); | |
443 PostTaskAndReplyWithResult( | |
444 content::BrowserThread::GetBlockingPool(), | |
445 FROM_HERE, | |
446 base::Bind(&LoadSyncToken, profile_dir), | |
447 callback); | |
448 } | |
449 | |
450 void SupervisedUserManagerImpl::ConfigureSyncWithToken( | |
451 Profile* profile, | |
452 const std::string& token) { | |
453 if (!token.empty()) | |
454 ManagedUserServiceFactory::GetForProfile(profile)->InitSync(token); | |
455 } | |
456 | |
420 } // namespace chromeos | 457 } // namespace chromeos |
OLD | NEW |