| 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/managed/supervised_user_login_flow.h" | 5 #include "chrome/browser/chromeos/login/managed/supervised_user_login_flow.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | |
| 8 #include "base/files/file_path.h" | |
| 9 #include "base/logging.h" | 7 #include "base/logging.h" |
| 10 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
| 11 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | |
| 13 #include "base/values.h" | 10 #include "base/values.h" |
| 14 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | 11 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |
| 15 #include "chrome/browser/chromeos/login/login_utils.h" | 12 #include "chrome/browser/chromeos/login/login_utils.h" |
| 16 #include "chrome/browser/chromeos/login/managed/locally_managed_user_constants.h
" | 13 #include "chrome/browser/chromeos/login/managed/locally_managed_user_constants.h
" |
| 17 #include "chrome/browser/chromeos/login/managed/locally_managed_user_creation_sc
reen.h" | 14 #include "chrome/browser/chromeos/login/managed/locally_managed_user_creation_sc
reen.h" |
| 15 #include "chrome/browser/chromeos/login/supervised_user_manager.h" |
| 18 #include "chrome/browser/chromeos/login/user_manager.h" | 16 #include "chrome/browser/chromeos/login/user_manager.h" |
| 19 #include "chrome/browser/chromeos/login/wizard_controller.h" | 17 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 21 #include "chrome/browser/managed_mode/managed_user_service.h" | |
| 22 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | |
| 23 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 24 | 19 |
| 25 using content::BrowserThread; | 20 using content::BrowserThread; |
| 26 | 21 |
| 27 namespace chromeos { | 22 namespace chromeos { |
| 28 | 23 |
| 29 namespace { | |
| 30 | |
| 31 std::string LoadSyncToken(base::FilePath profile_dir) { | |
| 32 std::string token; | |
| 33 base::FilePath token_file = | |
| 34 profile_dir.Append(kManagedUserTokenFilename); | |
| 35 VLOG(1) << "Loading" << token_file.value(); | |
| 36 if (!base::ReadFileToString(token_file, &token)) { | |
| 37 return std::string(); | |
| 38 } | |
| 39 return token; | |
| 40 } | |
| 41 | |
| 42 } // namespace | |
| 43 | |
| 44 SupervisedUserLoginFlow::SupervisedUserLoginFlow( | 24 SupervisedUserLoginFlow::SupervisedUserLoginFlow( |
| 45 const std::string& user_id) | 25 const std::string& user_id) |
| 46 : ExtendedUserFlow(user_id), | 26 : ExtendedUserFlow(user_id), |
| 47 data_loaded_(false), | 27 data_loaded_(false), |
| 48 weak_factory_(this) { | 28 weak_factory_(this) { |
| 49 } | 29 } |
| 50 | 30 |
| 51 SupervisedUserLoginFlow::~SupervisedUserLoginFlow() {} | 31 SupervisedUserLoginFlow::~SupervisedUserLoginFlow() {} |
| 52 | 32 |
| 53 bool SupervisedUserLoginFlow::CanLockScreen() { | 33 bool SupervisedUserLoginFlow::CanLockScreen() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 76 } | 56 } |
| 77 | 57 |
| 78 void SupervisedUserLoginFlow::OnSyncSetupDataLoaded( | 58 void SupervisedUserLoginFlow::OnSyncSetupDataLoaded( |
| 79 const std::string& token) { | 59 const std::string& token) { |
| 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 81 ConfigureSync(token); | 61 ConfigureSync(token); |
| 82 } | 62 } |
| 83 | 63 |
| 84 void SupervisedUserLoginFlow::ConfigureSync(const std::string& token) { | 64 void SupervisedUserLoginFlow::ConfigureSync(const std::string& token) { |
| 85 data_loaded_ = true; | 65 data_loaded_ = true; |
| 66 |
| 86 // TODO(antrim): add error handling (no token loaded). | 67 // TODO(antrim): add error handling (no token loaded). |
| 87 // See also: http://crbug.com/312751 | 68 // See also: http://crbug.com/312751 |
| 88 if (!token.empty()) | 69 UserManager::Get()->GetSupervisedUserManager()->ConfigureSyncWithToken( |
| 89 ManagedUserServiceFactory::GetForProfile(profile_)->InitSync(token); | 70 profile_, token); |
| 90 | 71 |
| 91 LoginUtils::Get()->DoBrowserLaunch(profile_, host()); | 72 LoginUtils::Get()->DoBrowserLaunch(profile_, host()); |
| 92 profile_ = NULL; | 73 profile_ = NULL; |
| 93 UnregisterFlowSoon(); | 74 UnregisterFlowSoon(); |
| 94 } | 75 } |
| 95 | 76 |
| 96 void SupervisedUserLoginFlow::LaunchExtraSteps( | 77 void SupervisedUserLoginFlow::LaunchExtraSteps( |
| 97 Profile* profile) { | 78 Profile* profile) { |
| 98 profile_ = profile; | 79 profile_ = profile; |
| 99 base::FilePath profile_dir = ProfileHelper::GetProfilePathByUserIdHash( | 80 UserManager::Get()->GetSupervisedUserManager()->LoadSupervisedUserToken( |
| 100 UserManager::Get()->GetUserByProfile(profile)->username_hash()); | 81 profile, |
| 101 PostTaskAndReplyWithResult( | |
| 102 content::BrowserThread::GetBlockingPool(), | |
| 103 FROM_HERE, | |
| 104 base::Bind(&LoadSyncToken, profile_dir), | |
| 105 base::Bind( | 82 base::Bind( |
| 106 &SupervisedUserLoginFlow::OnSyncSetupDataLoaded, | 83 &SupervisedUserLoginFlow::OnSyncSetupDataLoaded, |
| 107 weak_factory_.GetWeakPtr())); | 84 weak_factory_.GetWeakPtr())); |
| 108 } | 85 } |
| 109 | 86 |
| 110 } // namespace chromeos | 87 } // namespace chromeos |
| OLD | NEW |