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

Side by Side Diff: chrome/browser/signin/signin_manager_factory.cc

Issue 2343663003: WIP: Experiment with auto sign-in for chrome enterprise support.
Patch Set: rebased Created 3 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/signin/signin_manager_factory.h" 5 #include "chrome/browser/signin/signin_manager_factory.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/first_run/first_run.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/signin/about_signin_internals_factory.h"
10 #include "chrome/browser/signin/account_fetcher_service_factory.h" 13 #include "chrome/browser/signin/account_fetcher_service_factory.h"
11 #include "chrome/browser/signin/account_tracker_service_factory.h" 14 #include "chrome/browser/signin/account_tracker_service_factory.h"
12 #include "chrome/browser/signin/chrome_signin_client_factory.h" 15 #include "chrome/browser/signin/chrome_signin_client_factory.h"
13 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" 16 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
14 #include "chrome/browser/signin/local_auth.h" 17 #include "chrome/browser/signin/local_auth.h"
15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
16 #include "components/keyed_service/content/browser_context_dependency_manager.h" 19 #include "components/keyed_service/content/browser_context_dependency_manager.h"
17 #include "components/prefs/pref_registry_simple.h" 20 #include "components/prefs/pref_registry_simple.h"
21 #include "components/signin/core/browser/about_signin_internals.h"
22 #include "components/signin/core/browser/signin_internals_util.h"
18 #include "components/signin/core/browser/signin_manager.h" 23 #include "components/signin/core/browser/signin_manager.h"
19 24
25 #if defined(OS_WIN)
26 #include "base/base64.h"
27 #include "base/strings/sys_string_conversions.h"
28 #include "base/win/registry.h"
29 #include "base/win/win_util.h"
30 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
31 #include "components/os_crypt/os_crypt.h"
32 #include "google_apis/google_api_keys.h"
33
34 namespace {
35
36 std::string DecryptRefreshToken(const std::string& cipher_text) {
37 std::string refresh_token;
38 if (!OSCrypt::DecryptString(cipher_text, &refresh_token)) {
39 LOG(ERROR) << "\n\n*** rogerta: unable to decrypt";
40 return std::string();
41 }
42
43 return refresh_token;
44 }
45
46 // This function is posted from SigninManagerFactory::BuildServiceInstanceFor()
47 void StartOneClickSigninSyncStarter(Profile* profile,
48 const base::string16& gaia_id,
49 const base::string16& email,
50 const std::string& refresh_token) {
51 AboutSigninInternals* signin_internals =
52 AboutSigninInternalsFactory::GetInstance()
53 ->GetForProfile(profile);
54 signin_internals->OnAuthenticationResultReceived("GCP");
55
56 // OneClickSigninSyncStarter will delete itself once done.
57 new OneClickSigninSyncStarter(
58 profile,
59 nullptr, // Browser*
60 base::SysWideToUTF8(gaia_id),
61 base::SysWideToUTF8(email),
62 std::string(), // password
63 refresh_token,
64 OneClickSigninSyncStarter::CURRENT_PROFILE,
65 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS,
66 nullptr, // WebContent*
67 OneClickSigninSyncStarter::CONFIRM_AFTER_SIGNIN,
68 GURL(), // current_url
69 GURL(), // continue_url
70 OneClickSigninSyncStarter::Callback());
71 }
72
73 } // namespace
74
75 #endif
76
20 SigninManagerFactory::SigninManagerFactory() 77 SigninManagerFactory::SigninManagerFactory()
21 : BrowserContextKeyedServiceFactory( 78 : BrowserContextKeyedServiceFactory(
22 "SigninManager", 79 "SigninManager",
23 BrowserContextDependencyManager::GetInstance()) { 80 BrowserContextDependencyManager::GetInstance()) {
81 DependsOn(AccountTrackerServiceFactory::GetInstance());
24 DependsOn(ChromeSigninClientFactory::GetInstance()); 82 DependsOn(ChromeSigninClientFactory::GetInstance());
25 DependsOn(GaiaCookieManagerServiceFactory::GetInstance()); 83 DependsOn(GaiaCookieManagerServiceFactory::GetInstance());
26 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); 84 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
27 DependsOn(AccountTrackerServiceFactory::GetInstance());
28 } 85 }
29 86
30 SigninManagerFactory::~SigninManagerFactory() { 87 SigninManagerFactory::~SigninManagerFactory() {
31 } 88 }
32 89
33 #if defined(OS_CHROMEOS) 90 #if defined(OS_CHROMEOS)
34 // static 91 // static
35 SigninManagerBase* SigninManagerFactory::GetForProfileIfExists( 92 SigninManagerBase* SigninManagerFactory::GetForProfileIfExists(
36 Profile* profile) { 93 Profile* profile) {
37 return static_cast<SigninManagerBase*>( 94 return static_cast<SigninManagerBase*>(
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 AccountTrackerServiceFactory::GetForProfile(profile)); 173 AccountTrackerServiceFactory::GetForProfile(profile));
117 #else 174 #else
118 service = new SigninManager( 175 service = new SigninManager(
119 client, 176 client,
120 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), 177 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
121 AccountTrackerServiceFactory::GetForProfile(profile), 178 AccountTrackerServiceFactory::GetForProfile(profile),
122 GaiaCookieManagerServiceFactory::GetForProfile(profile)); 179 GaiaCookieManagerServiceFactory::GetForProfile(profile));
123 AccountFetcherServiceFactory::GetForProfile(profile); 180 AccountFetcherServiceFactory::GetForProfile(profile);
124 #endif 181 #endif
125 service->Initialize(g_browser_process->local_state()); 182 service->Initialize(g_browser_process->local_state());
183
184 // Check to see if auto signin information is available. Only applies if:
185 //
186 // - running on windows
187 // - is an enterprise install
188 // - this is first run
189 // - opening the default profile (i.e. count==0 at this point)
190 // - not already signed in
191 #if defined(OS_WIN)
192 LOG(ERROR) << "\n\n*** rogerta: client_id="
193 << google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN);
194
195 bool check_for_auto_signin = first_run::IsChromeFirstRun() &&
196 g_browser_process->profile_manager()->GetNumberOfProfiles() == 0 &&
197 /*base::win::IsEnrolledToDomain() &&*/ !service->IsAuthenticated();
198 LOG(ERROR) << "\n\n*** rogerta: check=" << check_for_auto_signin;
199 if (check_for_auto_signin) {
200 base::win::RegKey key;
201 LONG sts = key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Accounts",
202 KEY_READ);
203 if (sts == ERROR_SUCCESS) {
204 LOG(ERROR) << "\n\n*** rogerta: opened a/g/a";
205 base::win::RegistryKeyIterator it(key.Handle(), L"");
206 if (it.Valid() && it.SubkeyCount() > 0) {
207 LOG(ERROR) << "\n\n*** rogerta: subkey count=" << it.SubkeyCount();
208 base::win::RegKey key_account(key.Handle(), it.Name(), KEY_READ);
209 if (key_account.Valid()) {
210 base::string16 gaia_id = it.Name();
211 base::string16 email;
212 key_account.ReadValue(L"email", &email);
213 LOG(ERROR) << "\n\n*** rogerta: id=" << it.Name()
214 << " email=" << email;
215
216 // Read the encrypted refresh token. The data is stored in
217 // binary format.
218 std::string encrypted_refresh_token;
219 DWORD size = 0;
220 DWORD type;
221 if (key_account.ReadValue(L"refresh_token", nullptr, &size, &type)
222 == ERROR_SUCCESS) {
223 LOG(ERROR) << "\n\n*** rogerta: rt size=" << size;
224 encrypted_refresh_token.resize(size);
225 key_account.ReadValue(
226 L"refresh_token",
227 const_cast<char*>(encrypted_refresh_token.c_str()),
228 &size, &type);
229 LOG(ERROR) << "\n\n*** rogerta: rt type=" << type;
230 if (!gaia_id.empty() && !email.empty() && type == REG_BINARY &&
231 !encrypted_refresh_token.empty()) {
232 LOG(ERROR) << "\n\n*** rogerta: do autologin";
233 // Delay the OneClickSigninSyncStarter since it will try to get
234 // PKS pointers, and this won't work very from within this PKS
235 // factory function.
236 base::ThreadTaskRunnerHandle::Get()->PostTask(
237 FROM_HERE,
238 base::Bind(&StartOneClickSigninSyncStarter,
239 profile, gaia_id, email,
240 DecryptRefreshToken(encrypted_refresh_token)));
241 }
242 }
243 }
244 }
245 }
246 }
247 #endif
248
126 for (Observer& observer : observer_list_) 249 for (Observer& observer : observer_list_)
127 observer.SigninManagerCreated(service); 250 observer.SigninManagerCreated(service);
128 return service; 251 return service;
129 } 252 }
130 253
131 void SigninManagerFactory::BrowserContextShutdown( 254 void SigninManagerFactory::BrowserContextShutdown(
132 content::BrowserContext* context) { 255 content::BrowserContext* context) {
133 SigninManagerBase* manager = static_cast<SigninManagerBase*>( 256 SigninManagerBase* manager = static_cast<SigninManagerBase*>(
134 GetServiceForBrowserContext(context, false)); 257 GetServiceForBrowserContext(context, false));
135 if (manager) { 258 if (manager) {
136 for (Observer& observer : observer_list_) 259 for (Observer& observer : observer_list_)
137 observer.SigninManagerShutdown(manager); 260 observer.SigninManagerShutdown(manager);
138 } 261 }
139 BrowserContextKeyedServiceFactory::BrowserContextShutdown(context); 262 BrowserContextKeyedServiceFactory::BrowserContextShutdown(context);
140 } 263 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698