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

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

Issue 11506006: [cros] RLZ tracking can be turned off via a flag file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-apply ps#16, it got lost Created 8 years 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 | Annotate | Revision Log
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/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/file_path.h" 14 #include "base/file_path.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/memory/singleton.h" 19 #include "base/memory/singleton.h"
20 #include "base/path_service.h" 20 #include "base/path_service.h"
21 #include "base/prefs/public/pref_member.h" 21 #include "base/prefs/public/pref_member.h"
22 #include "base/string_util.h" 22 #include "base/string_util.h"
23 #include "base/stringprintf.h" 23 #include "base/stringprintf.h"
24 #include "base/synchronization/lock.h" 24 #include "base/synchronization/lock.h"
25 #include "base/threading/thread_restrictions.h" 25 #include "base/task_runner_util.h"
26 #include "base/threading/worker_pool.h"
26 #include "base/time.h" 27 #include "base/time.h"
27 #include "base/utf_string_conversions.h" 28 #include "base/utf_string_conversions.h"
28 #include "cc/switches.h" 29 #include "cc/switches.h"
29 #include "chrome/browser/browser_process.h" 30 #include "chrome/browser/browser_process.h"
30 #include "chrome/browser/browser_shutdown.h" 31 #include "chrome/browser/browser_shutdown.h"
31 #include "chrome/browser/chromeos/boot_times_loader.h" 32 #include "chrome/browser/chromeos/boot_times_loader.h"
32 #include "chrome/browser/chromeos/cros/cert_library.h" 33 #include "chrome/browser/chromeos/cros/cert_library.h"
33 #include "chrome/browser/chromeos/cros/cros_library.h" 34 #include "chrome/browser/chromeos/cros/cros_library.h"
34 #include "chrome/browser/chromeos/cros/cryptohome_library.h" 35 #include "chrome/browser/chromeos/cros/cryptohome_library.h"
35 #include "chrome/browser/chromeos/cros/network_library.h" 36 #include "chrome/browser/chromeos/cros/network_library.h"
36 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" 37 #include "chrome/browser/chromeos/input_method/input_method_configuration.h"
37 #include "chrome/browser/chromeos/input_method/input_method_manager.h" 38 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
38 #include "chrome/browser/chromeos/input_method/input_method_util.h" 39 #include "chrome/browser/chromeos/input_method/input_method_util.h"
39 #include "chrome/browser/chromeos/login/language_switch_menu.h" 40 #include "chrome/browser/chromeos/login/language_switch_menu.h"
40 #include "chrome/browser/chromeos/login/login_display_host.h" 41 #include "chrome/browser/chromeos/login/login_display_host.h"
41 #include "chrome/browser/chromeos/login/oauth1_token_fetcher.h" 42 #include "chrome/browser/chromeos/login/oauth1_token_fetcher.h"
42 #include "chrome/browser/chromeos/login/oauth_login_verifier.h" 43 #include "chrome/browser/chromeos/login/oauth_login_verifier.h"
43 #include "chrome/browser/chromeos/login/parallel_authenticator.h" 44 #include "chrome/browser/chromeos/login/parallel_authenticator.h"
44 #include "chrome/browser/chromeos/login/policy_oauth_fetcher.h" 45 #include "chrome/browser/chromeos/login/policy_oauth_fetcher.h"
45 #include "chrome/browser/chromeos/login/screen_locker.h" 46 #include "chrome/browser/chromeos/login/screen_locker.h"
46 #include "chrome/browser/chromeos/login/user_manager.h" 47 #include "chrome/browser/chromeos/login/user_manager.h"
47 #include "chrome/browser/chromeos/settings/cros_settings.h" 48 #include "chrome/browser/chromeos/settings/cros_settings.h"
48 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 49 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
49 #include "chrome/browser/extensions/extension_service.h" 50 #include "chrome/browser/extensions/extension_service.h"
50 #include "chrome/browser/first_run/first_run.h" 51 #include "chrome/browser/first_run/first_run.h"
52 #include "chrome/browser/google/google_util_chromeos.h"
51 #include "chrome/browser/net/chrome_url_request_context.h" 53 #include "chrome/browser/net/chrome_url_request_context.h"
52 #include "chrome/browser/net/preconnect.h" 54 #include "chrome/browser/net/preconnect.h"
53 #include "chrome/browser/policy/browser_policy_connector.h" 55 #include "chrome/browser/policy/browser_policy_connector.h"
54 #include "chrome/browser/policy/cloud_policy_client.h" 56 #include "chrome/browser/policy/cloud_policy_client.h"
55 #include "chrome/browser/policy/cloud_policy_service.h" 57 #include "chrome/browser/policy/cloud_policy_service.h"
56 #include "chrome/browser/policy/network_configuration_updater.h" 58 #include "chrome/browser/policy/network_configuration_updater.h"
57 #include "chrome/browser/prefs/pref_service.h" 59 #include "chrome/browser/prefs/pref_service.h"
58 #include "chrome/browser/profiles/profile.h" 60 #include "chrome/browser/profiles/profile.h"
59 #include "chrome/browser/profiles/profile_manager.h" 61 #include "chrome/browser/profiles/profile_manager.h"
60 #include "chrome/browser/rlz/rlz.h" 62 #include "chrome/browser/rlz/rlz.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 void TransferDefaultAuthCacheOnIOThread( 182 void TransferDefaultAuthCacheOnIOThread(
181 net::URLRequestContextGetter* auth_context, 183 net::URLRequestContextGetter* auth_context,
182 net::URLRequestContextGetter* new_context) { 184 net::URLRequestContextGetter* new_context) {
183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
184 net::HttpAuthCache* new_cache = new_context->GetURLRequestContext()-> 186 net::HttpAuthCache* new_cache = new_context->GetURLRequestContext()->
185 http_transaction_factory()->GetSession()->http_auth_cache(); 187 http_transaction_factory()->GetSession()->http_auth_cache();
186 new_cache->UpdateAllFrom(*auth_context->GetURLRequestContext()-> 188 new_cache->UpdateAllFrom(*auth_context->GetURLRequestContext()->
187 http_transaction_factory()->GetSession()->http_auth_cache()); 189 http_transaction_factory()->GetSession()->http_auth_cache());
188 } 190 }
189 191
192 #if defined(ENABLE_RLZ)
193 // Flag file that disables RLZ tracking, when present.
194 const char kRLZDisabledFlagName[] = FILE_PATH_LITERAL(".rlz_disabled");
195
196 FilePath GetRlzDisabledFlagPath() {
197 return file_util::GetHomeDir().Append(kRLZDisabledFlagName);
198 }
199 #endif
200
190 } // namespace 201 } // namespace
191 202
192 // Used to request a restart to switch to the guest mode. 203 // Used to request a restart to switch to the guest mode.
193 class JobRestartRequest 204 class JobRestartRequest
194 : public base::RefCountedThreadSafe<JobRestartRequest> { 205 : public base::RefCountedThreadSafe<JobRestartRequest> {
195 public: 206 public:
196 JobRestartRequest(int pid, const std::string& command_line) 207 JobRestartRequest(int pid, const std::string& command_line)
197 : pid_(pid), 208 : pid_(pid),
198 command_line_(command_line), 209 command_line_(command_line),
199 local_state_(g_browser_process->local_state()) { 210 local_state_(g_browser_process->local_state()) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; 303 virtual void StartTokenServices(Profile* user_profile) OVERRIDE;
293 virtual void StartSignedInServices( 304 virtual void StartSignedInServices(
294 Profile* profile, 305 Profile* profile,
295 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; 306 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE;
296 virtual void TransferDefaultCookiesAndServerBoundCerts( 307 virtual void TransferDefaultCookiesAndServerBoundCerts(
297 Profile* default_profile, 308 Profile* default_profile,
298 Profile* new_profile) OVERRIDE; 309 Profile* new_profile) OVERRIDE;
299 virtual void TransferDefaultAuthCache(Profile* default_profile, 310 virtual void TransferDefaultAuthCache(Profile* default_profile,
300 Profile* new_profile) OVERRIDE; 311 Profile* new_profile) OVERRIDE;
301 virtual void StopBackgroundFetchers() OVERRIDE; 312 virtual void StopBackgroundFetchers() OVERRIDE;
313 virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE;
302 314
303 // OAuth1TokenFetcher::Delegate overrides. 315 // OAuth1TokenFetcher::Delegate overrides.
304 void OnOAuth1AccessTokenAvailable(const std::string& token, 316 void OnOAuth1AccessTokenAvailable(const std::string& token,
305 const std::string& secret) OVERRIDE; 317 const std::string& secret) OVERRIDE;
306 void OnOAuth1AccessTokenFetchFailed() OVERRIDE; 318 void OnOAuth1AccessTokenFetchFailed() OVERRIDE;
307 319
308 // OAuthLoginVerifier::Delegate overrides. 320 // OAuthLoginVerifier::Delegate overrides.
309 virtual void OnOAuthVerificationSucceeded(const std::string& user_name, 321 virtual void OnOAuthVerificationSucceeded(const std::string& user_name,
310 const std::string& sid, 322 const std::string& sid,
311 const std::string& lsid, 323 const std::string& lsid,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 const std::string& token, 374 const std::string& token,
363 const std::string& secret); 375 const std::string& secret);
364 376
365 // Check user's profile for kApplicationLocale setting. 377 // Check user's profile for kApplicationLocale setting.
366 void RespectLocalePreference(Profile* pref); 378 void RespectLocalePreference(Profile* pref);
367 379
368 // Callback for asynchronous profile creation. 380 // Callback for asynchronous profile creation.
369 void OnProfileCreated(Profile* profile, 381 void OnProfileCreated(Profile* profile,
370 Profile::CreateStatus status); 382 Profile::CreateStatus status);
371 383
384 // Initializes RLZ. If |disabled| is true, financial pings are turned off.
Peter Kasting 2012/12/17 20:14:03 Nit: What is a "financial ping"? Do you just mean
Ivan Korotkov 2012/12/20 09:20:42 Financial pings are pings with recorded product ev
385 void InitRlz(Profile* user_profile, bool disabled);
386
372 std::string password_; 387 std::string password_;
373 bool pending_requests_; 388 bool pending_requests_;
374 bool using_oauth_; 389 bool using_oauth_;
375 bool has_cookies_; 390 bool has_cookies_;
376 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). 391 // Has to be scoped_refptr, see comment for CreateAuthenticator(...).
377 scoped_refptr<Authenticator> authenticator_; 392 scoped_refptr<Authenticator> authenticator_;
378 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; 393 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_;
379 scoped_ptr<OAuth1TokenFetcher> oauth1_token_fetcher_; 394 scoped_ptr<OAuth1TokenFetcher> oauth1_token_fetcher_;
380 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_; 395 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_;
381 396
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 664
650 user_profile->OnLogin(); 665 user_profile->OnLogin();
651 666
652 // Send the notification before creating the browser so additional objects 667 // Send the notification before creating the browser so additional objects
653 // that need the profile (e.g. the launcher) can be created first. 668 // that need the profile (e.g. the launcher) can be created first.
654 content::NotificationService::current()->Notify( 669 content::NotificationService::current()->Notify(
655 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, 670 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
656 content::NotificationService::AllSources(), 671 content::NotificationService::AllSources(),
657 content::Details<Profile>(user_profile)); 672 content::Details<Profile>(user_profile));
658 673
659 #if defined(ENABLE_RLZ) 674 InitRlzDelayed(user_profile);
660 // Init the RLZ library.
661 int ping_delay = user_profile->GetPrefs()->GetInteger(
662 first_run::GetPingDelayPrefName().c_str());
663 RLZTracker::InitRlzFromProfileDelayed(
664 user_profile, UserManager::Get()->IsCurrentUserNew(), ping_delay);
665 #endif
666 675
667 // TODO(altimofeev): This pointer should probably never be NULL, but it looks 676 // TODO(altimofeev): This pointer should probably never be NULL, but it looks
668 // like LoginUtilsImpl::OnProfileCreated() may be getting called before 677 // like LoginUtilsImpl::OnProfileCreated() may be getting called before
669 // LoginUtilsImpl::PrepareProfile() has set |delegate_| when Chrome is killed 678 // LoginUtilsImpl::PrepareProfile() has set |delegate_| when Chrome is killed
670 // during shutdown in tests -- see http://crosbug.com/18269. Replace this 679 // during shutdown in tests -- see http://crosbug.com/18269. Replace this
671 // 'if' statement with a CHECK(delegate_) once the underlying issue is 680 // 'if' statement with a CHECK(delegate_) once the underlying issue is
672 // resolved. 681 // resolved.
673 if (delegate_) 682 if (delegate_)
674 delegate_->OnProfilePrepared(user_profile); 683 delegate_->OnProfilePrepared(user_profile);
675 } 684 }
676 685
686 void LoginUtilsImpl::InitRlzDelayed(Profile* user_profile) {
687 #if defined(ENABLE_RLZ)
688 if (!g_browser_process->local_state()->HasPrefPath(prefs::kRLZBrand)) {
689 // Read brand code asynchronously from an OEM file and repost ourselves.
690 google_util::chromeos::SetBrandFromFile(
691 base::Bind(&LoginUtilsImpl::InitRlzDelayed, AsWeakPtr(), user_profile));
692 return;
693 }
694 base::PostTaskAndReplyWithResult(
695 base::WorkerPool::GetTaskRunner(false /* task_is_slow */),
Peter Kasting 2012/12/17 20:14:03 Nit: Don't document argument names like this in ge
Ivan Korotkov 2012/12/20 09:20:42 Done.
696 FROM_HERE,
697 base::Bind(&file_util::PathExists, GetRlzDisabledFlagPath()),
698 base::Bind(&LoginUtilsImpl::InitRlz, AsWeakPtr(), user_profile));
699 #endif
700 }
701
702 void LoginUtilsImpl::InitRlz(Profile* user_profile, bool disabled) {
703 #if defined(ENABLE_RLZ)
704 if (disabled) {
705 // Empty brand code turns financial pings off.
Peter Kasting 2012/12/17 20:14:03 Nit: Again, this phrase that has no context or exp
Ivan Korotkov 2012/12/20 09:20:42 Rephrased.
706 google_util::chromeos::ClearBrandForCurrentSession();
707 }
708 // Init the RLZ library.
709 int ping_delay = user_profile->GetPrefs()->GetInteger(
710 first_run::GetPingDelayPrefName().c_str());
711 RLZTracker::InitRlzFromProfileDelayed(
712 user_profile, UserManager::Get()->IsCurrentUserNew(), ping_delay);
713 #endif
714 }
715
677 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { 716 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) {
678 std::string oauth1_token; 717 std::string oauth1_token;
679 std::string oauth1_secret; 718 std::string oauth1_secret;
680 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) 719 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret))
681 return; 720 return;
682 721
683 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), 722 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(),
684 oauth1_token, oauth1_secret); 723 oauth1_token, oauth1_secret);
685 } 724 }
686 725
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 bool LoginUtils::IsWhitelisted(const std::string& username) { 1310 bool LoginUtils::IsWhitelisted(const std::string& username) {
1272 CrosSettings* cros_settings = CrosSettings::Get(); 1311 CrosSettings* cros_settings = CrosSettings::Get();
1273 bool allow_new_user = false; 1312 bool allow_new_user = false;
1274 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); 1313 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user);
1275 if (allow_new_user) 1314 if (allow_new_user)
1276 return true; 1315 return true;
1277 return cros_settings->FindEmailInList(kAccountsPrefUsers, username); 1316 return cros_settings->FindEmailInList(kAccountsPrefUsers, username);
1278 } 1317 }
1279 1318
1280 } // namespace chromeos 1319 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698