diff options
author | ivankr@chromium.org <ivankr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-17 15:58:26 +0000 |
---|---|---|
committer | ivankr@chromium.org <ivankr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-17 15:58:26 +0000 |
commit | b2574e87c3acc53b77847d5ec57ea7fb485ecd3c (patch) | |
tree | 0156487cbfc496c8b2bca6f5055d60199f110bab | |
parent | 00fb56253c8f3de7d648bf98e9baf1ee8a688950 (diff) | |
download | chromium_src-b2574e87c3acc53b77847d5ec57ea7fb485ecd3c.zip chromium_src-b2574e87c3acc53b77847d5ec57ea7fb485ecd3c.tar.gz chromium_src-b2574e87c3acc53b77847d5ec57ea7fb485ecd3c.tar.bz2 |
[cros] RLZ tracking can be turned off via a flag file.
Also loads brand code from file for previous users.
BUG=157348
TBR=pkasting@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11506006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173472 0039d316-1c4b-4281-b951-d872f2087c98
19 files changed, 288 insertions, 165 deletions
diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc index 0fc08e5..1d7c829 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc @@ -70,6 +70,7 @@ #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/rlz/rlz.h" #include "chrome/browser/signin/token_service_factory.h" #include "chrome/browser/system_monitor/removable_device_notifications_chromeos.h" #include "chrome/common/chrome_notification_types.h" @@ -496,6 +497,11 @@ void ChromeBrowserMainPartsChromeos::PreProfileInit() { &tracker_); #endif +#if defined(ENABLE_RLZ) + if (parsed_command_line().HasSwitch(::switches::kTestType)) + RLZTracker::EnableZeroDelayForTesting(); +#endif + // In Aura builds this will initialize ash::Shell. ChromeBrowserMainPartsLinux::PreProfileInit(); } @@ -521,6 +527,9 @@ void ChromeBrowserMainPartsChromeos::PostProfileInit() { profile()->GetPrefs()->FindPreference(prefs::kUseSharedProxies); if (use_shared_proxies_pref->IsDefaultValue()) profile()->GetPrefs()->SetBoolean(prefs::kUseSharedProxies, false); + + // This is done in LoginUtils::OnProfileCreated during normal login. + LoginUtils::Get()->InitRlzDelayed(profile()); } // Make sure the NetworkConfigurationUpdater is ready so that it pushes ONC diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc index ecd0c92..2376c3f 100644 --- a/chrome/browser/chromeos/login/login_utils.cc +++ b/chrome/browser/chromeos/login/login_utils.cc @@ -22,7 +22,8 @@ #include "base/string_util.h" #include "base/stringprintf.h" #include "base/synchronization/lock.h" -#include "base/threading/thread_restrictions.h" +#include "base/task_runner_util.h" +#include "base/threading/worker_pool.h" #include "base/time.h" #include "base/utf_string_conversions.h" #include "cc/switches.h" @@ -48,6 +49,7 @@ #include "chrome/browser/chromeos/settings/cros_settings_names.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/first_run/first_run.h" +#include "chrome/browser/google/google_util_chromeos.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/net/preconnect.h" #include "chrome/browser/policy/browser_policy_connector.h" @@ -187,6 +189,15 @@ void TransferDefaultAuthCacheOnIOThread( http_transaction_factory()->GetSession()->http_auth_cache()); } +#if defined(ENABLE_RLZ) +// Flag file that disables RLZ tracking, when present. +const char kRLZDisabledFlagName[] = FILE_PATH_LITERAL(".rlz_disabled"); + +FilePath GetRlzDisabledFlagPath() { + return file_util::GetHomeDir().Append(kRLZDisabledFlagName); +} +#endif + } // namespace // Used to request a restart to switch to the guest mode. @@ -299,6 +310,7 @@ class LoginUtilsImpl virtual void TransferDefaultAuthCache(Profile* default_profile, Profile* new_profile) OVERRIDE; virtual void StopBackgroundFetchers() OVERRIDE; + virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE; // OAuth1TokenFetcher::Delegate overrides. void OnOAuth1AccessTokenAvailable(const std::string& token, @@ -369,6 +381,9 @@ class LoginUtilsImpl void OnProfileCreated(Profile* profile, Profile::CreateStatus status); + // Initializes RLZ. If |disabled| is true, financial pings are turned off. + void InitRlz(Profile* user_profile, bool disabled); + std::string password_; bool pending_requests_; bool using_oauth_; @@ -656,13 +671,7 @@ void LoginUtilsImpl::OnProfileCreated( content::NotificationService::AllSources(), content::Details<Profile>(user_profile)); -#if defined(ENABLE_RLZ) - // Init the RLZ library. - int ping_delay = user_profile->GetPrefs()->GetInteger( - first_run::GetPingDelayPrefName().c_str()); - RLZTracker::InitRlzFromProfileDelayed( - user_profile, UserManager::Get()->IsCurrentUserNew(), ping_delay); -#endif + InitRlzDelayed(user_profile); // TODO(altimofeev): This pointer should probably never be NULL, but it looks // like LoginUtilsImpl::OnProfileCreated() may be getting called before @@ -674,6 +683,36 @@ void LoginUtilsImpl::OnProfileCreated( delegate_->OnProfilePrepared(user_profile); } +void LoginUtilsImpl::InitRlzDelayed(Profile* user_profile) { +#if defined(ENABLE_RLZ) + if (!g_browser_process->local_state()->HasPrefPath(prefs::kRLZBrand)) { + // Read brand code asynchronously from an OEM file and repost ourselves. + google_util::chromeos::SetBrandFromFile( + base::Bind(&LoginUtilsImpl::InitRlzDelayed, AsWeakPtr(), user_profile)); + return; + } + base::PostTaskAndReplyWithResult( + base::WorkerPool::GetTaskRunner(false /* task_is_slow */), + FROM_HERE, + base::Bind(&file_util::PathExists, GetRlzDisabledFlagPath()), + base::Bind(&LoginUtilsImpl::InitRlz, AsWeakPtr(), user_profile)); +#endif +} + +void LoginUtilsImpl::InitRlz(Profile* user_profile, bool disabled) { +#if defined(ENABLE_RLZ) + if (disabled) { + // Empty brand code turns financial pings off. + google_util::chromeos::ClearBrandForCurrentSession(); + } + // Init the RLZ library. + int ping_delay = user_profile->GetPrefs()->GetInteger( + first_run::GetPingDelayPrefName().c_str()); + RLZTracker::InitRlzFromProfileDelayed( + user_profile, UserManager::Get()->IsCurrentUserNew(), ping_delay); +#endif +} + void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { std::string oauth1_token; std::string oauth1_secret; diff --git a/chrome/browser/chromeos/login/login_utils.h b/chrome/browser/chromeos/login/login_utils.h index 2abd2f6..092d22b 100644 --- a/chrome/browser/chromeos/login/login_utils.h +++ b/chrome/browser/chromeos/login/login_utils.h @@ -123,6 +123,9 @@ class LoginUtils { // Stops background fetchers. virtual void StopBackgroundFetchers() = 0; + // Initialize RLZ. + virtual void InitRlzDelayed(Profile* user_profile) = 0; + protected: friend class ::BrowserGuestSessionNavigatorTest; diff --git a/chrome/browser/chromeos/login/login_utils_browsertest.cc b/chrome/browser/chromeos/login/login_utils_browsertest.cc index ab90a32..1aa95dc 100644 --- a/chrome/browser/chromeos/login/login_utils_browsertest.cc +++ b/chrome/browser/chromeos/login/login_utils_browsertest.cc @@ -28,6 +28,7 @@ #include "chrome/browser/policy/policy_service.h" #include "chrome/browser/policy/proto/device_management_backend.pb.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/rlz/rlz.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" @@ -50,6 +51,10 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +#if defined(ENABLE_RLZ) +#include "rlz/lib/rlz_value_store.h" +#endif + namespace chromeos { namespace { @@ -264,6 +269,11 @@ class LoginUtilsTest : public testing::Test, NULL, NULL)); browser_process_->SetIOThread(io_thread_state_.get()); +#if defined(ENABLE_RLZ) + rlz_lib::testing::SetRlzStoreDirectory(scoped_temp_dir_.path()); + RLZTracker::EnableZeroDelayForTesting(); +#endif + RunUntilIdle(); } @@ -276,6 +286,9 @@ class LoginUtilsTest : public testing::Test, InvokeOnIO( base::Bind(&LoginUtilsTest::TearDownOnIO, base::Unretained(this))); + // LoginUtils instance must not outlive Profile instances. + LoginUtils::Set(NULL); + // These trigger some tasks that have to run while BrowserThread::UI // exists. Delete all the profiles before deleting the connector. browser_process_->SetProfileManager(NULL); diff --git a/chrome/browser/chromeos/login/mock_authenticator.cc b/chrome/browser/chromeos/login/mock_authenticator.cc index b195aca..923ffb5 100644 --- a/chrome/browser/chromeos/login/mock_authenticator.cc +++ b/chrome/browser/chromeos/login/mock_authenticator.cc @@ -12,10 +12,10 @@ using content::BrowserThread; namespace chromeos { void MockAuthenticator::AuthenticateToLogin(Profile* profile, - const std::string& username, - const std::string& password, - const std::string& login_token, - const std::string& login_captcha) { + const std::string& username, + const std::string& password, + const std::string& login_token, + const std::string& login_captcha) { if (expected_username_ == username && expected_password_ == password) { BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(&MockAuthenticator::OnLoginSuccess, this, false)); @@ -37,7 +37,7 @@ void MockAuthenticator::CompleteLogin(Profile* profile, } void MockAuthenticator::AuthenticateToUnlock(const std::string& username, - const std::string& password) { + const std::string& password) { AuthenticateToLogin(NULL /* not used */, username, password, std::string(), std::string()); } @@ -58,8 +58,7 @@ void MockAuthenticator::OnRetailModeLoginSuccess() { consumer_->OnRetailModeLoginSuccess(); } -void MockAuthenticator::OnLoginSuccess( - bool request_pending) { +void MockAuthenticator::OnLoginSuccess(bool request_pending) { // If we want to be more like the real thing, we could save username // in AuthenticateToLogin, but there's not much of a point. consumer_->OnLoginSuccess(expected_username_, @@ -72,57 +71,4 @@ void MockAuthenticator::OnLoginFailure(const LoginFailure& failure) { consumer_->OnLoginFailure(failure); } -//////////////////////////////////////////////////////////////////////////////// -// TestLoginUtils - -TestLoginUtils::TestLoginUtils(const std::string& expected_username, - const std::string& expected_password) - : expected_username_(expected_username), - expected_password_(expected_password) { -} - -TestLoginUtils::~TestLoginUtils() {} - -void TestLoginUtils::PrepareProfile( - const std::string& username, - const std::string& display_email, - const std::string& password, - bool pending_requests, - bool using_oauth, - bool has_cookies, - Delegate* delegate) { - DCHECK_EQ(expected_username_, username); - DCHECK_EQ(expected_password_, password); - // Profile hasn't been loaded. - delegate->OnProfilePrepared(NULL); -} - -void TestLoginUtils::DelegateDeleted(Delegate* delegate) { -} - -scoped_refptr<Authenticator> TestLoginUtils::CreateAuthenticator( - LoginStatusConsumer* consumer) { - return new MockAuthenticator( - consumer, expected_username_, expected_password_); -} - -std::string TestLoginUtils::GetOffTheRecordCommandLine( - const GURL& start_url, - const CommandLine& base_command_line, - CommandLine* command_line) { - return std::string(); -} - -void TestLoginUtils::TransferDefaultCookiesAndServerBoundCerts( - Profile* default_profile, - Profile* new_profile) { -} - -void TestLoginUtils::TransferDefaultAuthCache(Profile* default_profile, - Profile* new_profile) { -} - -void TestLoginUtils::StopBackgroundFetchers() { -} - } // namespace chromeos diff --git a/chrome/browser/chromeos/login/mock_authenticator.h b/chrome/browser/chromeos/login/mock_authenticator.h index d08b906..9215c32 100644 --- a/chrome/browser/chromeos/login/mock_authenticator.h +++ b/chrome/browser/chromeos/login/mock_authenticator.h @@ -7,12 +7,7 @@ #include <string> -#include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" #include "chrome/browser/chromeos/login/authenticator.h" -#include "chrome/browser/chromeos/login/login_utils.h" -#include "content/public/browser/browser_thread.h" -#include "google_apis/gaia/google_service_auth_error.h" #include "testing/gtest/include/gtest/gtest.h" class Profile; @@ -75,63 +70,6 @@ class MockAuthenticator : public Authenticator { DISALLOW_COPY_AND_ASSIGN(MockAuthenticator); }; -class TestLoginUtils : public LoginUtils { - public: - TestLoginUtils(const std::string& expected_username, - const std::string& expected_password); - virtual ~TestLoginUtils(); - - virtual void DoBrowserLaunch(Profile* profile, - LoginDisplayHost* login_host) OVERRIDE {} - virtual void PrepareProfile(const std::string& username, - const std::string& display_email, - const std::string& password, - bool pending_requests, - bool using_oauth, - bool has_cookies, - Delegate* delegate) OVERRIDE; - - virtual void DelegateDeleted(Delegate* delegate) OVERRIDE; - - virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE {} - - virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE {} - - virtual scoped_refptr<Authenticator> CreateAuthenticator( - LoginStatusConsumer* consumer) OVERRIDE; - - virtual void PrewarmAuthentication() OVERRIDE {} - - virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE {} - - virtual void StartTokenServices(Profile* profile) OVERRIDE {} - - virtual void StartSignedInServices( - Profile* profile, - const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE {} - - virtual std::string GetOffTheRecordCommandLine( - const GURL& start_url, - const CommandLine& base_command_line, - CommandLine* command_line) OVERRIDE; - - virtual void TransferDefaultCookiesAndServerBoundCerts( - Profile* default_profile, - Profile* new_profile) OVERRIDE; - - virtual void TransferDefaultAuthCache(Profile* default_profile, - Profile* new_profile) OVERRIDE; - - virtual void StopBackgroundFetchers() OVERRIDE; - - private: - std::string expected_username_; - std::string expected_password_; - std::string auth_token_; - - DISALLOW_COPY_AND_ASSIGN(TestLoginUtils); -}; - } // namespace chromeos #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_AUTHENTICATOR_H_ diff --git a/chrome/browser/chromeos/login/mock_login_utils.h b/chrome/browser/chromeos/login/mock_login_utils.h index 254cd38..fd5f8e5 100644 --- a/chrome/browser/chromeos/login/mock_login_utils.h +++ b/chrome/browser/chromeos/login/mock_login_utils.h @@ -49,6 +49,7 @@ class MockLoginUtils : public LoginUtils { MOCK_METHOD0(StopBackgroundFetchers, void(void)); MOCK_METHOD3(GetOffTheRecordCommandLine, std::string(const GURL&, const CommandLine&, CommandLine*)); + MOCK_METHOD1(InitRlzDelayed, void(Profile*)); }; } // namespace chromeos diff --git a/chrome/browser/chromeos/login/test_login_utils.cc b/chrome/browser/chromeos/login/test_login_utils.cc new file mode 100644 index 0000000..07a32c6 --- /dev/null +++ b/chrome/browser/chromeos/login/test_login_utils.cc @@ -0,0 +1,64 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/login/test_login_utils.h" + +#include "chrome/browser/chromeos/login/mock_authenticator.h" + +namespace chromeos { + +TestLoginUtils::TestLoginUtils(const std::string& expected_username, + const std::string& expected_password) + : expected_username_(expected_username), + expected_password_(expected_password) { +} + +TestLoginUtils::~TestLoginUtils() {} + +void TestLoginUtils::PrepareProfile( + const std::string& username, + const std::string& display_email, + const std::string& password, + bool pending_requests, + bool using_oauth, + bool has_cookies, + Delegate* delegate) { + DCHECK_EQ(expected_username_, username); + DCHECK_EQ(expected_password_, password); + // Profile hasn't been loaded. + delegate->OnProfilePrepared(NULL); +} + +void TestLoginUtils::DelegateDeleted(Delegate* delegate) { +} + +scoped_refptr<Authenticator> TestLoginUtils::CreateAuthenticator( + LoginStatusConsumer* consumer) { + return new MockAuthenticator( + consumer, expected_username_, expected_password_); +} + +std::string TestLoginUtils::GetOffTheRecordCommandLine( + const GURL& start_url, + const CommandLine& base_command_line, + CommandLine* command_line) { + return std::string(); +} + +void TestLoginUtils::InitRlzDelayed(Profile* user_profile) { +} + +void TestLoginUtils::TransferDefaultCookiesAndServerBoundCerts( + Profile* default_profile, + Profile* new_profile) { +} + +void TestLoginUtils::TransferDefaultAuthCache(Profile* default_profile, + Profile* new_profile) { +} + +void TestLoginUtils::StopBackgroundFetchers() { +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/login/test_login_utils.h b/chrome/browser/chromeos/login/test_login_utils.h new file mode 100644 index 0000000..162ea4b --- /dev/null +++ b/chrome/browser/chromeos/login/test_login_utils.h @@ -0,0 +1,83 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_TEST_LOGIN_UTILS_H_ +#define CHROME_BROWSER_CHROMEOS_LOGIN_TEST_LOGIN_UTILS_H_ + +#include <string> + +#include "base/memory/ref_counted.h" +#include "chrome/browser/chromeos/login/authenticator.h" +#include "chrome/browser/chromeos/login/login_utils.h" +#include "google_apis/gaia/google_service_auth_error.h" +#include "testing/gtest/include/gtest/gtest.h" + +class Profile; + +namespace chromeos { + +class LoginStatusConsumer; + +class TestLoginUtils : public LoginUtils { + public: + TestLoginUtils(const std::string& expected_username, + const std::string& expected_password); + virtual ~TestLoginUtils(); + + virtual void DoBrowserLaunch(Profile* profile, + LoginDisplayHost* login_host) OVERRIDE {} + virtual void PrepareProfile(const std::string& username, + const std::string& display_email, + const std::string& password, + bool pending_requests, + bool using_oauth, + bool has_cookies, + Delegate* delegate) OVERRIDE; + + virtual void DelegateDeleted(Delegate* delegate) OVERRIDE; + + virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE {} + + virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE {} + + virtual scoped_refptr<Authenticator> CreateAuthenticator( + LoginStatusConsumer* consumer) OVERRIDE; + + virtual void PrewarmAuthentication() OVERRIDE {} + + virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE {} + + virtual void StartTokenServices(Profile* profile) OVERRIDE {} + + virtual void StartSignedInServices( + Profile* profile, + const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE {} + + virtual std::string GetOffTheRecordCommandLine( + const GURL& start_url, + const CommandLine& base_command_line, + CommandLine* command_line) OVERRIDE; + + virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE; + + virtual void TransferDefaultCookiesAndServerBoundCerts( + Profile* default_profile, + Profile* new_profile) OVERRIDE; + + virtual void TransferDefaultAuthCache(Profile* default_profile, + Profile* new_profile) OVERRIDE; + + virtual void StopBackgroundFetchers() OVERRIDE; + + private: + std::string expected_username_; + std::string expected_password_; + std::string auth_token_; + + DISALLOW_COPY_AND_ASSIGN(TestLoginUtils); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_LOGIN_TEST_LOGIN_UTILS_H_ diff --git a/chrome/browser/chromeos/login/wizard_controller.cc b/chrome/browser/chromeos/login/wizard_controller.cc index 87a5ce5..f9f7cec 100644 --- a/chrome/browser/chromeos/login/wizard_controller.cc +++ b/chrome/browser/chromeos/login/wizard_controller.cc @@ -39,7 +39,6 @@ #include "chrome/browser/chromeos/login/user_manager.h" #include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings_names.h" -#include "chrome/browser/google/google_util_chromeos.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/options/options_util.h" @@ -148,8 +147,7 @@ WizardController::WizardController(chromeos::LoginDisplayHost* host, oobe_display_(oobe_display), usage_statistics_reporting_(true), skip_update_enroll_after_eula_(false), - login_screen_started_(false), - ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { + login_screen_started_(false) { DCHECK(default_controller_ == NULL); default_controller_ = this; } @@ -477,21 +475,6 @@ void WizardController::OnEulaAccepted() { #endif } - // TODO(ivankr): post-AU action when |kRLZBrand| is unset. -#if defined(ENABLE_RLZ) - LoadBrandCodeFromFile(); -#else - OnEulaBlockingTasksDone(); -#endif -} - -void WizardController::LoadBrandCodeFromFile() { - google_util::chromeos::SetBrandFromFile( - base::Bind(&WizardController::OnEulaBlockingTasksDone, - weak_ptr_factory_.GetWeakPtr())); -} - -void WizardController::OnEulaBlockingTasksDone() { if (skip_update_enroll_after_eula_) { PerformPostEulaActions(); PerformPostUpdateActions(); diff --git a/chrome/browser/chromeos/login/wizard_controller.h b/chrome/browser/chromeos/login/wizard_controller.h index 1a703d9..822e2e6 100644 --- a/chrome/browser/chromeos/login/wizard_controller.h +++ b/chrome/browser/chromeos/login/wizard_controller.h @@ -10,7 +10,6 @@ #include "base/compiler_specific.h" #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" #include "base/observer_list.h" #include "base/time.h" #include "base/timer.h" @@ -291,8 +290,6 @@ class WizardController : public ScreenObserver { bool login_screen_started_; - base::WeakPtrFactory<WizardController> weak_ptr_factory_; - FRIEND_TEST_ALL_PREFIXES(EnterpriseEnrollmentScreenTest, TestCancel); FRIEND_TEST_ALL_PREFIXES(WizardControllerFlowTest, Accelerators); friend class WizardControllerFlowTest; diff --git a/chrome/browser/chromeos/login/wizard_controller_browsertest.cc b/chrome/browser/chromeos/login/wizard_controller_browsertest.cc index 56da6aa..e345773 100644 --- a/chrome/browser/chromeos/login/wizard_controller_browsertest.cc +++ b/chrome/browser/chromeos/login/wizard_controller_browsertest.cc @@ -19,6 +19,7 @@ #include "chrome/browser/chromeos/login/mock_update_screen.h" #include "chrome/browser/chromeos/login/network_screen.h" #include "chrome/browser/chromeos/login/reset_screen.h" +#include "chrome/browser/chromeos/login/test_login_utils.h" #include "chrome/browser/chromeos/login/user_image_screen.h" #include "chrome/browser/chromeos/login/view_screen.h" #include "chrome/browser/chromeos/login/wizard_controller.h" diff --git a/chrome/browser/google/google_util_chromeos.cc b/chrome/browser/google/google_util_chromeos.cc index 2892efc..50947e5 100644 --- a/chrome/browser/google/google_util_chromeos.cc +++ b/chrome/browser/google/google_util_chromeos.cc @@ -40,12 +40,24 @@ void SetBrand(const base::Closure& callback, const std::string& brand) { callback.Run(); } +// True if brand code has been cleared for the current session. +bool g_brand_empty = false; + } // namespace +void ClearBrandForCurrentSession() { + DCHECK( + !content::BrowserThread::IsWellKnownThread(content::BrowserThread::UI) || + content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + g_brand_empty = true; +} + std::string GetBrand() { DCHECK( !content::BrowserThread::IsWellKnownThread(content::BrowserThread::UI) || content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + if (g_brand_empty) + return std::string(); DCHECK(g_browser_process->local_state()); return g_browser_process->local_state()->GetString(prefs::kRLZBrand); } diff --git a/chrome/browser/google/google_util_chromeos.h b/chrome/browser/google/google_util_chromeos.h index 94443ee..5a90eab 100644 --- a/chrome/browser/google/google_util_chromeos.h +++ b/chrome/browser/google/google_util_chromeos.h @@ -16,6 +16,10 @@ namespace chromeos { // partner. Returns empty string if the information is not available. std::string GetBrand(); +// Clears brand code for the current session (not persisted through browser +// restart). Future calls to GetBrand() will return an empty string. +void ClearBrandForCurrentSession(); + // Reads the brand code from a board-specific file and stores it to Local State. // |callback| is invoked on the calling thread after that. void SetBrandFromFile(const base::Closure& callback); diff --git a/chrome/browser/rlz/rlz.cc b/chrome/browser/rlz/rlz.cc index 7048b92..31a8316 100644 --- a/chrome/browser/rlz/rlz.cc +++ b/chrome/browser/rlz/rlz.cc @@ -57,6 +57,11 @@ using content::NavigationEntry; namespace { +// Maximum and minimum delay for financial ping we would allow to be set through +// master preferences. Somewhat arbitrary, may need to be adjusted in future. +const int kMaxDelay = 200 * 1000; +const int kMinDelay = 20 * 1000; + bool IsGoogleUrl(const GURL& url) { return google_util::IsGoogleHomePageUrl(url.possibly_invalid_spec()); } @@ -180,9 +185,11 @@ RLZTracker::RLZTracker() is_google_default_search_(false), is_google_homepage_(false), is_google_in_startpages_(false), + worker_pool_token_(BrowserThread::GetBlockingPool()->GetSequenceToken()), already_ran_(false), omnibox_used_(false), - homepage_used_(false) { + homepage_used_(false), + min_delay_(kMinDelay) { } RLZTracker::~RLZTracker() { @@ -259,13 +266,8 @@ bool RLZTracker::Init(bool first_run, delay = -delay; } - // Maximum and minimum delay we would allow to be set through master - // preferences. Somewhat arbitrary, may need to be adjusted in future. - const int kMaxDelay = 200 * 1000; - const int kMinDelay = 20 * 1000; - delay *= 1000; - delay = (delay < kMinDelay) ? kMinDelay : delay; + delay = (delay < min_delay_) ? min_delay_ : delay; delay = (delay > kMaxDelay) ? kMaxDelay : delay; if (google_util::GetBrand(&brand_) && !IsBrandOrganic(brand_)) { @@ -294,15 +296,14 @@ bool RLZTracker::Init(bool first_run, void RLZTracker::ScheduleDelayedInit(int delay) { // The RLZTracker is a singleton object that outlives any runnable tasks // that will be queued up. - BrowserThread::GetBlockingPool()->PostDelayedTask( + BrowserThread::GetBlockingPool()->PostDelayedSequencedWorkerTask( + worker_pool_token_, FROM_HERE, base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), base::TimeDelta::FromMilliseconds(delay)); } void RLZTracker::DelayedInit() { - worker_pool_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken(); - bool schedule_ping = false; // For organic brandcodes do not use rlz at all. Empty brandcode usually @@ -330,6 +331,10 @@ void RLZTracker::DelayedInit() { ScheduleFinancialPing(); } +void RLZTracker::EnableZeroDelayForTesting() { + GetInstance()->min_delay_ = 0; +} + void RLZTracker::ScheduleFinancialPing() { BrowserThread::GetBlockingPool()->PostSequencedWorkerTask( worker_pool_token_, @@ -432,10 +437,6 @@ bool RLZTracker::ScheduleRecordProductEvent(rlz_lib::Product product, rlz_lib::Event event_id) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) return false; - if (!already_ran_) { - LOG(ERROR) << "Attempted recording RLZ event before RLZ init."; - return true; - } BrowserThread::GetBlockingPool()->PostSequencedWorkerTask( worker_pool_token_, diff --git a/chrome/browser/rlz/rlz.h b/chrome/browser/rlz/rlz.h index aa02d49..3c1733e 100644 --- a/chrome/browser/rlz/rlz.h +++ b/chrome/browser/rlz/rlz.h @@ -75,6 +75,9 @@ class RLZTracker : public content::NotificationObserver { // This method is public for use by the Singleton class. static RLZTracker* GetInstance(); + // Enables zero delay for InitRlzFromProfileDelayed. For testing only. + static void EnableZeroDelayForTesting(); + // The following methods are made protected so that they can be used for // testing purposes. Production code should never need to call these. protected: @@ -198,6 +201,9 @@ class RLZTracker : public content::NotificationObserver { content::NotificationRegistrar registrar_; + // Minimum delay before sending financial ping after initialization. + int min_delay_; + DISALLOW_COPY_AND_ASSIGN(RLZTracker); }; diff --git a/chrome/browser/search_engines/template_url_service_test_util.cc b/chrome/browser/search_engines/template_url_service_test_util.cc index 356b05a..5eb45f4 100644 --- a/chrome/browser/search_engines/template_url_service_test_util.cc +++ b/chrome/browser/search_engines/template_url_service_test_util.cc @@ -23,6 +23,10 @@ #include "content/public/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" +#if defined(OS_CHROMEOS) +#include "chrome/browser/google/google_util_chromeos.h" +#endif + using content::BrowserThread; namespace { @@ -175,6 +179,10 @@ void TemplateURLServiceTestUtil::SetUp() { TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( profile_.get(), TestingTemplateURLService::Build)); service->AddObserver(this); + +#if defined(OS_CHROMEOS) + google_util::chromeos::ClearBrandForCurrentSession(); +#endif } void TemplateURLServiceTestUtil::TearDown() { diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 24dfd67..7cf424d 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -905,6 +905,8 @@ 'browser/chromeos/login/network_screen_browsertest.cc', 'browser/chromeos/login/screen_locker_tester.cc', 'browser/chromeos/login/screen_locker_tester.h', + 'browser/chromeos/login/test_login_utils.cc', + 'browser/chromeos/login/test_login_utils.h', 'browser/chromeos/login/update_screen_browsertest.cc', 'browser/chromeos/login/user_image_manager_browsertest.cc', 'browser/chromeos/login/wizard_controller_browsertest.cc', diff --git a/rlz/test/rlz_unittest_main.cc b/rlz/test/rlz_unittest_main.cc index 8ebbaf8..f2e99cb 100644 --- a/rlz/test/rlz_unittest_main.cc +++ b/rlz/test/rlz_unittest_main.cc @@ -10,6 +10,12 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +#if defined(OS_POSIX) +#include "base/file_path.h" +#include "base/files/scoped_temp_dir.h" +#include "rlz/lib/rlz_value_store.h" +#endif + int main(int argc, char **argv) { base::AtExitManager at_exit; CommandLine::Init(argc, argv); @@ -21,6 +27,13 @@ int main(int argc, char **argv) { if (ret == 0) { // Now re-run all the tests using a supplementary brand code. This brand // code will remain in effect for the lifetime of the branding object. +#if defined(OS_POSIX) + // Set a temporary directory for RLZ here, because SupplementaryBranding + // creates and owns RlzValueStore object for its lifetime. + base::ScopedTempDir temp_dir; + if (temp_dir.CreateUniqueTempDir()) + rlz_lib::testing::SetRlzStoreDirectory(temp_dir.path()); +#endif rlz_lib::SupplementaryBranding branding("TEST"); ret = RUN_ALL_TESTS(); } |