Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: chrome/browser/chromeos/login/fake_login_utils.cc

Issue 656283002: [session_manager] Move user session initialization code out of ExistingUserController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/fake_login_utils.h" 5 #include "chrome/browser/chromeos/login/fake_login_utils.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 11 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
12 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
12 #include "chrome/browser/chromeos/login/user_flow.h" 13 #include "chrome/browser/chromeos/login/user_flow.h"
13 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" 14 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
14 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" 15 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
15 #include "chrome/browser/chromeos/profiles/profile_helper.h" 16 #include "chrome/browser/chromeos/profiles/profile_helper.h"
16 #include "chrome/browser/first_run/first_run.h" 17 #include "chrome/browser/first_run/first_run.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/startup/startup_browser_creator.h" 19 #include "chrome/browser/ui/startup/startup_browser_creator.h"
19 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
20 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
21 #include "chromeos/login/auth/mock_authenticator.h" 22 #include "chromeos/login/auth/mock_authenticator.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 54 }
54 if (login_host) 55 if (login_host)
55 login_host->Finalize(); 56 login_host->Finalize();
56 user_manager::UserManager::Get()->SessionStarted(); 57 user_manager::UserManager::Get()->SessionStarted();
57 } 58 }
58 59
59 void FakeLoginUtils::PrepareProfile(const UserContext& user_context, 60 void FakeLoginUtils::PrepareProfile(const UserContext& user_context,
60 bool has_cookies, 61 bool has_cookies,
61 bool has_active_session, 62 bool has_active_session,
62 LoginUtils::Delegate* delegate) { 63 LoginUtils::Delegate* delegate) {
63 user_manager::UserManager::Get()->UserLoggedIn( 64 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
65 user_manager->UserLoggedIn(
64 user_context.GetUserID(), user_context.GetUserIDHash(), false); 66 user_context.GetUserID(), user_context.GetUserIDHash(), false);
65 user_manager::User* user = 67 user_manager::User* user =
66 user_manager::UserManager::Get()->FindUserAndModify( 68 user_manager->FindUserAndModify(user_context.GetUserID());
67 user_context.GetUserID());
68 DCHECK(user); 69 DCHECK(user);
69 70
70 // Make sure that we get the real Profile instead of the login Profile. 71 // Make sure that we get the real Profile instead of the login Profile.
71 user->set_profile_is_created(); 72 user->set_profile_is_created();
72 Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user); 73 Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user);
73 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 74 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
74 user_context.GetUserID()); 75 user_context.GetUserID());
75 76
76 if (user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) { 77 if (user_manager->IsLoggedInAsSupervisedUser()) {
77 user_manager::User* active_user = 78 user_manager::User* active_user = user_manager->GetActiveUser();
78 user_manager::UserManager::Get()->GetActiveUser();
79 std::string supervised_user_sync_id = 79 std::string supervised_user_sync_id =
80 ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId( 80 ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId(
81 active_user->email()); 81 active_user->email());
82 if (supervised_user_sync_id.empty()) 82 if (supervised_user_sync_id.empty())
83 supervised_user_sync_id = "DUMMY ID"; 83 supervised_user_sync_id = "DUMMY ID";
84 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, 84 profile->GetPrefs()->SetString(prefs::kSupervisedUserId,
85 supervised_user_sync_id); 85 supervised_user_sync_id);
86 } 86 }
87 87
88 content::NotificationService::current()->Notify( 88 content::NotificationService::current()->Notify(
89 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, 89 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
90 content::NotificationService::AllSources(), 90 content::NotificationService::AllSources(),
91 content::Details<Profile>(profile)); 91 content::Details<Profile>(profile));
92
93 // Emulate UserSessionManager::InitializeUserSession() for now till
94 // FakeLoginUtils are deprecated.
95 bool browser_launched = false;
96 if (!user_manager->IsLoggedInAsKioskApp()) {
97 if (user_manager->IsCurrentUserNew()) {
98 NOTREACHED() << "Method not implemented.";
99 } else {
100 browser_launched = true;
101 LoginUtils::Get()->DoBrowserLaunch(profile,
102 LoginDisplayHostImpl::default_host());
103 }
104 }
105
92 if (delegate) 106 if (delegate)
93 delegate->OnProfilePrepared(profile); 107 delegate->OnProfilePrepared(profile, browser_launched);
94 } 108 }
95 109
96 void FakeLoginUtils::DelegateDeleted(LoginUtils::Delegate* delegate) { 110 void FakeLoginUtils::DelegateDeleted(LoginUtils::Delegate* delegate) {
97 NOTREACHED() << "Method not implemented."; 111 NOTREACHED() << "Method not implemented.";
98 } 112 }
99 113
100 scoped_refptr<Authenticator> FakeLoginUtils::CreateAuthenticator( 114 scoped_refptr<Authenticator> FakeLoginUtils::CreateAuthenticator(
101 AuthStatusConsumer* consumer) { 115 AuthStatusConsumer* consumer) {
102 authenticator_ = new MockAuthenticator(consumer, expected_user_context_); 116 authenticator_ = new MockAuthenticator(consumer, expected_user_context_);
103 return authenticator_; 117 return authenticator_;
104 } 118 }
105 119
106 bool FakeLoginUtils::RestartToApplyPerSessionFlagsIfNeed(Profile* profile, 120 bool FakeLoginUtils::RestartToApplyPerSessionFlagsIfNeed(Profile* profile,
107 bool early_restart) { 121 bool early_restart) {
108 NOTREACHED() << "Method not implemented."; 122 NOTREACHED() << "Method not implemented.";
109 return false; 123 return false;
110 } 124 }
111 125
112 void FakeLoginUtils::SetExpectedCredentials(const UserContext& user_context) { 126 void FakeLoginUtils::SetExpectedCredentials(const UserContext& user_context) {
113 expected_user_context_ = user_context; 127 expected_user_context_ = user_context;
114 if (authenticator_.get()) { 128 if (authenticator_.get()) {
115 static_cast<MockAuthenticator*>(authenticator_.get())-> 129 static_cast<MockAuthenticator*>(authenticator_.get())->
116 SetExpectedCredentials(user_context); 130 SetExpectedCredentials(user_context);
117 } 131 }
118 } 132 }
119 133
120 } // namespace chromeos 134 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698