Index: chrome/browser/rlz/rlz.cc |
diff --git a/chrome/browser/rlz/rlz.cc b/chrome/browser/rlz/rlz.cc |
index 3027a1a1ad7943ab8917a444d570944dfabcd99d..89c62c857bdaba7769d4c1e3e991ed6327594ae7 100644 |
--- a/chrome/browser/rlz/rlz.cc |
+++ b/chrome/browser/rlz/rlz.cc |
@@ -11,15 +11,20 @@ |
#include <algorithm> |
#include "base/bind.h" |
+#include "base/command_line.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" |
@@ -57,6 +62,10 @@ 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); |
} |
@@ -196,6 +205,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, |
@@ -526,6 +577,16 @@ bool RLZTracker::ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) { |
// static |
void RLZTracker::CleanupRlz() { |
- GetInstance()->rlz_cache_.clear(); |
- GetInstance()->registrar_.RemoveAll(); |
+ RLZTracker* instance = GetInstance(); |
+ instance->rlz_cache_.clear(); |
+ instance->registrar_.RemoveAll(); |
+#if defined(OS_CHROMEOS) |
+ if (instance->blocking_task_runner_) { |
+ instance->blocking_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&rlz_lib::CleanupRlz)); |
+ instance->rlz_thread_.Stop(); |
+ } |
+#endif |
+ instance->blocking_task_runner_ = NULL; |
} |