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