OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // This code glues the RLZ library DLL with Chrome. It allows Chrome to work | 5 // This code glues the RLZ library DLL with Chrome. It allows Chrome to work |
6 // with or without the DLL being present. If the DLL is not present the | 6 // with or without the DLL being present. If the DLL is not present the |
7 // functions do nothing and just return false. | 7 // functions do nothing and just return false. |
8 | 8 |
9 #include "chrome/browser/rlz/rlz.h" | 9 #include "chrome/browser/rlz/rlz.h" |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" |
14 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/google/google_util.h" | 19 #include "chrome/browser/google/google_util.h" |
| 20 #include "chrome/browser/prefs/pref_service.h" |
| 21 #include "chrome/browser/prefs/session_startup_pref.h" |
19 #include "chrome/browser/search_engines/template_url.h" | 22 #include "chrome/browser/search_engines/template_url.h" |
20 #include "chrome/browser/search_engines/template_url_service.h" | 23 #include "chrome/browser/search_engines/template_url_service.h" |
21 #include "chrome/browser/search_engines/template_url_service_factory.h" | 24 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 25 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
22 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
| 27 #include "chrome/common/pref_names.h" |
23 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/navigation_entry.h" | 29 #include "content/public/browser/navigation_entry.h" |
25 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
26 #include "net/http/http_util.h" | 31 #include "net/http/http_util.h" |
27 | 32 |
28 #if defined(OS_CHROMEOS) | 33 #if defined(OS_CHROMEOS) |
29 #include "base/threading/sequenced_worker_pool.h" | 34 #include "base/threading/sequenced_worker_pool.h" |
30 #endif | 35 #endif |
31 | 36 |
32 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
(...skipping 17 matching lines...) Expand all Loading... |
50 } // namespace GoogleUpdateSettings | 55 } // namespace GoogleUpdateSettings |
51 #endif | 56 #endif |
52 | 57 |
53 using content::BrowserThread; | 58 using content::BrowserThread; |
54 using content::NavigationEntry; | 59 using content::NavigationEntry; |
55 | 60 |
56 namespace { | 61 namespace { |
57 | 62 |
58 const char kRlzThreadName[] = "RLZ_thread"; | 63 const char kRlzThreadName[] = "RLZ_thread"; |
59 | 64 |
| 65 bool IsGoogleUrl(const GURL& url) { |
| 66 return google_util::IsGoogleHomePageUrl(url.possibly_invalid_spec()); |
| 67 } |
| 68 |
60 bool IsBrandOrganic(const std::string& brand) { | 69 bool IsBrandOrganic(const std::string& brand) { |
61 return brand.empty() || google_util::IsOrganic(brand); | 70 return brand.empty() || google_util::IsOrganic(brand); |
62 } | 71 } |
63 | 72 |
64 void RecordProductEvents(bool first_run, | 73 void RecordProductEvents(bool first_run, |
65 bool is_google_default_search, | 74 bool is_google_default_search, |
66 bool is_google_homepage, | 75 bool is_google_homepage, |
67 bool is_google_in_startpages, | 76 bool is_google_in_startpages, |
68 bool already_ran, | 77 bool already_ran, |
69 bool omnibox_used, | 78 bool omnibox_used, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 // static | 198 // static |
190 bool RLZTracker::InitRlzDelayed(bool first_run, | 199 bool RLZTracker::InitRlzDelayed(bool first_run, |
191 int delay, | 200 int delay, |
192 bool is_google_default_search, | 201 bool is_google_default_search, |
193 bool is_google_homepage, | 202 bool is_google_homepage, |
194 bool is_google_in_startpages) { | 203 bool is_google_in_startpages) { |
195 return GetInstance()->Init(first_run, delay, is_google_default_search, | 204 return GetInstance()->Init(first_run, delay, is_google_default_search, |
196 is_google_homepage, is_google_in_startpages); | 205 is_google_homepage, is_google_in_startpages); |
197 } | 206 } |
198 | 207 |
| 208 // static |
| 209 bool RLZTracker::InitRlzFromProfileDelayed(Profile* profile, |
| 210 bool first_run, |
| 211 int delay) { |
| 212 bool is_google_default_search = false; |
| 213 TemplateURLService* template_url_service = |
| 214 TemplateURLServiceFactory::GetForProfile(profile); |
| 215 if (template_url_service) { |
| 216 const TemplateURL* url_template = |
| 217 template_url_service->GetDefaultSearchProvider(); |
| 218 is_google_default_search = |
| 219 url_template && url_template->url_ref().HasGoogleBaseURLs(); |
| 220 } |
| 221 |
| 222 PrefService* pref_service = profile->GetPrefs(); |
| 223 bool is_google_homepage = google_util::IsGoogleHomePageUrl( |
| 224 pref_service->GetString(prefs::kHomePage)); |
| 225 |
| 226 bool is_google_in_startpages = false; |
| 227 SessionStartupPref session_startup_prefs = |
| 228 StartupBrowserCreator::GetSessionStartupPref( |
| 229 *CommandLine::ForCurrentProcess(), profile); |
| 230 if (session_startup_prefs.type == SessionStartupPref::URLS) { |
| 231 is_google_in_startpages = std::count_if(session_startup_prefs.urls.begin(), |
| 232 session_startup_prefs.urls.end(), |
| 233 IsGoogleUrl) > 0; |
| 234 } |
| 235 |
| 236 if (!InitRlzDelayed(first_run, delay, |
| 237 is_google_default_search, is_google_homepage, |
| 238 is_google_in_startpages)) { |
| 239 return false; |
| 240 } |
| 241 |
| 242 // Prime the RLZ cache for the home page access point so that its avaiable |
| 243 // for the startup page if needed (i.e., when the startup page is set to |
| 244 // the home page). |
| 245 GetAccessPointRlz(CHROME_HOME_PAGE, NULL); |
| 246 |
| 247 return true; |
| 248 } |
| 249 |
199 bool RLZTracker::Init(bool first_run, | 250 bool RLZTracker::Init(bool first_run, |
200 int delay, | 251 int delay, |
201 bool is_google_default_search, | 252 bool is_google_default_search, |
202 bool is_google_homepage, | 253 bool is_google_homepage, |
203 bool is_google_in_startpages) { | 254 bool is_google_in_startpages) { |
204 first_run_ = first_run; | 255 first_run_ = first_run; |
205 is_google_default_search_ = is_google_default_search; | 256 is_google_default_search_ = is_google_default_search; |
206 is_google_homepage_ = is_google_homepage; | 257 is_google_homepage_ = is_google_homepage; |
207 is_google_in_startpages_ = is_google_in_startpages; | 258 is_google_in_startpages_ = is_google_in_startpages; |
208 | 259 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 string16* not_used = NULL; | 570 string16* not_used = NULL; |
520 blocking_task_runner_->PostTask( | 571 blocking_task_runner_->PostTask( |
521 FROM_HERE, | 572 FROM_HERE, |
522 base::Bind(base::IgnoreResult(&RLZTracker::GetAccessPointRlz), point, | 573 base::Bind(base::IgnoreResult(&RLZTracker::GetAccessPointRlz), point, |
523 not_used)); | 574 not_used)); |
524 return true; | 575 return true; |
525 } | 576 } |
526 | 577 |
527 // static | 578 // static |
528 void RLZTracker::CleanupRlz() { | 579 void RLZTracker::CleanupRlz() { |
529 GetInstance()->rlz_cache_.clear(); | 580 RLZTracker* instance = GetInstance(); |
530 GetInstance()->registrar_.RemoveAll(); | 581 instance->rlz_cache_.clear(); |
| 582 instance->registrar_.RemoveAll(); |
| 583 #if defined(OS_CHROMEOS) |
| 584 if (instance->blocking_task_runner_) { |
| 585 instance->blocking_task_runner_->PostTask( |
| 586 FROM_HERE, |
| 587 base::Bind(&rlz_lib::CleanupRlz)); |
| 588 instance->rlz_thread_.Stop(); |
| 589 } |
| 590 #endif |
| 591 instance->blocking_task_runner_ = NULL; |
531 } | 592 } |
OLD | NEW |