Chromium Code Reviews| 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 "components/rlz/rlz_tracker.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" | |
| 15 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 16 #include "base/prefs/pref_service.h" | |
| 17 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 20 #include "chrome/browser/browser_process.h" | |
| 21 #include "chrome/browser/chrome_notification_types.h" | |
| 22 #include "chrome/browser/google/google_brand.h" | |
| 23 #include "chrome/browser/prefs/session_startup_pref.h" | |
| 24 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
| 25 #include "chrome/browser/ui/startup/startup_browser_creator.h" | |
| 26 #include "chrome/common/chrome_switches.h" | |
| 27 #include "chrome/common/pref_names.h" | |
| 28 #include "components/google/core/browser/google_util.h" | 18 #include "components/google/core/browser/google_util.h" |
| 29 #include "components/omnibox/omnibox_log.h" | 19 #include "components/rlz/rlz_tracker_delegate.h" |
| 30 #include "components/search_engines/template_url.h" | |
| 31 #include "components/search_engines/template_url_service.h" | |
| 32 #include "content/public/browser/browser_thread.h" | |
| 33 #include "content/public/browser/navigation_controller.h" | |
| 34 #include "content/public/browser/navigation_details.h" | |
| 35 #include "content/public/browser/navigation_entry.h" | |
| 36 #include "content/public/browser/notification_service.h" | |
| 37 #include "net/http/http_util.h" | 20 #include "net/http/http_util.h" |
| 38 | 21 |
| 39 #if defined(OS_WIN) | |
| 40 #include "chrome/installer/util/google_update_settings.h" | |
| 41 #else | |
| 42 namespace GoogleUpdateSettings { | |
| 43 static bool GetLanguage(base::string16* language) { | |
| 44 // TODO(thakis): Implement. | |
| 45 NOTIMPLEMENTED(); | |
| 46 return false; | |
| 47 } | |
| 48 | |
| 49 // The referral program is defunct and not used. No need to implement these | |
| 50 // functions on non-Win platforms. | |
| 51 static bool GetReferral(base::string16* referral) { | |
| 52 return true; | |
| 53 } | |
| 54 static bool ClearReferral() { | |
| 55 return true; | |
| 56 } | |
| 57 } // namespace GoogleUpdateSettings | |
| 58 #endif | |
| 59 | |
| 60 using content::BrowserThread; | |
| 61 using content::NavigationEntry; | |
| 62 using content::NavigationController; | |
| 63 | |
| 64 namespace { | 22 namespace { |
| 65 | 23 |
| 66 // Maximum and minimum delay for financial ping we would allow to be set through | 24 // Maximum and minimum delay for financial ping we would allow to be set through |
| 67 // master preferences. Somewhat arbitrary, may need to be adjusted in future. | 25 // master preferences. Somewhat arbitrary, may need to be adjusted in future. |
| 68 const base::TimeDelta kMaxInitDelay = base::TimeDelta::FromSeconds(200); | 26 const base::TimeDelta kMaxInitDelay = base::TimeDelta::FromSeconds(200); |
| 69 const base::TimeDelta kMinInitDelay = base::TimeDelta::FromSeconds(20); | 27 const base::TimeDelta kMinInitDelay = base::TimeDelta::FromSeconds(20); |
| 70 | 28 |
| 71 bool IsBrandOrganic(const std::string& brand) { | |
| 72 return brand.empty() || google_brand::IsOrganic(brand); | |
| 73 } | |
| 74 | |
| 75 void RecordProductEvents(bool first_run, | 29 void RecordProductEvents(bool first_run, |
| 76 bool is_google_default_search, | 30 bool is_google_default_search, |
| 77 bool is_google_homepage, | 31 bool is_google_homepage, |
| 78 bool is_google_in_startpages, | 32 bool is_google_in_startpages, |
| 79 bool already_ran, | 33 bool already_ran, |
| 80 bool omnibox_used, | 34 bool omnibox_used, |
| 81 bool homepage_used, | 35 bool homepage_used, |
| 82 bool app_list_used) { | 36 bool app_list_used) { |
| 83 TRACE_EVENT0("RLZ", "RecordProductEvents"); | 37 TRACE_EVENT0("RLZ", "RecordProductEvents"); |
| 84 // Record the installation of chrome. We call this all the time but the rlz | 38 // Record the installation of chrome. We call this all the time but the rlz |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 RLZTracker* RLZTracker::GetInstance() { | 152 RLZTracker* RLZTracker::GetInstance() { |
| 199 return tracker_ ? tracker_ : Singleton<RLZTracker>::get(); | 153 return tracker_ ? tracker_ : Singleton<RLZTracker>::get(); |
| 200 } | 154 } |
| 201 | 155 |
| 202 RLZTracker::RLZTracker() | 156 RLZTracker::RLZTracker() |
| 203 : first_run_(false), | 157 : first_run_(false), |
| 204 send_ping_immediately_(false), | 158 send_ping_immediately_(false), |
| 205 is_google_default_search_(false), | 159 is_google_default_search_(false), |
| 206 is_google_homepage_(false), | 160 is_google_homepage_(false), |
| 207 is_google_in_startpages_(false), | 161 is_google_in_startpages_(false), |
| 208 worker_pool_token_(BrowserThread::GetBlockingPool()->GetSequenceToken()), | |
| 209 already_ran_(false), | 162 already_ran_(false), |
| 210 omnibox_used_(false), | 163 omnibox_used_(false), |
| 211 homepage_used_(false), | 164 homepage_used_(false), |
| 212 app_list_used_(false), | 165 app_list_used_(false), |
| 213 min_init_delay_(kMinInitDelay) { | 166 min_init_delay_(kMinInitDelay) { |
| 214 } | 167 } |
| 215 | 168 |
| 216 RLZTracker::~RLZTracker() { | 169 RLZTracker::~RLZTracker() { |
| 217 } | 170 } |
| 218 | 171 |
| 219 // static | 172 // static |
| 173 void RLZTracker::SetRlzDelegate(scoped_ptr<RLZTrackerDelegate> delegate) { | |
| 174 GetInstance()->SetDelegate(delegate.Pass()); | |
| 175 } | |
| 176 | |
| 177 void RLZTracker::SetDelegate(scoped_ptr<RLZTrackerDelegate> delegate) { | |
| 178 DCHECK(delegate); | |
| 179 if (!delegate_) { | |
|
Roger Tawa OOO till Jul 10th
2015/07/02 18:22:28
DCHECK(!delegate_); ? When would we want to chan
sdefresne
2015/07/03 16:16:37
RLZTracker is a singleton that is not tied to the
Roger Tawa OOO till Jul 10th
2015/07/03 17:25:20
Acknowledged.
| |
| 180 delegate_ = delegate.Pass(); | |
| 181 worker_pool_token_ = delegate_->GetBlockingPool()->GetSequenceToken(); | |
| 182 } | |
| 183 } | |
| 184 | |
| 185 // static | |
| 220 bool RLZTracker::InitRlzDelayed(bool first_run, | 186 bool RLZTracker::InitRlzDelayed(bool first_run, |
| 221 bool send_ping_immediately, | 187 bool send_ping_immediately, |
| 222 base::TimeDelta delay, | 188 base::TimeDelta delay, |
| 223 bool is_google_default_search, | 189 bool is_google_default_search, |
| 224 bool is_google_homepage, | 190 bool is_google_homepage, |
| 225 bool is_google_in_startpages) { | 191 bool is_google_in_startpages) { |
| 226 return GetInstance()->Init(first_run, send_ping_immediately, delay, | 192 return GetInstance()->Init(first_run, send_ping_immediately, delay, |
| 227 is_google_default_search, is_google_homepage, | 193 is_google_default_search, is_google_homepage, |
| 228 is_google_in_startpages); | 194 is_google_in_startpages); |
| 229 } | 195 } |
| 230 | 196 |
| 231 // static | |
| 232 bool RLZTracker::InitRlzFromProfileDelayed(Profile* profile, | |
| 233 bool first_run, | |
| 234 bool send_ping_immediately, | |
| 235 base::TimeDelta delay) { | |
| 236 bool is_google_default_search = false; | |
| 237 TemplateURLService* template_url_service = | |
| 238 TemplateURLServiceFactory::GetForProfile(profile); | |
| 239 if (template_url_service) { | |
| 240 const TemplateURL* url_template = | |
| 241 template_url_service->GetDefaultSearchProvider(); | |
| 242 is_google_default_search = | |
| 243 url_template && url_template->url_ref().HasGoogleBaseURLs( | |
| 244 template_url_service->search_terms_data()); | |
| 245 } | |
| 246 | |
| 247 PrefService* pref_service = profile->GetPrefs(); | |
| 248 bool is_google_homepage = google_util::IsGoogleHomePageUrl( | |
| 249 GURL(pref_service->GetString(prefs::kHomePage))); | |
| 250 | |
| 251 bool is_google_in_startpages = false; | |
| 252 #if !defined(OS_IOS) | |
| 253 // iOS does not have a notion of startpages. | |
| 254 SessionStartupPref session_startup_prefs = | |
| 255 StartupBrowserCreator::GetSessionStartupPref( | |
| 256 *base::CommandLine::ForCurrentProcess(), profile); | |
| 257 if (session_startup_prefs.type == SessionStartupPref::URLS) { | |
| 258 is_google_in_startpages = | |
| 259 std::count_if(session_startup_prefs.urls.begin(), | |
| 260 session_startup_prefs.urls.end(), | |
| 261 google_util::IsGoogleHomePageUrl) > 0; | |
| 262 } | |
| 263 #endif | |
| 264 | |
| 265 if (!InitRlzDelayed(first_run, send_ping_immediately, delay, | |
| 266 is_google_default_search, is_google_homepage, | |
| 267 is_google_in_startpages)) { | |
| 268 return false; | |
| 269 } | |
| 270 | |
| 271 #if !defined(OS_IOS) | |
| 272 // Prime the RLZ cache for the home page access point so that its avaiable | |
| 273 // for the startup page if needed (i.e., when the startup page is set to | |
| 274 // the home page). | |
| 275 GetAccessPointRlz(ChromeHomePage(), NULL); | |
| 276 #endif // !defined(OS_IOS) | |
| 277 | |
| 278 return true; | |
| 279 } | |
| 280 | |
| 281 bool RLZTracker::Init(bool first_run, | 197 bool RLZTracker::Init(bool first_run, |
| 282 bool send_ping_immediately, | 198 bool send_ping_immediately, |
| 283 base::TimeDelta delay, | 199 base::TimeDelta delay, |
| 284 bool is_google_default_search, | 200 bool is_google_default_search, |
| 285 bool is_google_homepage, | 201 bool is_google_homepage, |
| 286 bool is_google_in_startpages) { | 202 bool is_google_in_startpages) { |
| 287 first_run_ = first_run; | 203 first_run_ = first_run; |
| 288 is_google_default_search_ = is_google_default_search; | 204 is_google_default_search_ = is_google_default_search; |
| 289 is_google_homepage_ = is_google_homepage; | 205 is_google_homepage_ = is_google_homepage; |
| 290 is_google_in_startpages_ = is_google_in_startpages; | 206 is_google_in_startpages_ = is_google_in_startpages; |
| 291 send_ping_immediately_ = send_ping_immediately; | 207 send_ping_immediately_ = send_ping_immediately; |
| 292 | 208 |
| 293 // Enable zero delays for testing. | 209 // Enable zero delays for testing. |
| 294 if (base::CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType)) | 210 if (delegate_->ShouldEnableZeroDelayForTesting()) |
| 295 EnableZeroDelayForTesting(); | 211 EnableZeroDelayForTesting(); |
| 296 | 212 |
| 297 delay = std::min(kMaxInitDelay, std::max(min_init_delay_, delay)); | 213 delay = std::min(kMaxInitDelay, std::max(min_init_delay_, delay)); |
| 298 | 214 |
| 299 if (google_brand::GetBrand(&brand_) && !IsBrandOrganic(brand_)) { | 215 if (delegate_->GetBrand(&brand_) && !delegate_->IsBrandOrganic(brand_)) { |
| 300 // Register for notifications from the omnibox so that we can record when | 216 // Register for notifications from the omnibox so that we can record when |
| 301 // the user performs a first search. | 217 // the user performs a first search. |
| 302 registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, | 218 delegate_->SetOmniboxSearchCallback( |
| 303 content::NotificationService::AllSources()); | 219 base::Bind(&RLZTracker::RecordFirstSearch, base::Unretained(this), |
| 220 ChromeOmnibox())); | |
| 304 | 221 |
| 305 #if !defined(OS_IOS) | 222 #if !defined(OS_IOS) |
| 306 // Register for notifications from navigations, to see if the user has used | 223 // Register for notifications from navigations, to see if the user has used |
| 307 // the home page. | 224 // the home page. |
| 308 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 225 delegate_->SetOmniboxSearchCallback( |
| 309 content::NotificationService::AllSources()); | 226 base::Bind(&RLZTracker::RecordFirstSearch, base::Unretained(this), |
| 310 #endif // !defined(OS_IOS) | 227 ChromeHomePage())); |
| 228 #endif | |
| 311 } | 229 } |
| 312 google_brand::GetReactivationBrand(&reactivation_brand_); | 230 delegate_->GetReactivationBrand(&reactivation_brand_); |
| 313 | |
| 314 net::URLRequestContextGetter* context_getter = | |
| 315 g_browser_process->system_request_context(); | |
| 316 | 231 |
| 317 // Could be NULL; don't run if so. RLZ will try again next restart. | 232 // Could be NULL; don't run if so. RLZ will try again next restart. |
| 233 net::URLRequestContextGetter* context_getter = delegate_->GetRequestContext(); | |
| 318 if (context_getter) { | 234 if (context_getter) { |
| 319 rlz_lib::SetURLRequestContext(context_getter); | 235 rlz_lib::SetURLRequestContext(context_getter); |
| 320 ScheduleDelayedInit(delay); | 236 ScheduleDelayedInit(delay); |
| 321 } | 237 } |
| 322 | 238 |
| 239 #if !defined(OS_IOS) | |
| 240 // Prime the RLZ cache for the home page access point so that its avaiable | |
| 241 // for the startup page if needed (i.e., when the startup page is set to | |
| 242 // the home page). | |
| 243 GetAccessPointRlz(ChromeHomePage(), NULL); | |
| 244 #endif // !defined(OS_IOS) | |
| 245 | |
| 323 return true; | 246 return true; |
| 324 } | 247 } |
| 325 | 248 |
| 249 void RLZTracker::Cleanup() { | |
| 250 rlz_cache_.clear(); | |
| 251 if (delegate_) | |
| 252 delegate_->Cleanup(); | |
| 253 } | |
| 254 | |
| 326 void RLZTracker::ScheduleDelayedInit(base::TimeDelta delay) { | 255 void RLZTracker::ScheduleDelayedInit(base::TimeDelta delay) { |
| 327 // The RLZTracker is a singleton object that outlives any runnable tasks | 256 // The RLZTracker is a singleton object that outlives any runnable tasks |
| 328 // that will be queued up. | 257 // that will be queued up. |
| 329 BrowserThread::GetBlockingPool()->PostDelayedSequencedWorkerTask( | 258 delegate_->GetBlockingPool()->PostDelayedSequencedWorkerTask( |
| 330 worker_pool_token_, | 259 worker_pool_token_, FROM_HERE, |
| 331 FROM_HERE, | 260 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), delay); |
| 332 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), | |
| 333 delay); | |
| 334 } | 261 } |
| 335 | 262 |
| 336 void RLZTracker::DelayedInit() { | 263 void RLZTracker::DelayedInit() { |
| 337 bool schedule_ping = false; | 264 bool schedule_ping = false; |
| 338 | 265 |
| 339 // For organic brandcodes do not use rlz at all. Empty brandcode usually | 266 // For organic brandcodes do not use rlz at all. Empty brandcode usually |
| 340 // means a chromium install. This is ok. | 267 // means a chromium install. This is ok. |
| 341 if (!IsBrandOrganic(brand_)) { | 268 if (!delegate_->IsBrandOrganic(brand_)) { |
| 342 RecordProductEvents(first_run_, is_google_default_search_, | 269 RecordProductEvents(first_run_, is_google_default_search_, |
| 343 is_google_homepage_, is_google_in_startpages_, | 270 is_google_homepage_, is_google_in_startpages_, |
| 344 already_ran_, omnibox_used_, homepage_used_, | 271 already_ran_, omnibox_used_, homepage_used_, |
| 345 app_list_used_); | 272 app_list_used_); |
| 346 schedule_ping = true; | 273 schedule_ping = true; |
| 347 } | 274 } |
| 348 | 275 |
| 349 // If chrome has been reactivated, record the events for this brand | 276 // If chrome has been reactivated, record the events for this brand |
| 350 // as well. | 277 // as well. |
| 351 if (!IsBrandOrganic(reactivation_brand_)) { | 278 if (!delegate_->IsBrandOrganic(reactivation_brand_)) { |
| 352 rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); | 279 rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); |
| 353 RecordProductEvents(first_run_, is_google_default_search_, | 280 RecordProductEvents(first_run_, is_google_default_search_, |
| 354 is_google_homepage_, is_google_in_startpages_, | 281 is_google_homepage_, is_google_in_startpages_, |
| 355 already_ran_, omnibox_used_, homepage_used_, | 282 already_ran_, omnibox_used_, homepage_used_, |
| 356 app_list_used_); | 283 app_list_used_); |
| 357 schedule_ping = true; | 284 schedule_ping = true; |
| 358 } | 285 } |
| 359 | 286 |
| 360 already_ran_ = true; | 287 already_ran_ = true; |
| 361 | 288 |
| 362 if (schedule_ping) | 289 if (schedule_ping) |
| 363 ScheduleFinancialPing(); | 290 ScheduleFinancialPing(); |
| 364 } | 291 } |
| 365 | 292 |
| 366 void RLZTracker::ScheduleFinancialPing() { | 293 void RLZTracker::ScheduleFinancialPing() { |
| 367 BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( | 294 delegate_->GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( |
| 368 worker_pool_token_, | 295 worker_pool_token_, FROM_HERE, |
| 369 FROM_HERE, | |
| 370 base::Bind(&RLZTracker::PingNowImpl, base::Unretained(this)), | 296 base::Bind(&RLZTracker::PingNowImpl, base::Unretained(this)), |
| 371 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 297 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 372 } | 298 } |
| 373 | 299 |
| 374 void RLZTracker::PingNowImpl() { | 300 void RLZTracker::PingNowImpl() { |
| 375 TRACE_EVENT0("RLZ", "RLZTracker::PingNowImpl"); | 301 TRACE_EVENT0("RLZ", "RLZTracker::PingNowImpl"); |
| 376 base::string16 lang; | 302 base::string16 lang; |
| 377 GoogleUpdateSettings::GetLanguage(&lang); | 303 delegate_->GetLanguage(&lang); |
| 378 if (lang.empty()) | 304 if (lang.empty()) |
| 379 lang = base::ASCIIToUTF16("en"); | 305 lang = base::ASCIIToUTF16("en"); |
| 380 base::string16 referral; | 306 base::string16 referral; |
| 381 GoogleUpdateSettings::GetReferral(&referral); | 307 delegate_->GetReferral(&referral); |
| 382 | 308 |
| 383 if (!IsBrandOrganic(brand_) && SendFinancialPing(brand_, lang, referral)) { | 309 if (!delegate_->IsBrandOrganic(brand_) && |
| 384 GoogleUpdateSettings::ClearReferral(); | 310 SendFinancialPing(brand_, lang, referral)) { |
| 311 delegate_->ClearReferral(); | |
| 385 | 312 |
| 386 { | 313 { |
| 387 base::AutoLock lock(cache_lock_); | 314 base::AutoLock lock(cache_lock_); |
| 388 rlz_cache_.clear(); | 315 rlz_cache_.clear(); |
| 389 } | 316 } |
| 390 | 317 |
| 391 // Prime the RLZ cache for the access points we are interested in. | 318 // Prime the RLZ cache for the access points we are interested in. |
| 392 GetAccessPointRlz(RLZTracker::ChromeOmnibox(), NULL); | 319 GetAccessPointRlz(RLZTracker::ChromeOmnibox(), NULL); |
| 393 #if !defined(OS_IOS) | 320 #if !defined(OS_IOS) |
| 394 GetAccessPointRlz(RLZTracker::ChromeHomePage(), NULL); | 321 GetAccessPointRlz(RLZTracker::ChromeHomePage(), NULL); |
| 395 GetAccessPointRlz(RLZTracker::ChromeAppList(), NULL); | 322 GetAccessPointRlz(RLZTracker::ChromeAppList(), NULL); |
| 396 #endif // !defined(OS_IOS) | 323 #endif // !defined(OS_IOS) |
| 397 } | 324 } |
| 398 | 325 |
| 399 if (!IsBrandOrganic(reactivation_brand_)) { | 326 if (!delegate_->IsBrandOrganic(reactivation_brand_)) { |
| 400 rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); | 327 rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); |
| 401 SendFinancialPing(reactivation_brand_, lang, referral); | 328 SendFinancialPing(reactivation_brand_, lang, referral); |
| 402 } | 329 } |
| 403 } | 330 } |
| 404 | 331 |
| 405 bool RLZTracker::SendFinancialPing(const std::string& brand, | 332 bool RLZTracker::SendFinancialPing(const std::string& brand, |
| 406 const base::string16& lang, | 333 const base::string16& lang, |
| 407 const base::string16& referral) { | 334 const base::string16& referral) { |
| 408 return ::SendFinancialPing(brand, lang, referral); | 335 return ::SendFinancialPing(brand, lang, referral); |
| 409 } | 336 } |
| 410 | 337 |
| 411 void RLZTracker::Observe(int type, | |
| 412 const content::NotificationSource& source, | |
| 413 const content::NotificationDetails& details) { | |
| 414 switch (type) { | |
| 415 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: | |
| 416 // In M-36, we made NOTIFICATION_OMNIBOX_OPENED_URL fire more often than | |
| 417 // it did previously. The RLZ folks want RLZ's "first search" detection | |
| 418 // to remain as unaffected as possible by this change. This test is | |
| 419 // there to keep the old behavior. | |
| 420 if (!content::Details<OmniboxLog>(details).ptr()->is_popup_open) | |
| 421 break; | |
| 422 RecordFirstSearch(ChromeOmnibox()); | |
| 423 registrar_.Remove(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, | |
| 424 content::NotificationService::AllSources()); | |
| 425 break; | |
| 426 #if !defined(OS_IOS) | |
| 427 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { | |
| 428 // Firstly check if it is a Google search. | |
| 429 content::LoadCommittedDetails* load_details = | |
| 430 content::Details<content::LoadCommittedDetails>(details).ptr(); | |
| 431 if (load_details == NULL) | |
| 432 break; | |
| 433 | |
| 434 NavigationEntry* entry = load_details->entry; | |
| 435 if (entry == NULL) | |
| 436 break; | |
| 437 | |
| 438 if (google_util::IsGoogleSearchUrl(entry->GetURL())) { | |
| 439 // If it is a Google search, check if it originates from HOMEPAGE by | |
| 440 // getting the previous NavigationEntry. | |
| 441 NavigationController* controller = | |
| 442 content::Source<NavigationController>(source).ptr(); | |
| 443 if (controller == NULL) | |
| 444 break; | |
| 445 | |
| 446 int entry_index = controller->GetLastCommittedEntryIndex(); | |
| 447 if (entry_index < 1) | |
| 448 break; | |
| 449 | |
| 450 const NavigationEntry* previous_entry = controller->GetEntryAtIndex( | |
| 451 entry_index - 1); | |
| 452 | |
| 453 if (previous_entry == NULL) | |
| 454 break; | |
| 455 | |
| 456 // Make sure it is a Google web page originated from HOMEPAGE. | |
| 457 if (google_util::IsGoogleHomePageUrl(previous_entry->GetURL()) && | |
| 458 ((previous_entry->GetTransitionType() & | |
| 459 ui::PAGE_TRANSITION_HOME_PAGE) != 0)) { | |
| 460 RecordFirstSearch(ChromeHomePage()); | |
| 461 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 462 content::NotificationService::AllSources()); | |
| 463 } | |
| 464 } | |
| 465 break; | |
| 466 } | |
| 467 #endif // !defined(OS_IOS) | |
| 468 default: | |
| 469 NOTREACHED(); | |
| 470 break; | |
| 471 } | |
| 472 } | |
| 473 | |
| 474 // static | 338 // static |
| 475 bool RLZTracker::RecordProductEvent(rlz_lib::Product product, | 339 bool RLZTracker::RecordProductEvent(rlz_lib::Product product, |
| 476 rlz_lib::AccessPoint point, | 340 rlz_lib::AccessPoint point, |
| 477 rlz_lib::Event event_id) { | 341 rlz_lib::Event event_id) { |
| 478 return GetInstance()->RecordProductEventImpl(product, point, event_id); | 342 return GetInstance()->RecordProductEventImpl(product, point, event_id); |
| 479 } | 343 } |
| 480 | 344 |
| 481 bool RLZTracker::RecordProductEventImpl(rlz_lib::Product product, | 345 bool RLZTracker::RecordProductEventImpl(rlz_lib::Product product, |
| 482 rlz_lib::AccessPoint point, | 346 rlz_lib::AccessPoint point, |
| 483 rlz_lib::Event event_id) { | 347 rlz_lib::Event event_id) { |
| 484 // Make sure we don't access disk outside of the I/O thread. | 348 // Make sure we don't access disk outside of the I/O thread. |
| 485 // In such case we repost the task on the right thread and return error. | 349 // In such case we repost the task on the right thread and return error. |
| 486 if (ScheduleRecordProductEvent(product, point, event_id)) | 350 if (ScheduleRecordProductEvent(product, point, event_id)) |
| 487 return true; | 351 return true; |
| 488 | 352 |
| 489 bool ret = rlz_lib::RecordProductEvent(product, point, event_id); | 353 bool ret = rlz_lib::RecordProductEvent(product, point, event_id); |
| 490 | 354 |
| 491 // If chrome has been reactivated, record the event for this brand as well. | 355 // If chrome has been reactivated, record the event for this brand as well. |
| 492 if (!reactivation_brand_.empty()) { | 356 if (!reactivation_brand_.empty()) { |
| 493 rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); | 357 rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); |
| 494 ret &= rlz_lib::RecordProductEvent(product, point, event_id); | 358 ret &= rlz_lib::RecordProductEvent(product, point, event_id); |
| 495 } | 359 } |
| 496 | 360 |
| 497 return ret; | 361 return ret; |
| 498 } | 362 } |
| 499 | 363 |
| 500 bool RLZTracker::ScheduleRecordProductEvent(rlz_lib::Product product, | 364 bool RLZTracker::ScheduleRecordProductEvent(rlz_lib::Product product, |
| 501 rlz_lib::AccessPoint point, | 365 rlz_lib::AccessPoint point, |
| 502 rlz_lib::Event event_id) { | 366 rlz_lib::Event event_id) { |
| 503 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) | 367 if (!delegate_->IsOnUIThread()) |
| 504 return false; | 368 return false; |
| 505 | 369 |
| 506 BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( | 370 delegate_->GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( |
| 507 worker_pool_token_, | 371 worker_pool_token_, FROM_HERE, |
| 508 FROM_HERE, | 372 base::Bind(base::IgnoreResult(&RLZTracker::RecordProductEvent), product, |
| 509 base::Bind(base::IgnoreResult(&RLZTracker::RecordProductEvent), | 373 point, event_id), |
| 510 product, point, event_id), | |
| 511 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 374 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 512 | 375 |
| 513 return true; | 376 return true; |
| 514 } | 377 } |
| 515 | 378 |
| 516 void RLZTracker::RecordFirstSearch(rlz_lib::AccessPoint point) { | 379 void RLZTracker::RecordFirstSearch(rlz_lib::AccessPoint point) { |
| 517 // Make sure we don't access disk outside of the I/O thread. | 380 // Make sure we don't access disk outside of the I/O thread. |
| 518 // In such case we repost the task on the right thread and return error. | 381 // In such case we repost the task on the right thread and return error. |
| 519 if (ScheduleRecordFirstSearch(point)) | 382 if (ScheduleRecordFirstSearch(point)) |
| 520 return; | 383 return; |
| 521 | 384 |
| 522 bool* record_used = GetAccessPointRecord(point); | 385 bool* record_used = GetAccessPointRecord(point); |
| 523 | 386 |
| 524 // Try to record event now, else set the flag to try later when we | 387 // Try to record event now, else set the flag to try later when we |
| 525 // attempt the ping. | 388 // attempt the ping. |
| 526 if (!RecordProductEvent(rlz_lib::CHROME, point, rlz_lib::FIRST_SEARCH)) | 389 if (!RecordProductEvent(rlz_lib::CHROME, point, rlz_lib::FIRST_SEARCH)) |
| 527 *record_used = true; | 390 *record_used = true; |
| 528 else if (send_ping_immediately_ && point == ChromeOmnibox()) | 391 else if (send_ping_immediately_ && point == ChromeOmnibox()) |
| 529 ScheduleDelayedInit(base::TimeDelta()); | 392 ScheduleDelayedInit(base::TimeDelta()); |
| 530 } | 393 } |
| 531 | 394 |
| 532 bool RLZTracker::ScheduleRecordFirstSearch(rlz_lib::AccessPoint point) { | 395 bool RLZTracker::ScheduleRecordFirstSearch(rlz_lib::AccessPoint point) { |
| 533 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) | 396 if (!delegate_->IsOnUIThread()) |
| 534 return false; | 397 return false; |
| 535 BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( | 398 delegate_->GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( |
| 536 worker_pool_token_, | 399 worker_pool_token_, FROM_HERE, |
| 537 FROM_HERE, | 400 base::Bind(&RLZTracker::RecordFirstSearch, base::Unretained(this), point), |
| 538 base::Bind(&RLZTracker::RecordFirstSearch, | |
| 539 base::Unretained(this), point), | |
| 540 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 401 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 541 return true; | 402 return true; |
| 542 } | 403 } |
| 543 | 404 |
| 544 bool* RLZTracker::GetAccessPointRecord(rlz_lib::AccessPoint point) { | 405 bool* RLZTracker::GetAccessPointRecord(rlz_lib::AccessPoint point) { |
| 545 if (point == ChromeOmnibox()) | 406 if (point == ChromeOmnibox()) |
| 546 return &omnibox_used_; | 407 return &omnibox_used_; |
| 547 #if !defined(OS_IOS) | 408 #if !defined(OS_IOS) |
| 548 if (point == ChromeHomePage()) | 409 if (point == ChromeHomePage()) |
| 549 return &homepage_used_; | 410 return &homepage_used_; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 base::string16 rlz_local(base::ASCIIToUTF16(str_rlz)); | 465 base::string16 rlz_local(base::ASCIIToUTF16(str_rlz)); |
| 605 if (rlz) | 466 if (rlz) |
| 606 *rlz = rlz_local; | 467 *rlz = rlz_local; |
| 607 | 468 |
| 608 base::AutoLock lock(cache_lock_); | 469 base::AutoLock lock(cache_lock_); |
| 609 rlz_cache_[point] = rlz_local; | 470 rlz_cache_[point] = rlz_local; |
| 610 return true; | 471 return true; |
| 611 } | 472 } |
| 612 | 473 |
| 613 bool RLZTracker::ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) { | 474 bool RLZTracker::ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) { |
| 614 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) | 475 if (!delegate_->IsOnUIThread()) |
| 615 return false; | 476 return false; |
| 616 | 477 |
| 617 base::string16* not_used = NULL; | 478 base::string16* not_used = NULL; |
| 618 BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( | 479 delegate_->GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( |
| 619 worker_pool_token_, | 480 worker_pool_token_, FROM_HERE, |
| 620 FROM_HERE, | |
| 621 base::Bind(base::IgnoreResult(&RLZTracker::GetAccessPointRlz), point, | 481 base::Bind(base::IgnoreResult(&RLZTracker::GetAccessPointRlz), point, |
| 622 not_used), | 482 not_used), |
| 623 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 483 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 624 return true; | 484 return true; |
| 625 } | 485 } |
| 626 | 486 |
| 627 #if defined(OS_CHROMEOS) | 487 #if defined(OS_CHROMEOS) |
| 628 // static | 488 // static |
| 629 void RLZTracker::ClearRlzState() { | 489 void RLZTracker::ClearRlzState() { |
| 630 GetInstance()->ClearRlzStateImpl(); | 490 GetInstance()->ClearRlzStateImpl(); |
| 631 } | 491 } |
| 632 | 492 |
| 633 void RLZTracker::ClearRlzStateImpl() { | 493 void RLZTracker::ClearRlzStateImpl() { |
| 634 if (ScheduleClearRlzState()) | 494 if (ScheduleClearRlzState()) |
| 635 return; | 495 return; |
| 636 rlz_lib::ClearAllProductEvents(rlz_lib::CHROME); | 496 rlz_lib::ClearAllProductEvents(rlz_lib::CHROME); |
| 637 } | 497 } |
| 638 | 498 |
| 639 bool RLZTracker::ScheduleClearRlzState() { | 499 bool RLZTracker::ScheduleClearRlzState() { |
| 640 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) | 500 if (!delegate_->IsOnUIThread()) |
| 641 return false; | 501 return false; |
| 642 | 502 |
| 643 BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( | 503 delegate_->GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( |
| 644 worker_pool_token_, | 504 worker_pool_token_, FROM_HERE, |
| 645 FROM_HERE, | 505 base::Bind(&RLZTracker::ClearRlzStateImpl, base::Unretained(this)), |
| 646 base::Bind(&RLZTracker::ClearRlzStateImpl, | |
| 647 base::Unretained(this)), | |
| 648 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 506 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 649 return true; | 507 return true; |
| 650 } | 508 } |
| 651 #endif | 509 #endif |
| 652 | 510 |
| 653 // static | 511 // static |
| 654 void RLZTracker::CleanupRlz() { | 512 void RLZTracker::CleanupRlz() { |
| 655 GetInstance()->rlz_cache_.clear(); | 513 GetInstance()->Cleanup(); |
| 656 GetInstance()->registrar_.RemoveAll(); | |
| 657 rlz_lib::SetURLRequestContext(NULL); | 514 rlz_lib::SetURLRequestContext(NULL); |
| 658 } | 515 } |
| 659 | 516 |
| 660 // static | 517 // static |
| 661 void RLZTracker::EnableZeroDelayForTesting() { | 518 void RLZTracker::EnableZeroDelayForTesting() { |
| 662 GetInstance()->min_init_delay_ = base::TimeDelta(); | 519 GetInstance()->min_init_delay_ = base::TimeDelta(); |
| 663 } | 520 } |
| 664 | 521 |
| 665 #if !defined(OS_IOS) | 522 #if !defined(OS_IOS) |
| 666 // static | 523 // static |
| 667 void RLZTracker::RecordAppListSearch() { | 524 void RLZTracker::RecordAppListSearch() { |
| 668 GetInstance()->RecordFirstSearch(RLZTracker::ChromeAppList()); | 525 GetInstance()->RecordFirstSearch(RLZTracker::ChromeAppList()); |
| 669 } | 526 } |
| 670 #endif | 527 #endif |
| OLD | NEW |