Index: chrome/browser/rlz/rlz.cc |
diff --git a/chrome/browser/rlz/rlz.cc b/chrome/browser/rlz/rlz.cc |
index 7005e32d47c199b57d171818dd68c6e9a37feff3..7048b925b0c14d3c2f54dca8ccf241284589b9dd 100644 |
--- a/chrome/browser/rlz/rlz.cc |
+++ b/chrome/browser/rlz/rlz.cc |
@@ -11,25 +11,26 @@ |
#include <algorithm> |
#include "base/bind.h" |
+#include "base/command_line.h" |
#include "base/debug/trace_event.h" |
#include "base/message_loop.h" |
#include "base/string_util.h" |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/google/google_util.h" |
+#include "chrome/browser/prefs/pref_service.h" |
+#include "chrome/browser/prefs/session_startup_pref.h" |
#include "chrome/browser/search_engines/template_url.h" |
#include "chrome/browser/search_engines/template_url_service.h" |
#include "chrome/browser/search_engines/template_url_service_factory.h" |
+#include "chrome/browser/ui/startup/startup_browser_creator.h" |
#include "chrome/common/chrome_notification_types.h" |
+#include "chrome/common/pref_names.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/navigation_entry.h" |
#include "content/public/browser/notification_service.h" |
#include "net/http/http_util.h" |
-#if defined(OS_CHROMEOS) |
-#include "base/threading/sequenced_worker_pool.h" |
-#endif |
- |
#if defined(OS_WIN) |
#include "chrome/installer/util/google_update_settings.h" |
#else |
@@ -56,7 +57,9 @@ using content::NavigationEntry; |
namespace { |
-const char kRlzThreadName[] = "RLZ_thread"; |
+bool IsGoogleUrl(const GURL& url) { |
+ return google_util::IsGoogleHomePageUrl(url.possibly_invalid_spec()); |
+} |
bool IsBrandOrganic(const std::string& brand) { |
return brand.empty() || google_util::IsOrganic(brand); |
@@ -177,9 +180,6 @@ RLZTracker::RLZTracker() |
is_google_default_search_(false), |
is_google_homepage_(false), |
is_google_in_startpages_(false), |
- rlz_thread_(kRlzThreadName), |
- blocking_task_runner_(NULL), |
- url_request_context_(NULL), |
already_ran_(false), |
omnibox_used_(false), |
homepage_used_(false) { |
@@ -198,6 +198,48 @@ bool RLZTracker::InitRlzDelayed(bool first_run, |
is_google_homepage, is_google_in_startpages); |
} |
+// static |
+bool RLZTracker::InitRlzFromProfileDelayed(Profile* profile, |
+ bool first_run, |
+ int 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(); |
+ } |
+ |
+ PrefService* pref_service = profile->GetPrefs(); |
+ bool is_google_homepage = google_util::IsGoogleHomePageUrl( |
+ pref_service->GetString(prefs::kHomePage)); |
+ |
+ bool is_google_in_startpages = false; |
+ SessionStartupPref session_startup_prefs = |
+ StartupBrowserCreator::GetSessionStartupPref( |
+ *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(), |
+ IsGoogleUrl) > 0; |
+ } |
+ |
+ if (!InitRlzDelayed(first_run, delay, |
+ is_google_default_search, is_google_homepage, |
+ is_google_in_startpages)) { |
+ return false; |
+ } |
+ |
+ // 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(CHROME_HOME_PAGE, NULL); |
+ |
+ return true; |
+} |
+ |
bool RLZTracker::Init(bool first_run, |
int delay, |
bool is_google_default_search, |
@@ -208,9 +250,6 @@ bool RLZTracker::Init(bool first_run, |
is_google_homepage_ = is_google_homepage; |
is_google_in_startpages_ = is_google_in_startpages; |
- if (!InitWorkers()) |
- return false; |
- |
// A negative delay means that a financial ping should be sent immediately |
// after a first search is recorded, without waiting for the next restart |
// of chrome. However, we only want this behaviour on first run. |
@@ -229,8 +268,7 @@ bool RLZTracker::Init(bool first_run, |
delay = (delay < kMinDelay) ? kMinDelay : delay; |
delay = (delay > kMaxDelay) ? kMaxDelay : delay; |
- std::string brand; |
- if (google_util::GetBrand(&brand) && !IsBrandOrganic(brand)) { |
+ if (google_util::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, |
@@ -245,8 +283,9 @@ bool RLZTracker::Init(bool first_run, |
registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
content::NotificationService::AllSources()); |
} |
+ google_util::GetReactivationBrand(&reactivation_brand_); |
- url_request_context_ = g_browser_process->system_request_context(); |
+ rlz_lib::SetURLRequestContext(g_browser_process->system_request_context()); |
ScheduleDelayedInit(delay); |
return true; |
@@ -255,42 +294,20 @@ bool RLZTracker::Init(bool first_run, |
void RLZTracker::ScheduleDelayedInit(int delay) { |
// The RLZTracker is a singleton object that outlives any runnable tasks |
// that will be queued up. |
- blocking_task_runner_->PostDelayedTask( |
+ BrowserThread::GetBlockingPool()->PostDelayedTask( |
FROM_HERE, |
base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), |
base::TimeDelta::FromMilliseconds(delay)); |
} |
-bool RLZTracker::InitWorkers() { |
- base::Thread::Options options; |
- options.message_loop_type = MessageLoop::TYPE_IO; |
- if (!rlz_thread_.StartWithOptions(options)) |
- return false; |
- blocking_task_runner_ = rlz_thread_.message_loop_proxy(); |
- |
-#if defined(OS_CHROMEOS) |
- base::SequencedWorkerPool* worker_pool = |
- content::BrowserThread::GetBlockingPool(); |
- if (!worker_pool) |
- return false; |
- rlz_lib::SetIOTaskRunner( |
- worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
- worker_pool->GetSequenceToken(), |
- base::SequencedWorkerPool::BLOCK_SHUTDOWN)); |
-#endif |
- return true; |
-} |
- |
void RLZTracker::DelayedInit() { |
- if (!already_ran_) |
- rlz_lib::SetURLRequestContext(url_request_context_); |
+ worker_pool_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken(); |
bool schedule_ping = false; |
// For organic brandcodes do not use rlz at all. Empty brandcode usually |
// means a chromium install. This is ok. |
- std::string brand; |
- if (google_util::GetBrand(&brand) && !IsBrandOrganic(brand)) { |
+ if (!IsBrandOrganic(brand_)) { |
RecordProductEvents(first_run_, is_google_default_search_, |
is_google_homepage_, is_google_in_startpages_, |
already_ran_, omnibox_used_, homepage_used_); |
@@ -299,10 +316,8 @@ void RLZTracker::DelayedInit() { |
// If chrome has been reactivated, record the events for this brand |
// as well. |
- std::string reactivation_brand; |
- if (google_util::GetReactivationBrand(&reactivation_brand) && |
- !IsBrandOrganic(reactivation_brand)) { |
- rlz_lib::SupplementaryBranding branding(reactivation_brand.c_str()); |
+ 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_); |
@@ -316,7 +331,8 @@ void RLZTracker::DelayedInit() { |
} |
void RLZTracker::ScheduleFinancialPing() { |
- blocking_task_runner_->PostTask( |
+ BrowserThread::GetBlockingPool()->PostSequencedWorkerTask( |
+ worker_pool_token_, |
FROM_HERE, |
base::Bind(&RLZTracker::PingNowImpl, base::Unretained(this))); |
} |
@@ -330,9 +346,7 @@ void RLZTracker::PingNowImpl() { |
string16 referral; |
GoogleUpdateSettings::GetReferral(&referral); |
- std::string brand; |
- if (google_util::GetBrand(&brand) && !IsBrandOrganic(brand) && |
- SendFinancialPing(brand, lang, referral)) { |
+ if (!IsBrandOrganic(brand_) && SendFinancialPing(brand_, lang, referral)) { |
GoogleUpdateSettings::ClearReferral(); |
{ |
@@ -345,11 +359,9 @@ void RLZTracker::PingNowImpl() { |
GetAccessPointRlz(RLZTracker::CHROME_HOME_PAGE, NULL); |
} |
- std::string reactivation_brand; |
- if (google_util::GetReactivationBrand(&reactivation_brand) && |
- !IsBrandOrganic(reactivation_brand)) { |
- rlz_lib::SupplementaryBranding branding(reactivation_brand.c_str()); |
- SendFinancialPing(reactivation_brand, lang, referral); |
+ if (!IsBrandOrganic(reactivation_brand_)) { |
+ rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); |
+ SendFinancialPing(reactivation_brand_, lang, referral); |
} |
} |
@@ -407,9 +419,8 @@ bool RLZTracker::RecordProductEventImpl(rlz_lib::Product product, |
bool ret = rlz_lib::RecordProductEvent(product, point, event_id); |
// If chrome has been reactivated, record the event for this brand as well. |
- std::string reactivation_brand; |
- if (google_util::GetReactivationBrand(&reactivation_brand)) { |
- rlz_lib::SupplementaryBranding branding(reactivation_brand.c_str()); |
+ if (!reactivation_brand_.empty()) { |
+ rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); |
ret &= rlz_lib::RecordProductEvent(product, point, event_id); |
} |
@@ -421,12 +432,13 @@ bool RLZTracker::ScheduleRecordProductEvent(rlz_lib::Product product, |
rlz_lib::Event event_id) { |
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) |
return false; |
- if (!blocking_task_runner_) { |
+ if (!already_ran_) { |
LOG(ERROR) << "Attempted recording RLZ event before RLZ init."; |
return true; |
} |
- blocking_task_runner_->PostTask( |
+ BrowserThread::GetBlockingPool()->PostSequencedWorkerTask( |
+ worker_pool_token_, |
FROM_HERE, |
base::Bind(base::IgnoreResult(&RLZTracker::RecordProductEvent), |
product, point, event_id)); |
@@ -454,7 +466,8 @@ void RLZTracker::RecordFirstSearch(rlz_lib::AccessPoint point) { |
bool RLZTracker::ScheduleRecordFirstSearch(rlz_lib::AccessPoint point) { |
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) |
return false; |
- blocking_task_runner_->PostTask( |
+ BrowserThread::GetBlockingPool()->PostSequencedWorkerTask( |
+ worker_pool_token_, |
FROM_HERE, |
base::Bind(&RLZTracker::RecordFirstSearch, |
base::Unretained(this), point)); |
@@ -522,7 +535,8 @@ bool RLZTracker::ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) { |
return false; |
string16* not_used = NULL; |
- blocking_task_runner_->PostTask( |
+ BrowserThread::GetBlockingPool()->PostSequencedWorkerTask( |
+ worker_pool_token_, |
FROM_HERE, |
base::Bind(base::IgnoreResult(&RLZTracker::GetAccessPointRlz), point, |
not_used)); |