summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/BUILD.gn18
-rw-r--r--chrome/browser/DEPS1
-rw-r--r--chrome/browser/browser_shutdown.cc4
-rw-r--r--chrome/browser/chrome_browser_main.cc14
-rw-r--r--chrome/browser/chromeos/chrome_browser_main_chromeos.cc5
-rw-r--r--chrome/browser/chromeos/login/login_utils_browsertest.cc13
-rw-r--r--chrome/browser/chromeos/login/session/user_session_manager.cc21
-rw-r--r--chrome/browser/rlz/chrome_rlz_tracker_delegate.cc236
-rw-r--r--chrome/browser/rlz/chrome_rlz_tracker_delegate.h56
-rw-r--r--chrome/browser/rlz/chrome_rlz_tracker_delegate_unittest.cc48
-rw-r--r--chrome/browser/rlz/rlz.cc670
-rw-r--r--chrome/browser/rlz/rlz.h246
-rw-r--r--chrome/browser/rlz/rlz_chromeos.cc20
-rw-r--r--chrome/browser/rlz/rlz_ios.mm14
-rw-r--r--chrome/browser/rlz/rlz_mac.cc20
-rw-r--r--chrome/browser/rlz/rlz_unittest.cc925
-rw-r--r--chrome/browser/rlz/rlz_win.cc20
-rw-r--r--chrome/browser/search_engines/template_url_service_factory.cc13
-rw-r--r--chrome/browser/search_engines/ui_thread_search_terms_data.cc8
-rw-r--r--chrome/browser/ui/app_list/app_list_controller_delegate.cc4
-rw-r--r--chrome/browser/ui/browser_commands.cc9
-rw-r--r--chrome/browser/ui/startup/startup_browser_creator_impl.cc9
22 files changed, 418 insertions, 1956 deletions
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 353cc37..43c90b3 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -685,9 +685,7 @@ source_set("browser") {
}
if (enable_rlz) {
- sources +=
- rebase_path(gypi_values.chrome_browser_rlz_sources, ".", "//chrome")
- deps += [ "//rlz:rlz_lib" ]
+ deps += [ ":rlz" ]
}
# TODO(GYP)
@@ -1197,3 +1195,17 @@ source_set("test_support") {
]
}
}
+
+if (enable_rlz_support) {
+ source_set("rlz") {
+ sources =
+ rebase_path(gypi_values.chrome_browser_rlz_sources, ".", "//chrome")
+ deps = [
+ "//components/google/core/browser",
+ "//components/omnibox/browser",
+ "//components/rlz",
+ "//components/search_engines",
+ "//rlz:rlz_lib",
+ ]
+ }
+}
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS
index 4b598f5..4bd2354 100644
--- a/chrome/browser/DEPS
+++ b/chrome/browser/DEPS
@@ -72,6 +72,7 @@ include_rules = [
"+components/query_parser",
"+components/rappor",
"+components/renderer_context_menu",
+ "+components/rlz",
"+components/safe_json",
"+components/search",
"+components/search_engines",
diff --git a/chrome/browser/browser_shutdown.cc b/chrome/browser/browser_shutdown.cc
index 8974bd5..9ee066b 100644
--- a/chrome/browser/browser_shutdown.cc
+++ b/chrome/browser/browser_shutdown.cc
@@ -40,7 +40,7 @@
#endif
#if defined(ENABLE_RLZ)
-#include "chrome/browser/rlz/rlz.h"
+#include "components/rlz/rlz_tracker.h"
#endif
#if defined(OS_CHROMEOS)
@@ -192,7 +192,7 @@ bool ShutdownPreThreadsStop() {
#if defined(ENABLE_RLZ)
// Cleanup any statics created by RLZ. Must be done before NotificationService
// is destroyed.
- RLZTracker::CleanupRlz();
+ rlz::RLZTracker::CleanupRlz();
#endif
return restart_last_session;
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index b1cfe0b..f9e0181 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -223,7 +223,8 @@
#endif // defined(ENABLE_PRINT_PREVIEW) && !defined(OFFICIAL_BUILD)
#if defined(ENABLE_RLZ)
-#include "chrome/browser/rlz/rlz.h"
+#include "chrome/browser/rlz/chrome_rlz_tracker_delegate.h"
+#include "components/rlz/rlz_tracker.h"
#endif // defined(ENABLE_RLZ)
#if defined(ENABLE_WEBRTC)
@@ -1451,9 +1452,14 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
pref_service->GetInteger(first_run::GetPingDelayPrefName().c_str());
// Negative ping delay means to send ping immediately after a first search is
// recorded.
- RLZTracker::InitRlzFromProfileDelayed(
- profile_, first_run::IsChromeFirstRun(), ping_delay < 0,
- base::TimeDelta::FromMilliseconds(abs(ping_delay)));
+ rlz::RLZTracker::SetRlzDelegate(
+ make_scoped_ptr(new ChromeRLZTrackerDelegate));
+ rlz::RLZTracker::InitRlzDelayed(
+ first_run::IsChromeFirstRun(), ping_delay < 0,
+ base::TimeDelta::FromMilliseconds(abs(ping_delay)),
+ ChromeRLZTrackerDelegate::IsGoogleDefaultSearch(profile_),
+ ChromeRLZTrackerDelegate::IsGoogleHomePage(profile_),
+ ChromeRLZTrackerDelegate::IsGoogleInStartpages(profile_));
#endif // defined(ENABLE_RLZ) && !defined(OS_CHROMEOS)
// Configure modules that need access to resources.
diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
index 32a5835..143e14e 100644
--- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
+++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
@@ -75,7 +75,6 @@
#include "chrome/browser/net/chrome_network_delegate.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
-#include "chrome/browser/rlz/rlz.h"
#include "chrome/browser/ui/ash/network_connect_delegate_chromeos.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
@@ -129,6 +128,10 @@
#include "ui/base/touch/touch_device.h"
#include "ui/events/event_utils.h"
+#if defined(ENABLE_RLZ)
+#include "components/rlz/rlz_tracker.h"
+#endif
+
// Exclude X11 dependents for ozone
#if defined(USE_X11)
#include "chrome/browser/chromeos/device_uma.h"
diff --git a/chrome/browser/chromeos/login/login_utils_browsertest.cc b/chrome/browser/chromeos/login/login_utils_browsertest.cc
index 6025228..53ca423 100644
--- a/chrome/browser/chromeos/login/login_utils_browsertest.cc
+++ b/chrome/browser/chromeos/login/login_utils_browsertest.cc
@@ -14,7 +14,6 @@
#include "chrome/browser/chromeos/login/test/oobe_base_test.h"
#include "chrome/browser/chromeos/login/ui/webui_login_display.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
-#include "chrome/browser/rlz/rlz.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
@@ -29,6 +28,10 @@
#include "net/test/embedded_test_server/http_response.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(ENABLE_RLZ)
+#include "components/rlz/rlz_tracker.h"
+#endif
+
namespace chromeos {
namespace {
@@ -37,7 +40,7 @@ namespace {
void GetAccessPointRlzInBackgroundThread(rlz_lib::AccessPoint point,
base::string16* rlz) {
ASSERT_FALSE(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- ASSERT_TRUE(RLZTracker::GetAccessPointRlz(point, rlz));
+ ASSERT_TRUE(rlz::RLZTracker::GetAccessPointRlz(point, rlz));
}
#endif
@@ -106,10 +109,8 @@ IN_PROC_BROWSER_TEST_P(LoginUtilsTest, RlzInitialized) {
base::RunLoop loop;
base::string16 rlz_string;
content::BrowserThread::PostBlockingPoolTaskAndReply(
- FROM_HERE,
- base::Bind(&GetAccessPointRlzInBackgroundThread,
- RLZTracker::ChromeHomePage(),
- &rlz_string),
+ FROM_HERE, base::Bind(&GetAccessPointRlzInBackgroundThread,
+ rlz::RLZTracker::ChromeHomePage(), &rlz_string),
loop.QuitClosure());
loop.Run();
EXPECT_EQ(base::string16(), rlz_string);
diff --git a/chrome/browser/chromeos/login/session/user_session_manager.cc b/chrome/browser/chromeos/login/session/user_session_manager.cc
index af0f026..5bedab6 100644
--- a/chrome/browser/chromeos/login/session/user_session_manager.cc
+++ b/chrome/browser/chromeos/login/session/user_session_manager.cc
@@ -65,7 +65,6 @@
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
-#include "chrome/browser/rlz/rlz.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/easy_unlock_service.h"
#include "chrome/browser/signin/signin_manager_factory.h"
@@ -101,6 +100,11 @@
#include "ui/base/ime/chromeos/input_method_manager.h"
#include "url/gurl.h"
+#if defined(ENABLE_RLZ)
+#include "chrome/browser/rlz/chrome_rlz_tracker_delegate.h"
+#include "components/rlz/rlz_tracker.h"
+#endif
+
namespace chromeos {
namespace {
@@ -1298,7 +1302,7 @@ void UserSessionManager::InitRlzImpl(Profile* profile, bool disabled) {
}
if (disabled != local_state->GetBoolean(prefs::kRLZDisabled)) {
// When switching to RLZ enabled/disabled state, clear all recorded events.
- RLZTracker::ClearRlzState();
+ rlz::RLZTracker::ClearRlzState();
local_state->SetBoolean(prefs::kRLZDisabled, disabled);
}
// Init the RLZ library.
@@ -1306,11 +1310,14 @@ void UserSessionManager::InitRlzImpl(Profile* profile, bool disabled) {
::first_run::GetPingDelayPrefName().c_str());
// Negative ping delay means to send ping immediately after a first search is
// recorded.
- RLZTracker::InitRlzFromProfileDelayed(
- profile,
- user_manager::UserManager::Get()->IsCurrentUserNew(),
- ping_delay < 0,
- base::TimeDelta::FromMilliseconds(abs(ping_delay)));
+ rlz::RLZTracker::SetRlzDelegate(
+ make_scoped_ptr(new ChromeRLZTrackerDelegate));
+ rlz::RLZTracker::InitRlzDelayed(
+ user_manager::UserManager::Get()->IsCurrentUserNew(), ping_delay < 0,
+ base::TimeDelta::FromMilliseconds(abs(ping_delay)),
+ ChromeRLZTrackerDelegate::IsGoogleDefaultSearch(profile),
+ ChromeRLZTrackerDelegate::IsGoogleHomepage(profile),
+ ChromeRLZTrackerDelegate::IsGoogleInStartpages(profile));
#endif
}
diff --git a/chrome/browser/rlz/chrome_rlz_tracker_delegate.cc b/chrome/browser/rlz/chrome_rlz_tracker_delegate.cc
new file mode 100644
index 0000000..091bac1
--- /dev/null
+++ b/chrome/browser/rlz/chrome_rlz_tracker_delegate.cc
@@ -0,0 +1,236 @@
+// Copyright 2015 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/rlz/chrome_rlz_tracker_delegate.h"
+
+#include "base/command_line.h"
+#include "base/prefs/pref_service.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/google/google_brand.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
+#include "components/google/core/browser/google_util.h"
+#include "components/omnibox/browser/omnibox_log.h"
+#include "components/search_engines/template_url.h"
+#include "components/search_engines/template_url_service.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/navigation_controller.h"
+#include "content/public/browser/navigation_details.h"
+#include "content/public/browser/navigation_entry.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_source.h"
+
+#if defined(OS_WIN)
+#include "chrome/installer/util/google_update_settings.h"
+#endif
+
+#if !defined(OS_IOS)
+#include "chrome/browser/prefs/session_startup_pref.h"
+#include "chrome/browser/ui/startup/startup_browser_creator.h"
+#endif
+
+ChromeRLZTrackerDelegate::ChromeRLZTrackerDelegate() {
+}
+
+ChromeRLZTrackerDelegate::~ChromeRLZTrackerDelegate() {
+}
+
+// static
+bool ChromeRLZTrackerDelegate::IsGoogleDefaultSearch(Profile* profile) {
+ bool is_google_default_search = false;
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(profile);
+ if (template_url_service) {
+ const TemplateURL* url_template =
+ template_url_service->GetDefaultSearchProvider();
+ is_google_default_search = url_template &&
+ url_template->url_ref().HasGoogleBaseURLs(
+ template_url_service->search_terms_data());
+ }
+ return is_google_default_search;
+}
+
+// static
+bool ChromeRLZTrackerDelegate::IsGoogleHomepage(Profile* profile) {
+ return google_util::IsGoogleHomePageUrl(
+ GURL(profile->GetPrefs()->GetString(prefs::kHomePage)));
+}
+
+// static
+bool ChromeRLZTrackerDelegate::IsGoogleInStartpages(Profile* profile) {
+#if !defined(OS_IOS)
+ bool is_google_in_startpages = false;
+ SessionStartupPref session_startup_prefs =
+ StartupBrowserCreator::GetSessionStartupPref(
+ *base::CommandLine::ForCurrentProcess(), profile);
+ if (session_startup_prefs.type == SessionStartupPref::URLS) {
+ is_google_in_startpages =
+ std::count_if(session_startup_prefs.urls.begin(),
+ session_startup_prefs.urls.end(),
+ google_util::IsGoogleHomePageUrl) > 0;
+ }
+ return is_google_in_startpages;
+#else
+ // iOS does not have a notion of startpages.
+ return false;
+#endif
+}
+
+void ChromeRLZTrackerDelegate::Cleanup() {
+ registrar_.RemoveAll();
+ on_omnibox_search_callback_.Reset();
+ on_homepage_search_callback_.Reset();
+}
+
+bool ChromeRLZTrackerDelegate::IsOnUIThread() {
+ return content::BrowserThread::CurrentlyOn(content::BrowserThread::UI);
+}
+
+base::SequencedWorkerPool* ChromeRLZTrackerDelegate::GetBlockingPool() {
+ return content::BrowserThread::GetBlockingPool();
+}
+
+net::URLRequestContextGetter* ChromeRLZTrackerDelegate::GetRequestContext() {
+ return g_browser_process->system_request_context();
+}
+
+bool ChromeRLZTrackerDelegate::GetBrand(std::string* brand) {
+ return google_brand::GetBrand(brand);
+}
+
+bool ChromeRLZTrackerDelegate::IsBrandOrganic(const std::string& brand) {
+ return brand.empty() || google_brand::IsOrganic(brand);
+}
+
+bool ChromeRLZTrackerDelegate::GetReactivationBrand(std::string* brand) {
+ return google_brand::GetReactivationBrand(brand);
+}
+
+bool ChromeRLZTrackerDelegate::ShouldEnableZeroDelayForTesting() {
+ return base::CommandLine::ForCurrentProcess()->HasSwitch(
+ ::switches::kTestType);
+}
+
+bool ChromeRLZTrackerDelegate::GetLanguage(base::string16* language) {
+#if defined(OS_WIN)
+ return GoogleUpdateSettings::GetLanguage(language);
+#else
+ // TODO(thakis): Implement.
+ NOTIMPLEMENTED();
+ return false;
+#endif
+}
+
+bool ChromeRLZTrackerDelegate::GetReferral(base::string16* referral) {
+#if defined(OS_WIN)
+ return GoogleUpdateSettings::GetReferral(referral);
+#else
+ // The referral program is defunct and not used. No need to implement this
+ // function on non-Win platforms.
+ return true;
+#endif
+}
+
+bool ChromeRLZTrackerDelegate::ClearReferral() {
+#if defined(OS_WIN)
+ return GoogleUpdateSettings::ClearReferral();
+#else
+ // The referral program is defunct and not used. No need to implement this
+ // function on non-Win platforms.
+ return true;
+#endif
+}
+
+void ChromeRLZTrackerDelegate::SetOmniboxSearchCallback(
+ const base::Closure& callback) {
+ DCHECK(!callback.is_null());
+ registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
+ content::NotificationService::AllSources());
+ on_omnibox_search_callback_ = callback;
+}
+
+void ChromeRLZTrackerDelegate::SetHomepageSearchCallback(
+ const base::Closure& callback) {
+#if !defined(OS_IOS)
+ DCHECK(!callback.is_null());
+ registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
+ content::NotificationService::AllSources());
+ on_homepage_search_callback_ = callback;
+#endif
+}
+
+void ChromeRLZTrackerDelegate::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ using std::swap;
+ base::Closure callback_to_run;
+ switch (type) {
+ case chrome::NOTIFICATION_OMNIBOX_OPENED_URL:
+ // In M-36, we made NOTIFICATION_OMNIBOX_OPENED_URL fire more often than
+ // it did previously. The RLZ folks want RLZ's "first search" detection
+ // to remain as unaffected as possible by this change. This test is
+ // there to keep the old behavior.
+ if (!content::Details<OmniboxLog>(details).ptr()->is_popup_open)
+ break;
+ registrar_.Remove(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
+ content::NotificationService::AllSources());
+ swap(callback_to_run, on_omnibox_search_callback_);
+ break;
+
+#if !defined(OS_IOS)
+ case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
+ // Firstly check if it is a Google search.
+ content::LoadCommittedDetails* load_details =
+ content::Details<content::LoadCommittedDetails>(details).ptr();
+ if (load_details == nullptr)
+ break;
+
+ content::NavigationEntry* entry = load_details->entry;
+ if (entry == nullptr)
+ break;
+
+ if (google_util::IsGoogleSearchUrl(entry->GetURL())) {
+ // If it is a Google search, check if it originates from HOMEPAGE by
+ // getting the previous NavigationEntry.
+ content::NavigationController* controller =
+ content::Source<content::NavigationController>(source).ptr();
+ if (controller == nullptr)
+ break;
+
+ int entry_index = controller->GetLastCommittedEntryIndex();
+ if (entry_index < 1)
+ break;
+
+ const content::NavigationEntry* previous_entry =
+ controller->GetEntryAtIndex(entry_index - 1);
+
+ if (previous_entry == nullptr)
+ break;
+
+ // Make sure it is a Google web page originated from HOMEPAGE.
+ if (google_util::IsGoogleHomePageUrl(previous_entry->GetURL()) &&
+ ((previous_entry->GetTransitionType() &
+ ui::PAGE_TRANSITION_HOME_PAGE) != 0)) {
+ registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
+ content::NotificationService::AllSources());
+ swap(callback_to_run, on_homepage_search_callback_);
+ }
+ }
+ break;
+ }
+#endif // !defined(OS_IOS)
+
+ default:
+ NOTREACHED();
+ break;
+ }
+
+ if (!callback_to_run.is_null())
+ callback_to_run.Run();
+}
diff --git a/chrome/browser/rlz/chrome_rlz_tracker_delegate.h b/chrome/browser/rlz/chrome_rlz_tracker_delegate.h
new file mode 100644
index 0000000..3494775
--- /dev/null
+++ b/chrome/browser/rlz/chrome_rlz_tracker_delegate.h
@@ -0,0 +1,56 @@
+// Copyright 2015 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_RLZ_CHROME_RLZ_TRACKER_DELEGATE_H_
+#define CHROME_BROWSER_RLZ_CHROME_RLZ_TRACKER_DELEGATE_H_
+
+#include "base/callback_list.h"
+#include "base/macros.h"
+#include "components/rlz/rlz_tracker_delegate.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+
+class Profile;
+
+// ChromeRLZTrackerDelegate implements RLZTrackerDelegate abstract interface
+// and provides access to Chrome features.
+class ChromeRLZTrackerDelegate : public rlz::RLZTrackerDelegate,
+ public content::NotificationObserver {
+ public:
+ ChromeRLZTrackerDelegate();
+ ~ChromeRLZTrackerDelegate() override;
+
+ static bool IsGoogleDefaultSearch(Profile* profile);
+ static bool IsGoogleHomepage(Profile* profile);
+ static bool IsGoogleInStartpages(Profile* profile);
+
+ private:
+ // RLZTrackerDelegate implementation.
+ void Cleanup() override;
+ bool IsOnUIThread() override;
+ base::SequencedWorkerPool* GetBlockingPool() override;
+ net::URLRequestContextGetter* GetRequestContext() override;
+ bool GetBrand(std::string* brand) override;
+ bool IsBrandOrganic(const std::string& brand) override;
+ bool GetReactivationBrand(std::string* brand) override;
+ bool ShouldEnableZeroDelayForTesting() override;
+ bool GetLanguage(base::string16* language) override;
+ bool GetReferral(base::string16* referral) override;
+ bool ClearReferral() override;
+ void SetOmniboxSearchCallback(const base::Closure& callback) override;
+ void SetHomepageSearchCallback(const base::Closure& callback) override;
+
+ // content::NotificationObserver implementation:
+ void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) override;
+
+ content::NotificationRegistrar registrar_;
+ base::Closure on_omnibox_search_callback_;
+ base::Closure on_homepage_search_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeRLZTrackerDelegate);
+};
+
+#endif // CHROME_BROWSER_RLZ_CHROME_RLZ_TRACKER_DELEGATE_H_
diff --git a/chrome/browser/rlz/chrome_rlz_tracker_delegate_unittest.cc b/chrome/browser/rlz/chrome_rlz_tracker_delegate_unittest.cc
new file mode 100644
index 0000000..fd7d6e0
--- /dev/null
+++ b/chrome/browser/rlz/chrome_rlz_tracker_delegate_unittest.cc
@@ -0,0 +1,48 @@
+// 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/rlz/chrome_rlz_tracker_delegate.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "content/public/browser/navigation_details.h"
+#include "content/public/browser/navigation_entry.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_source.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using content::NavigationEntry;
+using content::LoadCommittedDetails;
+
+class ChromeRLZTrackerDelegateTest : public testing::Test {
+ public:
+ ChromeRLZTrackerDelegateTest() : delegate_(new ChromeRLZTrackerDelegate) {}
+ ~ChromeRLZTrackerDelegateTest() override {}
+
+ void SendNotification(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ content::NotificationObserver* observer = delegate_.get();
+ observer->Observe(type, source, details);
+ }
+
+ private:
+ scoped_ptr<ChromeRLZTrackerDelegate> delegate_;
+};
+
+TEST_F(ChromeRLZTrackerDelegateTest, ObserveHandlesBadArgs) {
+ scoped_ptr<content::LoadCommittedDetails> details(
+ new content::LoadCommittedDetails());
+ scoped_ptr<content::NavigationEntry> entry(
+ content::NavigationEntry::Create());
+ details->entry = entry.get();
+ details->entry->SetPageID(0);
+ details->entry->SetTransitionType(ui::PAGE_TRANSITION_LINK);
+ SendNotification(content::NOTIFICATION_NAV_ENTRY_COMMITTED,
+ content::NotificationService::AllSources(),
+ content::Details<NavigationEntry>(nullptr));
+ SendNotification(content::NOTIFICATION_NAV_ENTRY_COMMITTED,
+ content::NotificationService::AllSources(),
+ content::Details<LoadCommittedDetails>(details.get()));
+}
diff --git a/chrome/browser/rlz/rlz.cc b/chrome/browser/rlz/rlz.cc
deleted file mode 100644
index 94064d2..0000000
--- a/chrome/browser/rlz/rlz.cc
+++ /dev/null
@@ -1,670 +0,0 @@
-// 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.
-//
-// This code glues the RLZ library DLL with Chrome. It allows Chrome to work
-// with or without the DLL being present. If the DLL is not present the
-// functions do nothing and just return false.
-
-#include "chrome/browser/rlz/rlz.h"
-
-#include <algorithm>
-
-#include "base/bind.h"
-#include "base/command_line.h"
-#include "base/message_loop/message_loop.h"
-#include "base/prefs/pref_service.h"
-#include "base/strings/string_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/trace_event/trace_event.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/google/google_brand.h"
-#include "chrome/browser/prefs/session_startup_pref.h"
-#include "chrome/browser/search_engines/template_url_service_factory.h"
-#include "chrome/browser/ui/startup/startup_browser_creator.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/common/pref_names.h"
-#include "components/google/core/browser/google_util.h"
-#include "components/omnibox/browser/omnibox_log.h"
-#include "components/search_engines/template_url.h"
-#include "components/search_engines/template_url_service.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/navigation_controller.h"
-#include "content/public/browser/navigation_details.h"
-#include "content/public/browser/navigation_entry.h"
-#include "content/public/browser/notification_service.h"
-#include "net/http/http_util.h"
-
-#if defined(OS_WIN)
-#include "chrome/installer/util/google_update_settings.h"
-#else
-namespace GoogleUpdateSettings {
-static bool GetLanguage(base::string16* language) {
- // TODO(thakis): Implement.
- NOTIMPLEMENTED();
- return false;
-}
-
-// The referral program is defunct and not used. No need to implement these
-// functions on non-Win platforms.
-static bool GetReferral(base::string16* referral) {
- return true;
-}
-static bool ClearReferral() {
- return true;
-}
-} // namespace GoogleUpdateSettings
-#endif
-
-using content::BrowserThread;
-using content::NavigationEntry;
-using content::NavigationController;
-
-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 base::TimeDelta kMaxInitDelay = base::TimeDelta::FromSeconds(200);
-const base::TimeDelta kMinInitDelay = base::TimeDelta::FromSeconds(20);
-
-bool IsBrandOrganic(const std::string& brand) {
- return brand.empty() || google_brand::IsOrganic(brand);
-}
-
-void RecordProductEvents(bool first_run,
- bool is_google_default_search,
- bool is_google_homepage,
- bool is_google_in_startpages,
- bool already_ran,
- bool omnibox_used,
- bool homepage_used,
- bool app_list_used) {
- TRACE_EVENT0("RLZ", "RecordProductEvents");
- // Record the installation of chrome. We call this all the time but the rlz
- // lib should ignore all but the first one.
- rlz_lib::RecordProductEvent(rlz_lib::CHROME,
- RLZTracker::ChromeOmnibox(),
- rlz_lib::INSTALL);
-#if !defined(OS_IOS)
- rlz_lib::RecordProductEvent(rlz_lib::CHROME,
- RLZTracker::ChromeHomePage(),
- rlz_lib::INSTALL);
- rlz_lib::RecordProductEvent(rlz_lib::CHROME,
- RLZTracker::ChromeAppList(),
- rlz_lib::INSTALL);
-#endif // !defined(OS_IOS)
-
- if (!already_ran) {
- // Do the initial event recording if is the first run or if we have an
- // empty rlz which means we haven't got a chance to do it.
- char omnibox_rlz[rlz_lib::kMaxRlzLength + 1];
- if (!rlz_lib::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), omnibox_rlz,
- rlz_lib::kMaxRlzLength)) {
- omnibox_rlz[0] = 0;
- }
-
- // Record if google is the initial search provider and/or home page.
- if ((first_run || omnibox_rlz[0] == 0) && is_google_default_search) {
- rlz_lib::RecordProductEvent(rlz_lib::CHROME,
- RLZTracker::ChromeOmnibox(),
- rlz_lib::SET_TO_GOOGLE);
- }
-
-#if !defined(OS_IOS)
- char homepage_rlz[rlz_lib::kMaxRlzLength + 1];
- if (!rlz_lib::GetAccessPointRlz(RLZTracker::ChromeHomePage(), homepage_rlz,
- rlz_lib::kMaxRlzLength)) {
- homepage_rlz[0] = 0;
- }
-
- if ((first_run || homepage_rlz[0] == 0) &&
- (is_google_homepage || is_google_in_startpages)) {
- rlz_lib::RecordProductEvent(rlz_lib::CHROME,
- RLZTracker::ChromeHomePage(),
- rlz_lib::SET_TO_GOOGLE);
- }
-
- char app_list_rlz[rlz_lib::kMaxRlzLength + 1];
- if (!rlz_lib::GetAccessPointRlz(RLZTracker::ChromeAppList(), app_list_rlz,
- rlz_lib::kMaxRlzLength)) {
- app_list_rlz[0] = 0;
- }
-
- // Record if google is the initial search provider and/or home page.
- if ((first_run || app_list_rlz[0] == 0) && is_google_default_search) {
- rlz_lib::RecordProductEvent(rlz_lib::CHROME,
- RLZTracker::ChromeAppList(),
- rlz_lib::SET_TO_GOOGLE);
- }
-#endif // !defined(OS_IOS)
- }
-
- // Record first user interaction with the omnibox. We call this all the
- // time but the rlz lib should ingore all but the first one.
- if (omnibox_used) {
- rlz_lib::RecordProductEvent(rlz_lib::CHROME,
- RLZTracker::ChromeOmnibox(),
- rlz_lib::FIRST_SEARCH);
- }
-
-#if !defined(OS_IOS)
- // Record first user interaction with the home page. We call this all the
- // time but the rlz lib should ingore all but the first one.
- if (homepage_used || is_google_in_startpages) {
- rlz_lib::RecordProductEvent(rlz_lib::CHROME,
- RLZTracker::ChromeHomePage(),
- rlz_lib::FIRST_SEARCH);
- }
-
- // Record first user interaction with the app list. We call this all the
- // time but the rlz lib should ingore all but the first one.
- if (app_list_used) {
- rlz_lib::RecordProductEvent(rlz_lib::CHROME,
- RLZTracker::ChromeAppList(),
- rlz_lib::FIRST_SEARCH);
- }
-#endif // !defined(OS_IOS)
-}
-
-bool SendFinancialPing(const std::string& brand,
- const base::string16& lang,
- const base::string16& referral) {
- rlz_lib::AccessPoint points[] = {RLZTracker::ChromeOmnibox(),
-#if !defined(OS_IOS)
- RLZTracker::ChromeHomePage(),
- RLZTracker::ChromeAppList(),
-#endif
- rlz_lib::NO_ACCESS_POINT};
- std::string lang_ascii(base::UTF16ToASCII(lang));
- std::string referral_ascii(base::UTF16ToASCII(referral));
- std::string product_signature;
-#if defined(OS_CHROMEOS)
- product_signature = "chromeos";
-#else
- product_signature = "chrome";
-#endif
- return rlz_lib::SendFinancialPing(rlz_lib::CHROME, points,
- product_signature.c_str(),
- brand.c_str(), referral_ascii.c_str(),
- lang_ascii.c_str(), false, true);
-}
-
-} // namespace
-
-RLZTracker* RLZTracker::tracker_ = NULL;
-
-// static
-RLZTracker* RLZTracker::GetInstance() {
- return tracker_ ? tracker_ : Singleton<RLZTracker>::get();
-}
-
-RLZTracker::RLZTracker()
- : first_run_(false),
- send_ping_immediately_(false),
- 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),
- app_list_used_(false),
- min_init_delay_(kMinInitDelay) {
-}
-
-RLZTracker::~RLZTracker() {
-}
-
-// static
-bool RLZTracker::InitRlzDelayed(bool first_run,
- bool send_ping_immediately,
- base::TimeDelta delay,
- bool is_google_default_search,
- bool is_google_homepage,
- bool is_google_in_startpages) {
- return GetInstance()->Init(first_run, send_ping_immediately, delay,
- is_google_default_search, is_google_homepage,
- is_google_in_startpages);
-}
-
-// static
-bool RLZTracker::InitRlzFromProfileDelayed(Profile* profile,
- bool first_run,
- bool send_ping_immediately,
- base::TimeDelta delay) {
- bool is_google_default_search = false;
- TemplateURLService* template_url_service =
- TemplateURLServiceFactory::GetForProfile(profile);
- if (template_url_service) {
- const TemplateURL* url_template =
- template_url_service->GetDefaultSearchProvider();
- is_google_default_search =
- url_template && url_template->url_ref().HasGoogleBaseURLs(
- template_url_service->search_terms_data());
- }
-
- PrefService* pref_service = profile->GetPrefs();
- bool is_google_homepage = google_util::IsGoogleHomePageUrl(
- GURL(pref_service->GetString(prefs::kHomePage)));
-
- bool is_google_in_startpages = false;
-#if !defined(OS_IOS)
- // iOS does not have a notion of startpages.
- SessionStartupPref session_startup_prefs =
- StartupBrowserCreator::GetSessionStartupPref(
- *base::CommandLine::ForCurrentProcess(), profile);
- if (session_startup_prefs.type == SessionStartupPref::URLS) {
- is_google_in_startpages =
- std::count_if(session_startup_prefs.urls.begin(),
- session_startup_prefs.urls.end(),
- google_util::IsGoogleHomePageUrl) > 0;
- }
-#endif
-
- if (!InitRlzDelayed(first_run, send_ping_immediately, delay,
- is_google_default_search, is_google_homepage,
- is_google_in_startpages)) {
- return false;
- }
-
-#if !defined(OS_IOS)
- // Prime the RLZ cache for the home page access point so that its avaiable
- // for the startup page if needed (i.e., when the startup page is set to
- // the home page).
- GetAccessPointRlz(ChromeHomePage(), NULL);
-#endif // !defined(OS_IOS)
-
- return true;
-}
-
-bool RLZTracker::Init(bool first_run,
- bool send_ping_immediately,
- base::TimeDelta delay,
- bool is_google_default_search,
- bool is_google_homepage,
- bool is_google_in_startpages) {
- first_run_ = first_run;
- is_google_default_search_ = is_google_default_search;
- is_google_homepage_ = is_google_homepage;
- is_google_in_startpages_ = is_google_in_startpages;
- send_ping_immediately_ = send_ping_immediately;
-
- // Enable zero delays for testing.
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType))
- EnableZeroDelayForTesting();
-
- delay = std::min(kMaxInitDelay, std::max(min_init_delay_, delay));
-
- if (google_brand::GetBrand(&brand_) && !IsBrandOrganic(brand_)) {
- // Register for notifications from the omnibox so that we can record when
- // the user performs a first search.
- registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
- content::NotificationService::AllSources());
-
-#if !defined(OS_IOS)
- // Register for notifications from navigations, to see if the user has used
- // the home page.
- registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- content::NotificationService::AllSources());
-#endif // !defined(OS_IOS)
- }
- google_brand::GetReactivationBrand(&reactivation_brand_);
-
- net::URLRequestContextGetter* context_getter =
- g_browser_process->system_request_context();
-
- // Could be NULL; don't run if so. RLZ will try again next restart.
- if (context_getter) {
- rlz_lib::SetURLRequestContext(context_getter);
- ScheduleDelayedInit(delay);
- }
-
- return true;
-}
-
-void RLZTracker::ScheduleDelayedInit(base::TimeDelta delay) {
- // The RLZTracker is a singleton object that outlives any runnable tasks
- // that will be queued up.
- BrowserThread::GetBlockingPool()->PostDelayedSequencedWorkerTask(
- worker_pool_token_,
- FROM_HERE,
- base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)),
- delay);
-}
-
-void RLZTracker::DelayedInit() {
- bool schedule_ping = false;
-
- // For organic brandcodes do not use rlz at all. Empty brandcode usually
- // means a chromium install. This is ok.
- if (!IsBrandOrganic(brand_)) {
- RecordProductEvents(first_run_, is_google_default_search_,
- is_google_homepage_, is_google_in_startpages_,
- already_ran_, omnibox_used_, homepage_used_,
- app_list_used_);
- schedule_ping = true;
- }
-
- // If chrome has been reactivated, record the events for this brand
- // as well.
- if (!IsBrandOrganic(reactivation_brand_)) {
- rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str());
- RecordProductEvents(first_run_, is_google_default_search_,
- is_google_homepage_, is_google_in_startpages_,
- already_ran_, omnibox_used_, homepage_used_,
- app_list_used_);
- schedule_ping = true;
- }
-
- already_ran_ = true;
-
- if (schedule_ping)
- ScheduleFinancialPing();
-}
-
-void RLZTracker::ScheduleFinancialPing() {
- BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior(
- worker_pool_token_,
- FROM_HERE,
- base::Bind(&RLZTracker::PingNowImpl, base::Unretained(this)),
- base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
-}
-
-void RLZTracker::PingNowImpl() {
- TRACE_EVENT0("RLZ", "RLZTracker::PingNowImpl");
- base::string16 lang;
- GoogleUpdateSettings::GetLanguage(&lang);
- if (lang.empty())
- lang = base::ASCIIToUTF16("en");
- base::string16 referral;
- GoogleUpdateSettings::GetReferral(&referral);
-
- if (!IsBrandOrganic(brand_) && SendFinancialPing(brand_, lang, referral)) {
- GoogleUpdateSettings::ClearReferral();
-
- {
- base::AutoLock lock(cache_lock_);
- rlz_cache_.clear();
- }
-
- // Prime the RLZ cache for the access points we are interested in.
- GetAccessPointRlz(RLZTracker::ChromeOmnibox(), NULL);
-#if !defined(OS_IOS)
- GetAccessPointRlz(RLZTracker::ChromeHomePage(), NULL);
- GetAccessPointRlz(RLZTracker::ChromeAppList(), NULL);
-#endif // !defined(OS_IOS)
- }
-
- if (!IsBrandOrganic(reactivation_brand_)) {
- rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str());
- SendFinancialPing(reactivation_brand_, lang, referral);
- }
-}
-
-bool RLZTracker::SendFinancialPing(const std::string& brand,
- const base::string16& lang,
- const base::string16& referral) {
- return ::SendFinancialPing(brand, lang, referral);
-}
-
-void RLZTracker::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- switch (type) {
- case chrome::NOTIFICATION_OMNIBOX_OPENED_URL:
- // In M-36, we made NOTIFICATION_OMNIBOX_OPENED_URL fire more often than
- // it did previously. The RLZ folks want RLZ's "first search" detection
- // to remain as unaffected as possible by this change. This test is
- // there to keep the old behavior.
- if (!content::Details<OmniboxLog>(details).ptr()->is_popup_open)
- break;
- RecordFirstSearch(ChromeOmnibox());
- registrar_.Remove(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
- content::NotificationService::AllSources());
- break;
-#if !defined(OS_IOS)
- case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
- // Firstly check if it is a Google search.
- content::LoadCommittedDetails* load_details =
- content::Details<content::LoadCommittedDetails>(details).ptr();
- if (load_details == NULL)
- break;
-
- NavigationEntry* entry = load_details->entry;
- if (entry == NULL)
- break;
-
- if (google_util::IsGoogleSearchUrl(entry->GetURL())) {
- // If it is a Google search, check if it originates from HOMEPAGE by
- // getting the previous NavigationEntry.
- NavigationController* controller =
- content::Source<NavigationController>(source).ptr();
- if (controller == NULL)
- break;
-
- int entry_index = controller->GetLastCommittedEntryIndex();
- if (entry_index < 1)
- break;
-
- const NavigationEntry* previous_entry = controller->GetEntryAtIndex(
- entry_index - 1);
-
- if (previous_entry == NULL)
- break;
-
- // Make sure it is a Google web page originated from HOMEPAGE.
- if (google_util::IsGoogleHomePageUrl(previous_entry->GetURL()) &&
- ((previous_entry->GetTransitionType() &
- ui::PAGE_TRANSITION_HOME_PAGE) != 0)) {
- RecordFirstSearch(ChromeHomePage());
- registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- content::NotificationService::AllSources());
- }
- }
- break;
- }
-#endif // !defined(OS_IOS)
- default:
- NOTREACHED();
- break;
- }
-}
-
-// static
-bool RLZTracker::RecordProductEvent(rlz_lib::Product product,
- rlz_lib::AccessPoint point,
- rlz_lib::Event event_id) {
- return GetInstance()->RecordProductEventImpl(product, point, event_id);
-}
-
-bool RLZTracker::RecordProductEventImpl(rlz_lib::Product product,
- rlz_lib::AccessPoint point,
- rlz_lib::Event event_id) {
- // Make sure we don't access disk outside of the I/O thread.
- // In such case we repost the task on the right thread and return error.
- if (ScheduleRecordProductEvent(product, point, event_id))
- return true;
-
- bool ret = rlz_lib::RecordProductEvent(product, point, event_id);
-
- // If chrome has been reactivated, record the event for this brand as well.
- if (!reactivation_brand_.empty()) {
- rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str());
- ret &= rlz_lib::RecordProductEvent(product, point, event_id);
- }
-
- return ret;
-}
-
-bool RLZTracker::ScheduleRecordProductEvent(rlz_lib::Product product,
- rlz_lib::AccessPoint point,
- rlz_lib::Event event_id) {
- if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
- return false;
-
- BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior(
- worker_pool_token_,
- FROM_HERE,
- base::Bind(base::IgnoreResult(&RLZTracker::RecordProductEvent),
- product, point, event_id),
- base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
-
- return true;
-}
-
-void RLZTracker::RecordFirstSearch(rlz_lib::AccessPoint point) {
- // Make sure we don't access disk outside of the I/O thread.
- // In such case we repost the task on the right thread and return error.
- if (ScheduleRecordFirstSearch(point))
- return;
-
- bool* record_used = GetAccessPointRecord(point);
-
- // Try to record event now, else set the flag to try later when we
- // attempt the ping.
- if (!RecordProductEvent(rlz_lib::CHROME, point, rlz_lib::FIRST_SEARCH))
- *record_used = true;
- else if (send_ping_immediately_ && point == ChromeOmnibox())
- ScheduleDelayedInit(base::TimeDelta());
-}
-
-bool RLZTracker::ScheduleRecordFirstSearch(rlz_lib::AccessPoint point) {
- if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
- return false;
- BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior(
- worker_pool_token_,
- FROM_HERE,
- base::Bind(&RLZTracker::RecordFirstSearch,
- base::Unretained(this), point),
- base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
- return true;
-}
-
-bool* RLZTracker::GetAccessPointRecord(rlz_lib::AccessPoint point) {
- if (point == ChromeOmnibox())
- return &omnibox_used_;
-#if !defined(OS_IOS)
- if (point == ChromeHomePage())
- return &homepage_used_;
- if (point == ChromeAppList())
- return &app_list_used_;
-#endif // !defined(OS_IOS)
- NOTREACHED();
- return NULL;
-}
-
-// static
-std::string RLZTracker::GetAccessPointHttpHeader(rlz_lib::AccessPoint point) {
- TRACE_EVENT0("RLZ", "RLZTracker::GetAccessPointHttpHeader");
- std::string extra_headers;
- base::string16 rlz_string;
- RLZTracker::GetAccessPointRlz(point, &rlz_string);
- if (!rlz_string.empty()) {
- net::HttpUtil::AppendHeaderIfMissing("X-Rlz-String",
- base::UTF16ToUTF8(rlz_string),
- &extra_headers);
- }
-
- return extra_headers;
-}
-
-// GetAccessPointRlz() caches RLZ strings for all access points. If we had
-// a successful ping, then we update the cached value.
-bool RLZTracker::GetAccessPointRlz(rlz_lib::AccessPoint point,
- base::string16* rlz) {
- TRACE_EVENT0("RLZ", "RLZTracker::GetAccessPointRlz");
- return GetInstance()->GetAccessPointRlzImpl(point, rlz);
-}
-
-// GetAccessPointRlz() caches RLZ strings for all access points. If we had
-// a successful ping, then we update the cached value.
-bool RLZTracker::GetAccessPointRlzImpl(rlz_lib::AccessPoint point,
- base::string16* rlz) {
- // If the RLZ string for the specified access point is already cached,
- // simply return its value.
- {
- base::AutoLock lock(cache_lock_);
- if (rlz_cache_.find(point) != rlz_cache_.end()) {
- if (rlz)
- *rlz = rlz_cache_[point];
- return true;
- }
- }
-
- // Make sure we don't access disk outside of the I/O thread.
- // In such case we repost the task on the right thread and return error.
- if (ScheduleGetAccessPointRlz(point))
- return false;
-
- char str_rlz[rlz_lib::kMaxRlzLength + 1];
- if (!rlz_lib::GetAccessPointRlz(point, str_rlz, rlz_lib::kMaxRlzLength))
- return false;
-
- base::string16 rlz_local(base::ASCIIToUTF16(str_rlz));
- if (rlz)
- *rlz = rlz_local;
-
- base::AutoLock lock(cache_lock_);
- rlz_cache_[point] = rlz_local;
- return true;
-}
-
-bool RLZTracker::ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) {
- if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
- return false;
-
- base::string16* not_used = NULL;
- BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior(
- worker_pool_token_,
- FROM_HERE,
- base::Bind(base::IgnoreResult(&RLZTracker::GetAccessPointRlz), point,
- not_used),
- base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
- return true;
-}
-
-#if defined(OS_CHROMEOS)
-// static
-void RLZTracker::ClearRlzState() {
- GetInstance()->ClearRlzStateImpl();
-}
-
-void RLZTracker::ClearRlzStateImpl() {
- if (ScheduleClearRlzState())
- return;
- rlz_lib::ClearAllProductEvents(rlz_lib::CHROME);
-}
-
-bool RLZTracker::ScheduleClearRlzState() {
- if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
- return false;
-
- BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior(
- worker_pool_token_,
- FROM_HERE,
- base::Bind(&RLZTracker::ClearRlzStateImpl,
- base::Unretained(this)),
- base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
- return true;
-}
-#endif
-
-// static
-void RLZTracker::CleanupRlz() {
- GetInstance()->rlz_cache_.clear();
- GetInstance()->registrar_.RemoveAll();
- rlz_lib::SetURLRequestContext(NULL);
-}
-
-// static
-void RLZTracker::EnableZeroDelayForTesting() {
- GetInstance()->min_init_delay_ = base::TimeDelta();
-}
-
-#if !defined(OS_IOS)
-// static
-void RLZTracker::RecordAppListSearch() {
- GetInstance()->RecordFirstSearch(RLZTracker::ChromeAppList());
-}
-#endif
diff --git a/chrome/browser/rlz/rlz.h b/chrome/browser/rlz/rlz.h
deleted file mode 100644
index 4fd9b9c..0000000
--- a/chrome/browser/rlz/rlz.h
+++ /dev/null
@@ -1,246 +0,0 @@
-// 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_RLZ_RLZ_H_
-#define CHROME_BROWSER_RLZ_RLZ_H_
-
-#include "build/build_config.h"
-
-#if defined(ENABLE_RLZ)
-
-#include <map>
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/memory/singleton.h"
-#include "base/strings/string16.h"
-#include "base/threading/sequenced_worker_pool.h"
-#include "base/time/time.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
-#include "rlz/lib/rlz_lib.h"
-
-class Profile;
-namespace net {
-class URLRequestContextGetter;
-}
-
-// RLZ is a library which is used to measure distribution scenarios.
-// Its job is to record certain lifetime events in the registry and to send
-// them encoded as a compact string at most twice. The sent data does
-// not contain information that can be used to identify a user or to infer
-// browsing habits. The API in this file is a wrapper around the open source
-// RLZ library which can be found at http://code.google.com/p/rlz.
-//
-// For partner or bundled installs, the RLZ might send more information
-// according to the terms disclosed in the EULA.
-
-class RLZTracker : public content::NotificationObserver {
- public:
- // Initializes the RLZ library services for use in chrome. Schedules a delayed
- // task that performs the ping and registers some events when 'first-run' is
- // true.
- //
- // When |send_ping_immediately| is true, a financial ping should be sent
- // immediately after a first search is recorded, without waiting for |delay|.
- // However, we only want this behaviour on first run.
- //
- // If the chrome brand is organic (no partners) then the pings don't occur.
- static bool InitRlzFromProfileDelayed(Profile* profile,
- bool first_run,
- bool send_ping_immediately,
- base::TimeDelta delay);
-
- // Records an RLZ event. Some events can be access point independent.
- // Returns false it the event could not be recorded. Requires write access
- // to the HKCU registry hive on windows.
- static bool RecordProductEvent(rlz_lib::Product product,
- rlz_lib::AccessPoint point,
- rlz_lib::Event event_id);
-
- // For the point parameter of RecordProductEvent.
- static rlz_lib::AccessPoint ChromeOmnibox();
-#if !defined(OS_IOS)
- static rlz_lib::AccessPoint ChromeHomePage();
- static rlz_lib::AccessPoint ChromeAppList();
-#endif
-
- // Gets the HTTP header value that can be added to requests from the
- // specific access point. The string returned is of the form:
- //
- // "X-Rlz-String: <access-point-rlz>\r\n"
- //
- static std::string GetAccessPointHttpHeader(rlz_lib::AccessPoint point);
-
- // Gets the RLZ value of the access point.
- // Returns false if the rlz string could not be obtained. In some cases
- // an empty string can be returned which is not an error.
- static bool GetAccessPointRlz(rlz_lib::AccessPoint point,
- base::string16* rlz);
-
- // Invoked during shutdown to clean up any state created by RLZTracker.
- static void CleanupRlz();
-
-#if defined(OS_CHROMEOS)
- // Clears all product state. Should be called when turning RLZ off. On other
- // platforms, this is done by product uninstaller.
- static void ClearRlzState();
-#endif
-
- // This method is public for use by the Singleton class.
- static RLZTracker* GetInstance();
-
- // Enables zero delay for InitRlzFromProfileDelayed. For testing only.
- static void EnableZeroDelayForTesting();
-
-#if !defined(OS_IOS)
- // Records that the app list search has been used.
- static void RecordAppListSearch();
-#endif
-
- // The following methods are made protected so that they can be used for
- // testing purposes. Production code should never need to call these.
- protected:
- RLZTracker();
- ~RLZTracker() override;
-
- // Called by InitRlzFromProfileDelayed with values taken from |profile|.
- static bool InitRlzDelayed(bool first_run,
- bool send_ping_immediately,
- base::TimeDelta delay,
- bool is_google_default_search,
- bool is_google_homepage,
- bool is_google_in_startpages);
-
- // Performs initialization of RLZ tracker that is purposefully delayed so
- // that it does not interfere with chrome startup time.
- virtual void DelayedInit();
-
- // content::NotificationObserver implementation:
- void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
-
- // Used by test code to override the default RLZTracker instance returned
- // by GetInstance().
- void set_tracker(RLZTracker* tracker) {
- tracker_ = tracker;
- }
-
- // Sends the financial ping to the RLZ servers and invalidates the RLZ string
- // cache since the response from the RLZ server may have changed then.
- // Protected so that its accessible from tests.
- void PingNowImpl();
-
- private:
- friend struct DefaultSingletonTraits<RLZTracker>;
- friend class base::RefCountedThreadSafe<RLZTracker>;
-
- // Implementation called from InitRlzDelayed() static method.
- bool Init(bool first_run,
- bool send_ping_immediately,
- base::TimeDelta delay,
- bool google_default_search,
- bool google_default_homepage,
- bool is_google_in_startpages);
-
- // Implementation called from RecordProductEvent() static method.
- bool RecordProductEventImpl(rlz_lib::Product product,
- rlz_lib::AccessPoint point,
- rlz_lib::Event event_id);
-
- // Records FIRST_SEARCH event. Called from Observe() on blocking task runner.
- void RecordFirstSearch(rlz_lib::AccessPoint point);
-
- // Implementation called from GetAccessPointRlz() static method.
- bool GetAccessPointRlzImpl(rlz_lib::AccessPoint point, base::string16* rlz);
-
- // Schedules the delayed initialization. This method is virtual to allow
- // tests to override how the scheduling is done.
- virtual void ScheduleDelayedInit(base::TimeDelta delay);
-
- // Schedules a call to rlz_lib::RecordProductEvent(). This method is virtual
- // to allow tests to override how the scheduling is done.
- virtual bool ScheduleRecordProductEvent(rlz_lib::Product product,
- rlz_lib::AccessPoint point,
- rlz_lib::Event event_id);
-
- // Schedules a call to rlz_lib::RecordFirstSearch(). This method is virtual
- // to allow tests to override how the scheduling is done.
- virtual bool ScheduleRecordFirstSearch(rlz_lib::AccessPoint point);
-
- // Schedules a call to rlz_lib::SendFinancialPing(). This method is virtual
- // to allow tests to override how the scheduling is done.
- virtual void ScheduleFinancialPing();
-
- // Schedules a call to GetAccessPointRlz() on the I/O thread if the current
- // thread is not already the I/O thread, otherwise does nothing. Returns
- // true if the call was scheduled, and false otherwise. This method is
- // virtual to allow tests to override how the scheduling is done.
- virtual bool ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point);
-
- // Sends the financial ping to the RLZ servers. This method is virtual to
- // allow tests to override.
- virtual bool SendFinancialPing(const std::string& brand,
- const base::string16& lang,
- const base::string16& referral);
-
-#if defined(OS_CHROMEOS)
- // Implementation called from ClearRlzState static method.
- void ClearRlzStateImpl();
-
- // Schedules a call to ClearRlzStateImpl(). This method is virtual
- // to allow tests to override how the scheduling is done.
- virtual bool ScheduleClearRlzState();
-#endif
-
- // Returns a pointer to the bool corresponding to whether |point| has been
- // used but not reported.
- bool* GetAccessPointRecord(rlz_lib::AccessPoint point);
-
- // Tracker used for testing purposes only. If this value is non-NULL, it
- // will be returned from GetInstance() instead of the regular singleton.
- static RLZTracker* tracker_;
-
- // Configuation data for RLZ tracker. Set by call to Init().
- bool first_run_;
- bool send_ping_immediately_;
- bool is_google_default_search_;
- bool is_google_homepage_;
- bool is_google_in_startpages_;
-
- // Unique sequence token so that tasks posted by RLZTracker are executed
- // sequentially in the blocking pool.
- base::SequencedWorkerPool::SequenceToken worker_pool_token_;
-
- // Keeps track if the RLZ tracker has already performed its delayed
- // initialization.
- bool already_ran_;
-
- // Keeps a cache of RLZ access point strings, since they rarely change.
- // The cache must be protected by a lock since it may be accessed from
- // the UI thread for reading and the IO thread for reading and/or writing.
- base::Lock cache_lock_;
- std::map<rlz_lib::AccessPoint, base::string16> rlz_cache_;
-
- // Keeps track of whether the omnibox, home page or app list have been used.
- bool omnibox_used_;
- bool homepage_used_;
- bool app_list_used_;
-
- // Main and (optionally) reactivation brand codes, assigned on UI thread.
- std::string brand_;
- std::string reactivation_brand_;
-
- content::NotificationRegistrar registrar_;
-
- // Minimum delay before sending financial ping after initialization.
- base::TimeDelta min_init_delay_;
-
- DISALLOW_COPY_AND_ASSIGN(RLZTracker);
-};
-
-#endif // defined(ENABLE_RLZ)
-
-#endif // CHROME_BROWSER_RLZ_RLZ_H_
diff --git a/chrome/browser/rlz/rlz_chromeos.cc b/chrome/browser/rlz/rlz_chromeos.cc
deleted file mode 100644
index 8f9a874..0000000
--- a/chrome/browser/rlz/rlz_chromeos.cc
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2014 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/rlz/rlz.h"
-
-// static
-rlz_lib::AccessPoint RLZTracker::ChromeOmnibox() {
- return rlz_lib::CHROMEOS_OMNIBOX;
-}
-
-// static
-rlz_lib::AccessPoint RLZTracker::ChromeHomePage() {
- return rlz_lib::CHROMEOS_HOME_PAGE;
-}
-
-// static
-rlz_lib::AccessPoint RLZTracker::ChromeAppList() {
- return rlz_lib::CHROMEOS_APP_LIST;
-}
diff --git a/chrome/browser/rlz/rlz_ios.mm b/chrome/browser/rlz/rlz_ios.mm
deleted file mode 100644
index 7af1f59..0000000
--- a/chrome/browser/rlz/rlz_ios.mm
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2014 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/rlz/rlz.h"
-
-#import <UIKit/UIKit.h>
-
-// static
-rlz_lib::AccessPoint RLZTracker::ChromeOmnibox() {
- return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone
- ? rlz_lib::CHROME_IOS_OMNIBOX_MOBILE
- : rlz_lib::CHROME_IOS_OMNIBOX_TABLET;
-}
diff --git a/chrome/browser/rlz/rlz_mac.cc b/chrome/browser/rlz/rlz_mac.cc
deleted file mode 100644
index d3e32a9..0000000
--- a/chrome/browser/rlz/rlz_mac.cc
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2014 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/rlz/rlz.h"
-
-// static
-rlz_lib::AccessPoint RLZTracker::ChromeOmnibox() {
- return rlz_lib::CHROME_MAC_OMNIBOX;
-}
-
-// static
-rlz_lib::AccessPoint RLZTracker::ChromeHomePage() {
- return rlz_lib::CHROME_MAC_HOME_PAGE;
-}
-
-// static
-rlz_lib::AccessPoint RLZTracker::ChromeAppList() {
- return rlz_lib::CHROME_MAC_APP_LIST;
-}
diff --git a/chrome/browser/rlz/rlz_unittest.cc b/chrome/browser/rlz/rlz_unittest.cc
deleted file mode 100644
index 8aeb09c..0000000
--- a/chrome/browser/rlz/rlz_unittest.cc
+++ /dev/null
@@ -1,925 +0,0 @@
-// 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/rlz/rlz.h"
-
-#include "base/memory/scoped_ptr.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/time/time.h"
-#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/google/google_brand.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/installer/util/browser_distribution.h"
-#include "chrome/installer/util/google_update_constants.h"
-#include "chrome/test/base/chrome_render_view_host_test_harness.h"
-#include "components/metrics/proto/omnibox_event.pb.h"
-#include "components/omnibox/browser/autocomplete_controller.h"
-#include "components/omnibox/browser/omnibox_log.h"
-#include "content/public/browser/navigation_details.h"
-#include "content/public/browser/navigation_entry.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_service.h"
-#include "content/public/browser/notification_source.h"
-#include "content/public/test/test_renderer_host.h"
-#include "rlz/test/rlz_test_helpers.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "url/gurl.h"
-
-#if defined(OS_WIN)
-#include "base/win/registry.h"
-#endif
-
-using content::NavigationEntry;
-using content::LoadCommittedDetails;
-using testing::AssertionResult;
-using testing::AssertionSuccess;
-using testing::AssertionFailure;
-
-#if defined(OS_WIN)
-using base::win::RegKey;
-#endif
-
-namespace {
-
-// Dummy RLZ string for the access points.
-const char kOmniboxRlzString[] = "test_omnibox";
-const char kHomepageRlzString[] = "test_homepage";
-const char kAppListRlzString[] = "test_applist";
-const char kNewOmniboxRlzString[] = "new_omnibox";
-const char kNewHomepageRlzString[] = "new_homepage";
-const char kNewAppListRlzString[] = "new_applist";
-
-// Some helper macros to test it a string contains/does not contain a substring.
-
-AssertionResult CmpHelperSTRC(const char* str_expression,
- const char* substr_expression,
- const char* str,
- const char* substr) {
- if (NULL != strstr(str, substr)) {
- return AssertionSuccess();
- }
-
- return AssertionFailure() << "Expected: (" << substr_expression << ") in ("
- << str_expression << "), actual: '"
- << substr << "' not in '" << str << "'";
-}
-
-AssertionResult CmpHelperSTRNC(const char* str_expression,
- const char* substr_expression,
- const char* str,
- const char* substr) {
- if (NULL == strstr(str, substr)) {
- return AssertionSuccess();
- }
-
- return AssertionFailure() << "Expected: (" << substr_expression
- << ") not in (" << str_expression << "), actual: '"
- << substr << "' in '" << str << "'";
-}
-
-#define EXPECT_STR_CONTAINS(str, substr) \
- EXPECT_PRED_FORMAT2(CmpHelperSTRC, str, substr)
-
-#define EXPECT_STR_NOT_CONTAIN(str, substr) \
- EXPECT_PRED_FORMAT2(CmpHelperSTRNC, str, substr)
-
-} // namespace
-
-// Test class for RLZ tracker. Makes some member functions public and
-// overrides others to make it easier to test.
-class TestRLZTracker : public RLZTracker {
- public:
- using RLZTracker::InitRlzDelayed;
- using RLZTracker::DelayedInit;
- using RLZTracker::Observe;
-
- TestRLZTracker() : assume_not_ui_thread_(true) {
- set_tracker(this);
- }
-
- ~TestRLZTracker() override {
- set_tracker(NULL);
- }
-
- bool was_ping_sent_for_brand(const std::string& brand) const {
- return pinged_brands_.count(brand) > 0;
- }
-
- void set_assume_not_ui_thread(bool assume_not_ui_thread) {
- assume_not_ui_thread_ = assume_not_ui_thread;
- }
-
- private:
- void ScheduleDelayedInit(base::TimeDelta delay) override {
- // If the delay is 0, invoke the delayed init now. Otherwise,
- // don't schedule anything, it will be manually called during tests.
- if (delay == base::TimeDelta())
- DelayedInit();
- }
-
- void ScheduleFinancialPing() override {
- PingNowImpl();
- }
-
- bool ScheduleRecordProductEvent(rlz_lib::Product product,
- rlz_lib::AccessPoint point,
- rlz_lib::Event event_id) override {
- return !assume_not_ui_thread_;
- }
-
- bool ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) override {
- return !assume_not_ui_thread_;
- }
-
- bool ScheduleRecordFirstSearch(rlz_lib::AccessPoint point) override {
- return !assume_not_ui_thread_;
- }
-
-#if defined(OS_CHROMEOS)
- bool ScheduleClearRlzState() override {
- return !assume_not_ui_thread_;
- }
-#endif
-
- bool SendFinancialPing(const std::string& brand,
- const base::string16& lang,
- const base::string16& referral) override {
- // Don't ping the server during tests, just pretend as if we did.
- EXPECT_FALSE(brand.empty());
- pinged_brands_.insert(brand);
-
- // Set new access points RLZ string, like the actual server ping would have
- // done.
- rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(),
- kNewOmniboxRlzString);
- rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(),
- kNewHomepageRlzString);
- rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(),
- kNewAppListRlzString);
- return true;
- }
-
- std::set<std::string> pinged_brands_;
- bool assume_not_ui_thread_;
-
- DISALLOW_COPY_AND_ASSIGN(TestRLZTracker);
-};
-
-class RlzLibTest : public ChromeRenderViewHostTestHarness {
- protected:
- void SetUp() override;
- void TearDown() override;
-
- void SetMainBrand(const char* brand);
- void SetReactivationBrand(const char* brand);
-#if defined(OS_WIN)
- void SetRegistryBrandValue(const wchar_t* name, const char* brand);
-#endif
-
- void SimulateOmniboxUsage();
- void SimulateHomepageUsage();
- void SimulateAppListUsage();
- void InvokeDelayedInit();
-
- void ExpectEventRecorded(const char* event_name, bool expected);
- void ExpectRlzPingSent(bool expected);
- void ExpectReactivationRlzPingSent(bool expected);
-
- scoped_ptr<TestRLZTracker> tracker_;
- RlzLibTestNoMachineStateHelper m_rlz_test_helper_;
-#if defined(OS_POSIX)
- scoped_ptr<google_brand::BrandForTesting> brand_override_;
-#endif
-};
-
-void RlzLibTest::SetUp() {
- ChromeRenderViewHostTestHarness::SetUp();
- m_rlz_test_helper_.SetUp();
- tracker_.reset(new TestRLZTracker());
-
- // Make sure a non-organic brand code is set in the registry or the RLZTracker
- // is pretty much a no-op.
- SetMainBrand("TEST");
- SetReactivationBrand("");
-}
-
-void RlzLibTest::TearDown() {
- tracker_.reset();
- ChromeRenderViewHostTestHarness::TearDown();
- m_rlz_test_helper_.TearDown();
-}
-
-void RlzLibTest::SetMainBrand(const char* brand) {
-#if defined(OS_WIN)
- SetRegistryBrandValue(google_update::kRegRLZBrandField, brand);
-#elif defined(OS_POSIX)
- brand_override_.reset(new google_brand::BrandForTesting(brand));
-#endif
- std::string check_brand;
- google_brand::GetBrand(&check_brand);
- EXPECT_EQ(brand, check_brand);
-}
-
-void RlzLibTest::SetReactivationBrand(const char* brand) {
- // TODO(thakis): Reactivation doesn't exist on Mac yet.
-#if defined(OS_WIN)
- SetRegistryBrandValue(google_update::kRegRLZReactivationBrandField, brand);
- std::string check_brand;
- google_brand::GetReactivationBrand(&check_brand);
- EXPECT_EQ(brand, check_brand);
-#endif
-}
-
-#if defined(OS_WIN)
-void RlzLibTest::SetRegistryBrandValue(const wchar_t* name,
- const char* brand) {
- BrowserDistribution* dist = BrowserDistribution::GetDistribution();
- base::string16 reg_path = dist->GetStateKey();
- RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_SET_VALUE);
- if (*brand == 0) {
- LONG result = key.DeleteValue(name);
- ASSERT_TRUE(ERROR_SUCCESS == result || ERROR_FILE_NOT_FOUND == result);
- } else {
- base::string16 brand16 = base::ASCIIToUTF16(brand);
- ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(name, brand16.c_str()));
- }
-}
-#endif
-
-void RlzLibTest::SimulateOmniboxUsage() {
- // Create a dummy OmniboxLog object. The 'is_popup_open' field needs to be
- // true to trigger record of the first search. All other fields are passed in
- // with empty or invalid values.
- AutocompleteResult empty_result;
- OmniboxLog dummy(base::string16(), false, metrics::OmniboxInputType::INVALID,
- true, 0, false, -1,
- metrics::OmniboxEventProto::INVALID_SPEC,
- base::TimeDelta::FromSeconds(0), 0,
- base::TimeDelta::FromSeconds(0),
- AutocompleteResult());
-
- tracker_->Observe(chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
- content::NotificationService::AllSources(),
- content::Details<OmniboxLog>(&dummy));
-}
-
-void RlzLibTest::SimulateHomepageUsage() {
- GURL home_url = GURL("https://www.google.com/");
- GURL search_url = GURL("https://www.google.com/#q=search");
-
- content::RenderFrameHostTester* rfht =
- content::RenderFrameHostTester::For(main_rfh());
-
- // Ensure the RenderFrame is initialized before simulating events coming from
- // it.
- rfht->InitializeRenderFrameIfNeeded();
-
- // Simulate a navigation to homepage first.
- rfht->SendNavigateWithTransition(
- 0, 0, true, home_url, ui::PAGE_TRANSITION_HOME_PAGE);
- // Then simulate a search from homepage.
- rfht->SendNavigateWithTransition(
- 1, 0, true, search_url, ui::PAGE_TRANSITION_LINK);
-}
-
-void RlzLibTest::SimulateAppListUsage() {
- RLZTracker::RecordAppListSearch();
-}
-
-void RlzLibTest::InvokeDelayedInit() {
- tracker_->DelayedInit();
-}
-
-void RlzLibTest::ExpectEventRecorded(const char* event_name, bool expected) {
- char cgi[rlz_lib::kMaxCgiLength];
- GetProductEventsAsCgi(rlz_lib::CHROME, cgi, arraysize(cgi));
- if (expected) {
- EXPECT_STR_CONTAINS(cgi, event_name);
- } else {
- EXPECT_STR_NOT_CONTAIN(cgi, event_name);
- }
-}
-
-void RlzLibTest::ExpectRlzPingSent(bool expected) {
- std::string brand;
- google_brand::GetBrand(&brand);
- EXPECT_EQ(expected, tracker_->was_ping_sent_for_brand(brand.c_str()));
-}
-
-void RlzLibTest::ExpectReactivationRlzPingSent(bool expected) {
- std::string brand;
- google_brand::GetReactivationBrand(&brand);
- EXPECT_EQ(expected, tracker_->was_ping_sent_for_brand(brand.c_str()));
-}
-
-// The events that affect the different RLZ scenarios are the following:
-//
-// A: the user starts chrome for the first time
-// B: the user stops chrome
-// C: the user start a subsequent time
-// D: the user stops chrome again
-// I: the RLZTracker::DelayedInit() method is invoked
-// X: the user performs a search using the omnibox
-// Y: the user performs a search using the home page
-// Z: the user performs a search using the app list
-//
-// The events A to D happen in chronological order, but the other events
-// may happen at any point between A-B or C-D, in no particular order.
-//
-// The visible results of the scenarios on Win are:
-//
-// C1I event is recorded
-// C2I event is recorded
-// C7I event is recorded
-// C1F event is recorded
-// C2F event is recorded
-// C7F event is recorded
-// C1S event is recorded
-// C2S event is recorded
-// C7S event is recorded
-// RLZ ping sent
-//
-// On Mac, C5 / C6 / C8 are sent instead of C1 / C2 / C7.
-// On ChromeOS, CA / CB / CC are sent, respectively.
-//
-// Variations on the above scenarios:
-//
-// - if the delay specified to InitRlzDelayed() is negative, then the RLZ
-// ping should be sent out at the time of event X and not wait for I
-//
-// Also want to test that pre-warming the RLZ string cache works correctly.
-
-#if defined(OS_WIN)
-const char kOmniboxInstall[] = "C1I";
-const char kOmniboxSetToGoogle[] = "C1S";
-const char kOmniboxFirstSearch[] = "C1F";
-
-const char kHomepageInstall[] = "C2I";
-const char kHomepageSetToGoogle[] = "C2S";
-const char kHomepageFirstSeach[] = "C2F";
-
-const char kAppListInstall[] = "C7I";
-const char kAppListSetToGoogle[] = "C7S";
-const char kAppListFirstSearch[] = "C7F";
-#elif defined(OS_MACOSX)
-const char kOmniboxInstall[] = "C5I";
-const char kOmniboxSetToGoogle[] = "C5S";
-const char kOmniboxFirstSearch[] = "C5F";
-
-const char kHomepageInstall[] = "C6I";
-const char kHomepageSetToGoogle[] = "C6S";
-const char kHomepageFirstSeach[] = "C6F";
-
-const char kAppListInstall[] = "C8I";
-const char kAppListSetToGoogle[] = "C8S";
-const char kAppListFirstSearch[] = "C8F";
-#elif defined(OS_CHROMEOS)
-const char kOmniboxInstall[] = "CAI";
-const char kOmniboxSetToGoogle[] = "CAS";
-const char kOmniboxFirstSearch[] = "CAF";
-
-const char kHomepageInstall[] = "CBI";
-const char kHomepageSetToGoogle[] = "CBS";
-const char kHomepageFirstSeach[] = "CBF";
-
-const char kAppListInstall[] = "CCI";
-const char kAppListSetToGoogle[] = "CCS";
-const char kAppListFirstSearch[] = "CCF";
-#endif
-
-const base::TimeDelta kDelay = base::TimeDelta::FromMilliseconds(20);
-
-TEST_F(RlzLibTest, RecordProductEvent) {
- RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(),
- rlz_lib::FIRST_SEARCH);
-
- ExpectEventRecorded(kOmniboxFirstSearch, true);
-}
-
-TEST_F(RlzLibTest, QuickStopAfterStart) {
- TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, true);
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, false);
- ExpectEventRecorded(kOmniboxSetToGoogle, false);
- ExpectEventRecorded(kOmniboxFirstSearch, false);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, false);
- ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSeach, false);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, false);
- ExpectEventRecorded(kAppListSetToGoogle, false);
- ExpectEventRecorded(kAppListFirstSearch, false);
-
- ExpectRlzPingSent(false);
-}
-
-TEST_F(RlzLibTest, DelayedInitOnly) {
- TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
- InvokeDelayedInit();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, true);
- ExpectEventRecorded(kOmniboxSetToGoogle, true);
- ExpectEventRecorded(kOmniboxFirstSearch, false);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, true);
- ExpectEventRecorded(kHomepageSetToGoogle, true);
- ExpectEventRecorded(kHomepageFirstSeach, false);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, true);
- ExpectEventRecorded(kAppListSetToGoogle, true);
- ExpectEventRecorded(kAppListFirstSearch, false);
-
- ExpectRlzPingSent(true);
-}
-
-TEST_F(RlzLibTest, DelayedInitOnlyGoogleAsStartup) {
- TestRLZTracker::InitRlzDelayed(true, false, kDelay, false, false, true);
- InvokeDelayedInit();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, true);
- ExpectEventRecorded(kOmniboxSetToGoogle, false);
- ExpectEventRecorded(kOmniboxFirstSearch, false);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, true);
- ExpectEventRecorded(kHomepageSetToGoogle, true);
- ExpectEventRecorded(kHomepageFirstSeach, true);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, true);
- ExpectEventRecorded(kAppListSetToGoogle, false);
- ExpectEventRecorded(kAppListFirstSearch, false);
-
- ExpectRlzPingSent(true);
-}
-
-TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStrings) {
- TestRLZTracker::InitRlzDelayed(false, false, kDelay, true, true, false);
- InvokeDelayedInit();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, true);
- ExpectEventRecorded(kOmniboxSetToGoogle, true);
- ExpectEventRecorded(kOmniboxFirstSearch, false);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, true);
- ExpectEventRecorded(kHomepageSetToGoogle, true);
- ExpectEventRecorded(kHomepageFirstSeach, false);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, true);
- ExpectEventRecorded(kAppListSetToGoogle, true);
- ExpectEventRecorded(kAppListFirstSearch, false);
-
- ExpectRlzPingSent(true);
-}
-
-TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStringsGoogleAsStartup) {
- TestRLZTracker::InitRlzDelayed(false, false, kDelay, false, false, true);
- InvokeDelayedInit();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, true);
- ExpectEventRecorded(kOmniboxSetToGoogle, false);
- ExpectEventRecorded(kOmniboxFirstSearch, false);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, true);
- ExpectEventRecorded(kHomepageSetToGoogle, true);
- ExpectEventRecorded(kHomepageFirstSeach, true);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, true);
- ExpectEventRecorded(kAppListSetToGoogle, false);
- ExpectEventRecorded(kAppListFirstSearch, false);
-
- ExpectRlzPingSent(true);
-}
-
-TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRun) {
- // Set some dummy RLZ strings to simulate that we already ran before and
- // performed a successful ping to the RLZ server.
- rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
- rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(), kHomepageRlzString);
- rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(), kAppListRlzString);
-
- TestRLZTracker::InitRlzDelayed(false, false, kDelay, true, true, true);
- InvokeDelayedInit();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, true);
- ExpectEventRecorded(kOmniboxSetToGoogle, false);
- ExpectEventRecorded(kOmniboxFirstSearch, false);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, true);
- ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSeach, true);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, true);
- ExpectEventRecorded(kAppListSetToGoogle, false);
- ExpectEventRecorded(kAppListFirstSearch, false);
-
- ExpectRlzPingSent(true);
-}
-
-TEST_F(RlzLibTest, DelayedInitOnlyNoGoogleDefaultSearchOrHomepageOrStartup) {
- TestRLZTracker::InitRlzDelayed(true, false, kDelay, false, false, false);
- InvokeDelayedInit();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, true);
- ExpectEventRecorded(kOmniboxSetToGoogle, false);
- ExpectEventRecorded(kOmniboxFirstSearch, false);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, true);
- ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSeach, false);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, true);
- ExpectEventRecorded(kAppListSetToGoogle, false);
- ExpectEventRecorded(kAppListFirstSearch, false);
-
- ExpectRlzPingSent(true);
-}
-
-TEST_F(RlzLibTest, OmniboxUsageOnly) {
- TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
- SimulateOmniboxUsage();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, false);
- ExpectEventRecorded(kOmniboxSetToGoogle, false);
- ExpectEventRecorded(kOmniboxFirstSearch, true);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, false);
- ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSeach, false);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, false);
- ExpectEventRecorded(kAppListSetToGoogle, false);
- ExpectEventRecorded(kAppListFirstSearch, false);
-
- ExpectRlzPingSent(false);
-}
-
-TEST_F(RlzLibTest, HomepageUsageOnly) {
- TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
- SimulateHomepageUsage();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, false);
- ExpectEventRecorded(kOmniboxSetToGoogle, false);
- ExpectEventRecorded(kOmniboxFirstSearch, false);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, false);
- ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSeach, true);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, false);
- ExpectEventRecorded(kAppListSetToGoogle, false);
- ExpectEventRecorded(kAppListFirstSearch, false);
-
- ExpectRlzPingSent(false);
-}
-
-TEST_F(RlzLibTest, AppListUsageOnly) {
- TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
- SimulateAppListUsage();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, false);
- ExpectEventRecorded(kOmniboxSetToGoogle, false);
- ExpectEventRecorded(kOmniboxFirstSearch, false);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, false);
- ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSeach, false);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, false);
- ExpectEventRecorded(kAppListSetToGoogle, false);
- ExpectEventRecorded(kAppListFirstSearch, true);
-
- ExpectRlzPingSent(false);
-}
-
-TEST_F(RlzLibTest, UsageBeforeDelayedInit) {
- TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
- SimulateOmniboxUsage();
- SimulateHomepageUsage();
- SimulateAppListUsage();
- InvokeDelayedInit();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, true);
- ExpectEventRecorded(kOmniboxSetToGoogle, true);
- ExpectEventRecorded(kOmniboxFirstSearch, true);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, true);
- ExpectEventRecorded(kHomepageSetToGoogle, true);
- ExpectEventRecorded(kHomepageFirstSeach, true);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, true);
- ExpectEventRecorded(kAppListSetToGoogle, true);
- ExpectEventRecorded(kAppListFirstSearch, true);
-
- ExpectRlzPingSent(true);
-}
-
-TEST_F(RlzLibTest, UsageAfterDelayedInit) {
- TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
- InvokeDelayedInit();
- SimulateOmniboxUsage();
- SimulateHomepageUsage();
- SimulateAppListUsage();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, true);
- ExpectEventRecorded(kOmniboxSetToGoogle, true);
- ExpectEventRecorded(kOmniboxFirstSearch, true);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, true);
- ExpectEventRecorded(kHomepageSetToGoogle, true);
- ExpectEventRecorded(kHomepageFirstSeach, true);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, true);
- ExpectEventRecorded(kAppListSetToGoogle, true);
- ExpectEventRecorded(kAppListFirstSearch, true);
-
- ExpectRlzPingSent(true);
-}
-
-TEST_F(RlzLibTest, OmniboxUsageSendsPingWhenSendPingImmediately) {
- TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, true, false);
- SimulateOmniboxUsage();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, true);
- ExpectEventRecorded(kOmniboxSetToGoogle, true);
- ExpectEventRecorded(kOmniboxFirstSearch, true);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, true);
- ExpectEventRecorded(kHomepageSetToGoogle, true);
- ExpectEventRecorded(kHomepageFirstSeach, false);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, true);
- ExpectEventRecorded(kAppListSetToGoogle, true);
- ExpectEventRecorded(kAppListFirstSearch, false);
-
- ExpectRlzPingSent(true);
-}
-
-TEST_F(RlzLibTest, HomepageUsageDoesNotSendPingWhenSendPingImmediately) {
- TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, true, false);
- SimulateHomepageUsage();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, false);
- ExpectEventRecorded(kOmniboxSetToGoogle, false);
- ExpectEventRecorded(kOmniboxFirstSearch, false);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, false);
- ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSeach, true);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, false);
- ExpectEventRecorded(kAppListSetToGoogle, false);
- ExpectEventRecorded(kAppListFirstSearch, false);
-
- ExpectRlzPingSent(false);
-}
-
-TEST_F(RlzLibTest, StartupUsageDoesNotSendPingWhenSendPingImmediately) {
- TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, false, true);
- SimulateHomepageUsage();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, false);
- ExpectEventRecorded(kOmniboxSetToGoogle, false);
- ExpectEventRecorded(kOmniboxFirstSearch, false);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, false);
- ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSeach, true);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, false);
- ExpectEventRecorded(kAppListSetToGoogle, false);
- ExpectEventRecorded(kAppListFirstSearch, false);
-
- ExpectRlzPingSent(false);
-}
-
-TEST_F(RlzLibTest, AppListUsageDoesNotSendPingWhenSendPingImmediately) {
- TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, false, false);
- SimulateAppListUsage();
-
- // Omnibox events.
- ExpectEventRecorded(kOmniboxInstall, false);
- ExpectEventRecorded(kOmniboxSetToGoogle, false);
- ExpectEventRecorded(kOmniboxFirstSearch, false);
-
- // Home page events.
- ExpectEventRecorded(kHomepageInstall, false);
- ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSeach, false);
-
- // App list events.
- ExpectEventRecorded(kAppListInstall, false);
- ExpectEventRecorded(kAppListSetToGoogle, false);
- ExpectEventRecorded(kAppListFirstSearch, true);
-
- ExpectRlzPingSent(false);
-}
-
-TEST_F(RlzLibTest, GetAccessPointRlzOnIoThread) {
- // Set dummy RLZ string.
- rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
-
- base::string16 rlz;
-
- tracker_->set_assume_not_ui_thread(true);
- EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
- EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
-}
-
-TEST_F(RlzLibTest, GetAccessPointRlzNotOnIoThread) {
- // Set dummy RLZ string.
- rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
-
- base::string16 rlz;
-
- tracker_->set_assume_not_ui_thread(false);
- EXPECT_FALSE(
- RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
-}
-
-TEST_F(RlzLibTest, GetAccessPointRlzIsCached) {
- // Set dummy RLZ string.
- rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
-
- base::string16 rlz;
-
- tracker_->set_assume_not_ui_thread(false);
- EXPECT_FALSE(
- RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
-
- tracker_->set_assume_not_ui_thread(true);
- EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
- EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
-
- tracker_->set_assume_not_ui_thread(false);
- EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
- EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
-}
-
-TEST_F(RlzLibTest, PingUpdatesRlzCache) {
- // Set dummy RLZ string.
- rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
- rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(), kHomepageRlzString);
- rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(), kAppListRlzString);
-
- base::string16 rlz;
-
- // Prime the cache.
- tracker_->set_assume_not_ui_thread(true);
-
- EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
- EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
- EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
- RLZTracker::ChromeHomePage(), &rlz));
- EXPECT_STREQ(kHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
- EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
- EXPECT_STREQ(kAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
-
- // Make sure cache is valid.
- tracker_->set_assume_not_ui_thread(false);
-
- EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
- EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
- EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
- RLZTracker::ChromeHomePage(), &rlz));
- EXPECT_STREQ(kHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
- EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
- EXPECT_STREQ(kAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
-
- // Perform ping.
- tracker_->set_assume_not_ui_thread(true);
- TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
- InvokeDelayedInit();
- ExpectRlzPingSent(true);
-
- // Make sure cache is now updated.
- tracker_->set_assume_not_ui_thread(false);
-
- EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
- EXPECT_STREQ(kNewOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
- EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
- RLZTracker::ChromeHomePage(), &rlz));
- EXPECT_STREQ(kNewHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
- EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
- EXPECT_STREQ(kNewAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
-}
-
-TEST_F(RlzLibTest, ObserveHandlesBadArgs) {
- scoped_ptr<LoadCommittedDetails> details(new LoadCommittedDetails());
- scoped_ptr<content::NavigationEntry> entry(
- content::NavigationEntry::Create());
- details->entry = entry.get();
- details->entry->SetPageID(0);
- details->entry->SetTransitionType(ui::PAGE_TRANSITION_LINK);
-
- tracker_->Observe(content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- content::NotificationService::AllSources(),
- content::Details<NavigationEntry>(NULL));
- tracker_->Observe(content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- content::NotificationService::AllSources(),
- content::Details<LoadCommittedDetails>(details.get()));
-}
-
-// TODO(thakis): Reactivation doesn't exist on Mac yet.
-#if defined(OS_WIN)
-TEST_F(RlzLibTest, ReactivationNonOrganicNonOrganic) {
- SetReactivationBrand("REAC");
-
- TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
- InvokeDelayedInit();
-
- ExpectRlzPingSent(true);
- ExpectReactivationRlzPingSent(true);
-}
-
-TEST_F(RlzLibTest, ReactivationOrganicNonOrganic) {
- SetMainBrand("GGLS");
- SetReactivationBrand("REAC");
-
- TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
- InvokeDelayedInit();
-
- ExpectRlzPingSent(false);
- ExpectReactivationRlzPingSent(true);
-}
-
-TEST_F(RlzLibTest, ReactivationNonOrganicOrganic) {
- SetMainBrand("TEST");
- SetReactivationBrand("GGLS");
-
- TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
- InvokeDelayedInit();
-
- ExpectRlzPingSent(true);
- ExpectReactivationRlzPingSent(false);
-}
-
-TEST_F(RlzLibTest, ReactivationOrganicOrganic) {
- SetMainBrand("GGLS");
- SetReactivationBrand("GGRS");
-
- TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
- InvokeDelayedInit();
-
- ExpectRlzPingSent(false);
- ExpectReactivationRlzPingSent(false);
-}
-#endif // defined(OS_WIN)
-
-#if defined(OS_CHROMEOS)
-TEST_F(RlzLibTest, ClearRlzState) {
- RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(),
- rlz_lib::FIRST_SEARCH);
-
- ExpectEventRecorded(kOmniboxFirstSearch, true);
-
- RLZTracker::ClearRlzState();
-
- ExpectEventRecorded(kOmniboxFirstSearch, false);
-}
-#endif // defined(OS_CHROMEOS)
diff --git a/chrome/browser/rlz/rlz_win.cc b/chrome/browser/rlz/rlz_win.cc
deleted file mode 100644
index 0f96858..0000000
--- a/chrome/browser/rlz/rlz_win.cc
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2014 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/rlz/rlz.h"
-
-// static
-rlz_lib::AccessPoint RLZTracker::ChromeOmnibox() {
- return rlz_lib::CHROME_OMNIBOX;
-}
-
-// static
-rlz_lib::AccessPoint RLZTracker::ChromeHomePage() {
- return rlz_lib::CHROME_HOME_PAGE;
-}
-
-// static
-rlz_lib::AccessPoint RLZTracker::ChromeAppList() {
- return rlz_lib::CHROME_APP_LIST;
-}
diff --git a/chrome/browser/search_engines/template_url_service_factory.cc b/chrome/browser/search_engines/template_url_service_factory.cc
index c5246e7..6d52447 100644
--- a/chrome/browser/search_engines/template_url_service_factory.cc
+++ b/chrome/browser/search_engines/template_url_service_factory.cc
@@ -13,7 +13,6 @@
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/rlz/rlz.h"
#include "chrome/browser/search_engines/chrome_template_url_service_client.h"
#include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
#include "chrome/browser/web_data_service_factory.h"
@@ -23,6 +22,10 @@
#include "components/search_engines/search_engines_pref_names.h"
#include "components/search_engines/template_url_service.h"
+#if defined(ENABLE_RLZ)
+#include "components/rlz/rlz_tracker.h"
+#endif
+
// static
TemplateURLService* TemplateURLServiceFactory::GetForProfile(Profile* profile) {
return static_cast<TemplateURLService*>(
@@ -39,11 +42,9 @@ scoped_ptr<KeyedService> TemplateURLServiceFactory::BuildInstanceFor(
content::BrowserContext* context) {
base::Closure dsp_change_callback;
#if defined(ENABLE_RLZ)
- dsp_change_callback =
- base::Bind(base::IgnoreResult(&RLZTracker::RecordProductEvent),
- rlz_lib::CHROME,
- RLZTracker::ChromeOmnibox(),
- rlz_lib::SET_TO_GOOGLE);
+ dsp_change_callback = base::Bind(
+ base::IgnoreResult(&rlz::RLZTracker::RecordProductEvent), rlz_lib::CHROME,
+ rlz::RLZTracker::ChromeOmnibox(), rlz_lib::SET_TO_GOOGLE);
#endif
Profile* profile = static_cast<Profile*>(context);
return make_scoped_ptr(new TemplateURLService(
diff --git a/chrome/browser/search_engines/ui_thread_search_terms_data.cc b/chrome/browser/search_engines/ui_thread_search_terms_data.cc
index 1ccd09a..11dae12 100644
--- a/chrome/browser/search_engines/ui_thread_search_terms_data.cc
+++ b/chrome/browser/search_engines/ui_thread_search_terms_data.cc
@@ -28,7 +28,7 @@
#include "url/gurl.h"
#if defined(ENABLE_RLZ)
-#include "chrome/browser/rlz/rlz.h"
+#include "components/rlz/rlz_tracker.h"
#endif
using content::BrowserThread;
@@ -82,12 +82,12 @@ base::string16 UIThreadSearchTermsData::GetRlzParameterValue(
// This call will return false the first time(s) it is called until the
// value has been cached. This normally would mean that at most one omnibox
// search might not send the RLZ data but this is not really a problem.
- rlz_lib::AccessPoint access_point = RLZTracker::ChromeOmnibox();
+ rlz_lib::AccessPoint access_point = rlz::RLZTracker::ChromeOmnibox();
#if !defined(OS_IOS)
if (from_app_list)
- access_point = RLZTracker::ChromeAppList();
+ access_point = rlz::RLZTracker::ChromeAppList();
#endif
- RLZTracker::GetAccessPointRlz(access_point, &rlz_string);
+ rlz::RLZTracker::GetAccessPointRlz(access_point, &rlz_string);
}
#endif
return rlz_string;
diff --git a/chrome/browser/ui/app_list/app_list_controller_delegate.cc b/chrome/browser/ui/app_list/app_list_controller_delegate.cc
index e6a19fc..76a54164 100644
--- a/chrome/browser/ui/app_list/app_list_controller_delegate.cc
+++ b/chrome/browser/ui/app_list/app_list_controller_delegate.cc
@@ -28,7 +28,7 @@
#include "ui/gfx/geometry/rect.h"
#if defined(ENABLE_RLZ)
-#include "chrome/browser/rlz/rlz.h"
+#include "components/rlz/rlz_tracker.h"
#endif
using extensions::ExtensionRegistry;
@@ -213,6 +213,6 @@ void AppListControllerDelegate::GetApps(Profile* profile,
void AppListControllerDelegate::OnSearchStarted() {
#if defined(ENABLE_RLZ)
- RLZTracker::RecordAppListSearch();
+ rlz::RLZTracker::RecordAppListSearch();
#endif
}
diff --git a/chrome/browser/ui/browser_commands.cc b/chrome/browser/ui/browser_commands.cc
index 6c031f3..1783266 100644
--- a/chrome/browser/ui/browser_commands.cc
+++ b/chrome/browser/ui/browser_commands.cc
@@ -20,7 +20,6 @@
#include "chrome/browser/platform_util.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/rlz/rlz.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/sessions/tab_restore_service.h"
@@ -104,6 +103,10 @@
#endif // defined(ENABLE_PRINT_PREVIEW)
#endif // defined(ENABLE_PRINTING)
+#if defined(ENABLE_RLZ)
+#include "components/rlz/rlz_tracker.h"
+#endif
+
namespace {
const char kOsOverrideForTabletSite[] = "Linux; Android 4.0.3";
}
@@ -433,8 +436,8 @@ void Home(Browser* browser, WindowOpenDisposition disposition) {
if (pref_service) {
if (google_util::IsGoogleHomePageUrl(
GURL(pref_service->GetString(prefs::kHomePage)))) {
- extra_headers = RLZTracker::GetAccessPointHttpHeader(
- RLZTracker::ChromeHomePage());
+ extra_headers = rlz::RLZTracker::GetAccessPointHttpHeader(
+ rlz::RLZTracker::ChromeHomePage());
}
}
#endif // defined(ENABLE_RLZ) && !defined(OS_IOS)
diff --git a/chrome/browser/ui/startup/startup_browser_creator_impl.cc b/chrome/browser/ui/startup/startup_browser_creator_impl.cc
index b6a1fdd..665f159 100644
--- a/chrome/browser/ui/startup/startup_browser_creator_impl.cc
+++ b/chrome/browser/ui/startup/startup_browser_creator_impl.cc
@@ -43,7 +43,6 @@
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_io_data.h"
-#include "chrome/browser/rlz/rlz.h"
#include "chrome/browser/sessions/session_restore.h"
#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sessions/session_service_factory.h"
@@ -103,6 +102,10 @@
#include "chrome/browser/apps/app_launch_for_metro_restart_win.h"
#endif
+#if defined(ENABLE_RLZ)
+#include "components/rlz/rlz_tracker.h"
+#endif
+
using content::ChildProcessSecurityPolicy;
using content::WebContents;
using extensions::Extension;
@@ -788,8 +791,8 @@ Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser(
#if defined(ENABLE_RLZ) && !defined(OS_IOS)
if (process_startup && google_util::IsGoogleHomePageUrl(tabs[i].url)) {
- params.extra_headers = RLZTracker::GetAccessPointHttpHeader(
- RLZTracker::ChromeHomePage());
+ params.extra_headers = rlz::RLZTracker::GetAccessPointHttpHeader(
+ rlz::RLZTracker::ChromeHomePage());
}
#endif // defined(ENABLE_RLZ) && !defined(OS_IOS)