OLD | NEW |
---|---|
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/chromeos/login/login_utils.h" | 5 #include "chrome/browser/chromeos/login/login_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
11 #include "base/chromeos/chromeos_version.h" | 11 #include "base/chromeos/chromeos_version.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/debug/trace_event.h" | |
Nikita (slow)
2012/12/11 13:02:54
I'm assuming tracing will be removed.
Ivan Korotkov
2012/12/11 15:44:53
Done. Takes 0.17 msec on Alex to stat() a file in
| |
14 #include "base/file_path.h" | 15 #include "base/file_path.h" |
15 #include "base/file_util.h" | 16 #include "base/file_util.h" |
16 #include "base/location.h" | 17 #include "base/location.h" |
17 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
18 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
19 #include "base/memory/singleton.h" | 20 #include "base/memory/singleton.h" |
20 #include "base/path_service.h" | 21 #include "base/path_service.h" |
21 #include "base/string_util.h" | 22 #include "base/string_util.h" |
22 #include "base/stringprintf.h" | 23 #include "base/stringprintf.h" |
23 #include "base/synchronization/lock.h" | 24 #include "base/synchronization/lock.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
40 #include "chrome/browser/chromeos/login/oauth1_token_fetcher.h" | 41 #include "chrome/browser/chromeos/login/oauth1_token_fetcher.h" |
41 #include "chrome/browser/chromeos/login/oauth_login_verifier.h" | 42 #include "chrome/browser/chromeos/login/oauth_login_verifier.h" |
42 #include "chrome/browser/chromeos/login/parallel_authenticator.h" | 43 #include "chrome/browser/chromeos/login/parallel_authenticator.h" |
43 #include "chrome/browser/chromeos/login/policy_oauth_fetcher.h" | 44 #include "chrome/browser/chromeos/login/policy_oauth_fetcher.h" |
44 #include "chrome/browser/chromeos/login/screen_locker.h" | 45 #include "chrome/browser/chromeos/login/screen_locker.h" |
45 #include "chrome/browser/chromeos/login/user_manager.h" | 46 #include "chrome/browser/chromeos/login/user_manager.h" |
46 #include "chrome/browser/chromeos/settings/cros_settings.h" | 47 #include "chrome/browser/chromeos/settings/cros_settings.h" |
47 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 48 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
48 #include "chrome/browser/extensions/extension_service.h" | 49 #include "chrome/browser/extensions/extension_service.h" |
49 #include "chrome/browser/first_run/first_run.h" | 50 #include "chrome/browser/first_run/first_run.h" |
51 #include "chrome/browser/google/google_util_chromeos.h" | |
50 #include "chrome/browser/net/chrome_url_request_context.h" | 52 #include "chrome/browser/net/chrome_url_request_context.h" |
51 #include "chrome/browser/net/preconnect.h" | 53 #include "chrome/browser/net/preconnect.h" |
52 #include "chrome/browser/policy/browser_policy_connector.h" | 54 #include "chrome/browser/policy/browser_policy_connector.h" |
53 #include "chrome/browser/policy/cloud_policy_client.h" | 55 #include "chrome/browser/policy/cloud_policy_client.h" |
54 #include "chrome/browser/policy/cloud_policy_service.h" | 56 #include "chrome/browser/policy/cloud_policy_service.h" |
55 #include "chrome/browser/policy/network_configuration_updater.h" | 57 #include "chrome/browser/policy/network_configuration_updater.h" |
56 #include "chrome/browser/prefs/pref_service.h" | 58 #include "chrome/browser/prefs/pref_service.h" |
57 #include "chrome/browser/profiles/profile.h" | 59 #include "chrome/browser/profiles/profile.h" |
58 #include "chrome/browser/profiles/profile_manager.h" | 60 #include "chrome/browser/profiles/profile_manager.h" |
59 #include "chrome/browser/rlz/rlz.h" | 61 #include "chrome/browser/rlz/rlz.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 void TransferDefaultAuthCacheOnIOThread( | 181 void TransferDefaultAuthCacheOnIOThread( |
180 net::URLRequestContextGetter* auth_context, | 182 net::URLRequestContextGetter* auth_context, |
181 net::URLRequestContextGetter* new_context) { | 183 net::URLRequestContextGetter* new_context) { |
182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
183 net::HttpAuthCache* new_cache = new_context->GetURLRequestContext()-> | 185 net::HttpAuthCache* new_cache = new_context->GetURLRequestContext()-> |
184 http_transaction_factory()->GetSession()->http_auth_cache(); | 186 http_transaction_factory()->GetSession()->http_auth_cache(); |
185 new_cache->UpdateAllFrom(*auth_context->GetURLRequestContext()-> | 187 new_cache->UpdateAllFrom(*auth_context->GetURLRequestContext()-> |
186 http_transaction_factory()->GetSession()->http_auth_cache()); | 188 http_transaction_factory()->GetSession()->http_auth_cache()); |
187 } | 189 } |
188 | 190 |
191 #if defined(ENABLE_RLZ) | |
192 // Flag file that disables RLZ tracking, when present. | |
193 const char kRLZDisabledFlagName[] = FILE_PATH_LITERAL(".rlz_disabled"); | |
194 | |
195 FilePath GetRlzDisabledFlagPath() { | |
196 return file_util::GetHomeDir().Append(kRLZDisabledFlagName); | |
197 } | |
198 #endif | |
199 | |
189 } // namespace | 200 } // namespace |
190 | 201 |
191 // Used to request a restart to switch to the guest mode. | 202 // Used to request a restart to switch to the guest mode. |
192 class JobRestartRequest | 203 class JobRestartRequest |
193 : public base::RefCountedThreadSafe<JobRestartRequest> { | 204 : public base::RefCountedThreadSafe<JobRestartRequest> { |
194 public: | 205 public: |
195 JobRestartRequest(int pid, const std::string& command_line) | 206 JobRestartRequest(int pid, const std::string& command_line) |
196 : pid_(pid), | 207 : pid_(pid), |
197 command_line_(command_line), | 208 command_line_(command_line), |
198 local_state_(g_browser_process->local_state()) { | 209 local_state_(g_browser_process->local_state()) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; | 302 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; |
292 virtual void StartSignedInServices( | 303 virtual void StartSignedInServices( |
293 Profile* profile, | 304 Profile* profile, |
294 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; | 305 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; |
295 virtual void TransferDefaultCookiesAndServerBoundCerts( | 306 virtual void TransferDefaultCookiesAndServerBoundCerts( |
296 Profile* default_profile, | 307 Profile* default_profile, |
297 Profile* new_profile) OVERRIDE; | 308 Profile* new_profile) OVERRIDE; |
298 virtual void TransferDefaultAuthCache(Profile* default_profile, | 309 virtual void TransferDefaultAuthCache(Profile* default_profile, |
299 Profile* new_profile) OVERRIDE; | 310 Profile* new_profile) OVERRIDE; |
300 virtual void StopBackgroundFetchers() OVERRIDE; | 311 virtual void StopBackgroundFetchers() OVERRIDE; |
312 virtual void InitRlzDelayed() OVERRIDE; | |
301 | 313 |
302 // OAuth1TokenFetcher::Delegate overrides. | 314 // OAuth1TokenFetcher::Delegate overrides. |
303 void OnOAuth1AccessTokenAvailable(const std::string& token, | 315 void OnOAuth1AccessTokenAvailable(const std::string& token, |
304 const std::string& secret) OVERRIDE; | 316 const std::string& secret) OVERRIDE; |
305 void OnOAuth1AccessTokenFetchFailed() OVERRIDE; | 317 void OnOAuth1AccessTokenFetchFailed() OVERRIDE; |
306 | 318 |
307 // OAuthLoginVerifier::Delegate overrides. | 319 // OAuthLoginVerifier::Delegate overrides. |
308 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, | 320 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, |
309 const std::string& sid, | 321 const std::string& sid, |
310 const std::string& lsid, | 322 const std::string& lsid, |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 | 660 |
649 user_profile->OnLogin(); | 661 user_profile->OnLogin(); |
650 | 662 |
651 // Send the notification before creating the browser so additional objects | 663 // Send the notification before creating the browser so additional objects |
652 // that need the profile (e.g. the launcher) can be created first. | 664 // that need the profile (e.g. the launcher) can be created first. |
653 content::NotificationService::current()->Notify( | 665 content::NotificationService::current()->Notify( |
654 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 666 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
655 content::NotificationService::AllSources(), | 667 content::NotificationService::AllSources(), |
656 content::Details<Profile>(user_profile)); | 668 content::Details<Profile>(user_profile)); |
657 | 669 |
658 #if defined(ENABLE_RLZ) | 670 InitRlzDelayed(); |
Nikita (slow)
2012/12/11 13:02:54
makes sense to pass user_profile here and remove G
Ivan Korotkov
2012/12/11 15:44:53
Done.
| |
659 // Init the RLZ library. | |
660 int ping_delay = user_profile->GetPrefs()->GetInteger( | |
661 first_run::GetPingDelayPrefName().c_str()); | |
662 RLZTracker::InitRlzFromProfileDelayed( | |
663 user_profile, UserManager::Get()->IsCurrentUserNew(), ping_delay); | |
664 #endif | |
665 | 671 |
666 // TODO(altimofeev): This pointer should probably never be NULL, but it looks | 672 // TODO(altimofeev): This pointer should probably never be NULL, but it looks |
667 // like LoginUtilsImpl::OnProfileCreated() may be getting called before | 673 // like LoginUtilsImpl::OnProfileCreated() may be getting called before |
668 // LoginUtilsImpl::PrepareProfile() has set |delegate_| when Chrome is killed | 674 // LoginUtilsImpl::PrepareProfile() has set |delegate_| when Chrome is killed |
669 // during shutdown in tests -- see http://crosbug.com/18269. Replace this | 675 // during shutdown in tests -- see http://crosbug.com/18269. Replace this |
670 // 'if' statement with a CHECK(delegate_) once the underlying issue is | 676 // 'if' statement with a CHECK(delegate_) once the underlying issue is |
671 // resolved. | 677 // resolved. |
672 if (delegate_) | 678 if (delegate_) |
673 delegate_->OnProfilePrepared(user_profile); | 679 delegate_->OnProfilePrepared(user_profile); |
674 } | 680 } |
675 | 681 |
682 void LoginUtilsImpl::InitRlzDelayed() { | |
683 #if defined(ENABLE_RLZ) | |
684 if (!g_browser_process->local_state()->HasPrefPath(prefs::kRLZBrand)) { | |
685 // Read brand code asynchronously from an OEM file and repost ourselves. | |
686 google_util::chromeos::SetBrandFromFile( | |
687 base::Bind(&LoginUtilsImpl::InitRlzDelayed, AsWeakPtr())); | |
688 return; | |
689 } | |
690 { | |
691 TRACE_EVENT_BEGIN0("RLZ", "LoginUtilsImpl::InitRlzDelayed//FlagFileCheck"); | |
692 // We need to perform a synchronous check for a flag file here. Should not | |
693 // be a problem since this only stat()s a file in home directory which by | |
694 // now should have been cached by filesystem anyway. | |
695 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
696 if (file_util::PathExists(GetRlzDisabledFlagPath())) { | |
697 // Empty brand code effectively turns RLZ off. | |
698 google_util::chromeos::SetTemporaryBrand(""); | |
699 } | |
700 TRACE_EVENT_END0("RLZ", "LoginUtilsImpl::InitRlzDelayed//FlagFileCheck"); | |
701 } | |
702 // Init the RLZ library. | |
703 Profile* user_profile = ProfileManager::GetDefaultProfile(); | |
704 int ping_delay = user_profile->GetPrefs()->GetInteger( | |
705 first_run::GetPingDelayPrefName().c_str()); | |
706 RLZTracker::InitRlzFromProfileDelayed( | |
707 user_profile, UserManager::Get()->IsCurrentUserNew(), ping_delay); | |
708 #endif | |
709 } | |
710 | |
676 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { | 711 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { |
677 std::string oauth1_token; | 712 std::string oauth1_token; |
678 std::string oauth1_secret; | 713 std::string oauth1_secret; |
679 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) | 714 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) |
680 return; | 715 return; |
681 | 716 |
682 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), | 717 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), |
683 oauth1_token, oauth1_secret); | 718 oauth1_token, oauth1_secret); |
684 } | 719 } |
685 | 720 |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1270 bool LoginUtils::IsWhitelisted(const std::string& username) { | 1305 bool LoginUtils::IsWhitelisted(const std::string& username) { |
1271 CrosSettings* cros_settings = CrosSettings::Get(); | 1306 CrosSettings* cros_settings = CrosSettings::Get(); |
1272 bool allow_new_user = false; | 1307 bool allow_new_user = false; |
1273 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 1308 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
1274 if (allow_new_user) | 1309 if (allow_new_user) |
1275 return true; | 1310 return true; |
1276 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); | 1311 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); |
1277 } | 1312 } |
1278 | 1313 |
1279 } // namespace chromeos | 1314 } // namespace chromeos |
OLD | NEW |