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 "components/rlz/rlz_tracker.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/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
17 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
18 #include "components/rlz/rlz_tracker_delegate.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" |
| 29 #include "components/omnibox/browser/omnibox_log.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" |
19 #include "net/http/http_util.h" | 37 #include "net/http/http_util.h" |
20 | 38 |
21 namespace rlz { | 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 |
22 namespace { | 64 namespace { |
23 | 65 |
24 // Maximum and minimum delay for financial ping we would allow to be set through | 66 // Maximum and minimum delay for financial ping we would allow to be set through |
25 // master preferences. Somewhat arbitrary, may need to be adjusted in future. | 67 // master preferences. Somewhat arbitrary, may need to be adjusted in future. |
26 const base::TimeDelta kMaxInitDelay = base::TimeDelta::FromSeconds(200); | 68 const base::TimeDelta kMaxInitDelay = base::TimeDelta::FromSeconds(200); |
27 const base::TimeDelta kMinInitDelay = base::TimeDelta::FromSeconds(20); | 69 const base::TimeDelta kMinInitDelay = base::TimeDelta::FromSeconds(20); |
28 | 70 |
| 71 bool IsBrandOrganic(const std::string& brand) { |
| 72 return brand.empty() || google_brand::IsOrganic(brand); |
| 73 } |
| 74 |
29 void RecordProductEvents(bool first_run, | 75 void RecordProductEvents(bool first_run, |
30 bool is_google_default_search, | 76 bool is_google_default_search, |
31 bool is_google_homepage, | 77 bool is_google_homepage, |
32 bool is_google_in_startpages, | 78 bool is_google_in_startpages, |
33 bool already_ran, | 79 bool already_ran, |
34 bool omnibox_used, | 80 bool omnibox_used, |
35 bool homepage_used, | 81 bool homepage_used, |
36 bool app_list_used) { | 82 bool app_list_used) { |
37 TRACE_EVENT0("RLZ", "RecordProductEvents"); | 83 TRACE_EVENT0("RLZ", "RecordProductEvents"); |
38 // Record the installation of chrome. We call this all the time but the rlz | 84 // Record the installation of chrome. We call this all the time but the rlz |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 product_signature = "chrome"; | 185 product_signature = "chrome"; |
140 #endif | 186 #endif |
141 return rlz_lib::SendFinancialPing(rlz_lib::CHROME, points, | 187 return rlz_lib::SendFinancialPing(rlz_lib::CHROME, points, |
142 product_signature.c_str(), | 188 product_signature.c_str(), |
143 brand.c_str(), referral_ascii.c_str(), | 189 brand.c_str(), referral_ascii.c_str(), |
144 lang_ascii.c_str(), false, true); | 190 lang_ascii.c_str(), false, true); |
145 } | 191 } |
146 | 192 |
147 } // namespace | 193 } // namespace |
148 | 194 |
149 RLZTracker* RLZTracker::tracker_ = nullptr; | 195 RLZTracker* RLZTracker::tracker_ = NULL; |
150 | 196 |
151 // static | 197 // static |
152 RLZTracker* RLZTracker::GetInstance() { | 198 RLZTracker* RLZTracker::GetInstance() { |
153 return tracker_ ? tracker_ : Singleton<RLZTracker>::get(); | 199 return tracker_ ? tracker_ : Singleton<RLZTracker>::get(); |
154 } | 200 } |
155 | 201 |
156 RLZTracker::RLZTracker() | 202 RLZTracker::RLZTracker() |
157 : first_run_(false), | 203 : first_run_(false), |
158 send_ping_immediately_(false), | 204 send_ping_immediately_(false), |
159 is_google_default_search_(false), | 205 is_google_default_search_(false), |
160 is_google_homepage_(false), | 206 is_google_homepage_(false), |
161 is_google_in_startpages_(false), | 207 is_google_in_startpages_(false), |
| 208 worker_pool_token_(BrowserThread::GetBlockingPool()->GetSequenceToken()), |
162 already_ran_(false), | 209 already_ran_(false), |
163 omnibox_used_(false), | 210 omnibox_used_(false), |
164 homepage_used_(false), | 211 homepage_used_(false), |
165 app_list_used_(false), | 212 app_list_used_(false), |
166 min_init_delay_(kMinInitDelay) { | 213 min_init_delay_(kMinInitDelay) { |
167 } | 214 } |
168 | 215 |
169 RLZTracker::~RLZTracker() { | 216 RLZTracker::~RLZTracker() { |
170 } | 217 } |
171 | 218 |
172 // static | 219 // 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_) { | |
180 delegate_ = delegate.Pass(); | |
181 worker_pool_token_ = delegate_->GetBlockingPool()->GetSequenceToken(); | |
182 } | |
183 } | |
184 | |
185 // static | |
186 bool RLZTracker::InitRlzDelayed(bool first_run, | 220 bool RLZTracker::InitRlzDelayed(bool first_run, |
187 bool send_ping_immediately, | 221 bool send_ping_immediately, |
188 base::TimeDelta delay, | 222 base::TimeDelta delay, |
189 bool is_google_default_search, | 223 bool is_google_default_search, |
190 bool is_google_homepage, | 224 bool is_google_homepage, |
191 bool is_google_in_startpages) { | 225 bool is_google_in_startpages) { |
192 return GetInstance()->Init(first_run, send_ping_immediately, delay, | 226 return GetInstance()->Init(first_run, send_ping_immediately, delay, |
193 is_google_default_search, is_google_homepage, | 227 is_google_default_search, is_google_homepage, |
194 is_google_in_startpages); | 228 is_google_in_startpages); |
195 } | 229 } |
196 | 230 |
| 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 |
197 bool RLZTracker::Init(bool first_run, | 281 bool RLZTracker::Init(bool first_run, |
198 bool send_ping_immediately, | 282 bool send_ping_immediately, |
199 base::TimeDelta delay, | 283 base::TimeDelta delay, |
200 bool is_google_default_search, | 284 bool is_google_default_search, |
201 bool is_google_homepage, | 285 bool is_google_homepage, |
202 bool is_google_in_startpages) { | 286 bool is_google_in_startpages) { |
203 first_run_ = first_run; | 287 first_run_ = first_run; |
204 is_google_default_search_ = is_google_default_search; | 288 is_google_default_search_ = is_google_default_search; |
205 is_google_homepage_ = is_google_homepage; | 289 is_google_homepage_ = is_google_homepage; |
206 is_google_in_startpages_ = is_google_in_startpages; | 290 is_google_in_startpages_ = is_google_in_startpages; |
207 send_ping_immediately_ = send_ping_immediately; | 291 send_ping_immediately_ = send_ping_immediately; |
208 | 292 |
209 // Enable zero delays for testing. | 293 // Enable zero delays for testing. |
210 if (delegate_->ShouldEnableZeroDelayForTesting()) | 294 if (base::CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType)) |
211 EnableZeroDelayForTesting(); | 295 EnableZeroDelayForTesting(); |
212 | 296 |
213 delay = std::min(kMaxInitDelay, std::max(min_init_delay_, delay)); | 297 delay = std::min(kMaxInitDelay, std::max(min_init_delay_, delay)); |
214 | 298 |
215 if (delegate_->GetBrand(&brand_) && !delegate_->IsBrandOrganic(brand_)) { | 299 if (google_brand::GetBrand(&brand_) && !IsBrandOrganic(brand_)) { |
216 // Register for notifications from the omnibox so that we can record when | 300 // Register for notifications from the omnibox so that we can record when |
217 // the user performs a first search. | 301 // the user performs a first search. |
218 delegate_->SetOmniboxSearchCallback( | 302 registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, |
219 base::Bind(&RLZTracker::RecordFirstSearch, base::Unretained(this), | 303 content::NotificationService::AllSources()); |
220 ChromeOmnibox())); | |
221 | 304 |
222 #if !defined(OS_IOS) | 305 #if !defined(OS_IOS) |
223 // Register for notifications from navigations, to see if the user has used | 306 // Register for notifications from navigations, to see if the user has used |
224 // the home page. | 307 // the home page. |
225 delegate_->SetHomepageSearchCallback( | 308 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
226 base::Bind(&RLZTracker::RecordFirstSearch, base::Unretained(this), | 309 content::NotificationService::AllSources()); |
227 ChromeHomePage())); | 310 #endif // !defined(OS_IOS) |
228 #endif | |
229 } | 311 } |
230 delegate_->GetReactivationBrand(&reactivation_brand_); | 312 google_brand::GetReactivationBrand(&reactivation_brand_); |
231 | 313 |
232 // Could be null; don't run if so. RLZ will try again next restart. | 314 net::URLRequestContextGetter* context_getter = |
233 net::URLRequestContextGetter* context_getter = delegate_->GetRequestContext(); | 315 g_browser_process->system_request_context(); |
| 316 |
| 317 // Could be NULL; don't run if so. RLZ will try again next restart. |
234 if (context_getter) { | 318 if (context_getter) { |
235 rlz_lib::SetURLRequestContext(context_getter); | 319 rlz_lib::SetURLRequestContext(context_getter); |
236 ScheduleDelayedInit(delay); | 320 ScheduleDelayedInit(delay); |
237 } | 321 } |
238 | 322 |
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(), nullptr); | |
244 #endif // !defined(OS_IOS) | |
245 | |
246 return true; | 323 return true; |
247 } | 324 } |
248 | 325 |
249 void RLZTracker::Cleanup() { | |
250 rlz_cache_.clear(); | |
251 if (delegate_) | |
252 delegate_->Cleanup(); | |
253 } | |
254 | |
255 void RLZTracker::ScheduleDelayedInit(base::TimeDelta delay) { | 326 void RLZTracker::ScheduleDelayedInit(base::TimeDelta delay) { |
256 // The RLZTracker is a singleton object that outlives any runnable tasks | 327 // The RLZTracker is a singleton object that outlives any runnable tasks |
257 // that will be queued up. | 328 // that will be queued up. |
258 delegate_->GetBlockingPool()->PostDelayedSequencedWorkerTask( | 329 BrowserThread::GetBlockingPool()->PostDelayedSequencedWorkerTask( |
259 worker_pool_token_, FROM_HERE, | 330 worker_pool_token_, |
260 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), delay); | 331 FROM_HERE, |
| 332 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), |
| 333 delay); |
261 } | 334 } |
262 | 335 |
263 void RLZTracker::DelayedInit() { | 336 void RLZTracker::DelayedInit() { |
264 bool schedule_ping = false; | 337 bool schedule_ping = false; |
265 | 338 |
266 // For organic brandcodes do not use rlz at all. Empty brandcode usually | 339 // For organic brandcodes do not use rlz at all. Empty brandcode usually |
267 // means a chromium install. This is ok. | 340 // means a chromium install. This is ok. |
268 if (!delegate_->IsBrandOrganic(brand_)) { | 341 if (!IsBrandOrganic(brand_)) { |
269 RecordProductEvents(first_run_, is_google_default_search_, | 342 RecordProductEvents(first_run_, is_google_default_search_, |
270 is_google_homepage_, is_google_in_startpages_, | 343 is_google_homepage_, is_google_in_startpages_, |
271 already_ran_, omnibox_used_, homepage_used_, | 344 already_ran_, omnibox_used_, homepage_used_, |
272 app_list_used_); | 345 app_list_used_); |
273 schedule_ping = true; | 346 schedule_ping = true; |
274 } | 347 } |
275 | 348 |
276 // If chrome has been reactivated, record the events for this brand | 349 // If chrome has been reactivated, record the events for this brand |
277 // as well. | 350 // as well. |
278 if (!delegate_->IsBrandOrganic(reactivation_brand_)) { | 351 if (!IsBrandOrganic(reactivation_brand_)) { |
279 rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); | 352 rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); |
280 RecordProductEvents(first_run_, is_google_default_search_, | 353 RecordProductEvents(first_run_, is_google_default_search_, |
281 is_google_homepage_, is_google_in_startpages_, | 354 is_google_homepage_, is_google_in_startpages_, |
282 already_ran_, omnibox_used_, homepage_used_, | 355 already_ran_, omnibox_used_, homepage_used_, |
283 app_list_used_); | 356 app_list_used_); |
284 schedule_ping = true; | 357 schedule_ping = true; |
285 } | 358 } |
286 | 359 |
287 already_ran_ = true; | 360 already_ran_ = true; |
288 | 361 |
289 if (schedule_ping) | 362 if (schedule_ping) |
290 ScheduleFinancialPing(); | 363 ScheduleFinancialPing(); |
291 } | 364 } |
292 | 365 |
293 void RLZTracker::ScheduleFinancialPing() { | 366 void RLZTracker::ScheduleFinancialPing() { |
294 delegate_->GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( | 367 BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( |
295 worker_pool_token_, FROM_HERE, | 368 worker_pool_token_, |
| 369 FROM_HERE, |
296 base::Bind(&RLZTracker::PingNowImpl, base::Unretained(this)), | 370 base::Bind(&RLZTracker::PingNowImpl, base::Unretained(this)), |
297 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 371 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
298 } | 372 } |
299 | 373 |
300 void RLZTracker::PingNowImpl() { | 374 void RLZTracker::PingNowImpl() { |
301 TRACE_EVENT0("RLZ", "RLZTracker::PingNowImpl"); | 375 TRACE_EVENT0("RLZ", "RLZTracker::PingNowImpl"); |
302 base::string16 lang; | 376 base::string16 lang; |
303 delegate_->GetLanguage(&lang); | 377 GoogleUpdateSettings::GetLanguage(&lang); |
304 if (lang.empty()) | 378 if (lang.empty()) |
305 lang = base::ASCIIToUTF16("en"); | 379 lang = base::ASCIIToUTF16("en"); |
306 base::string16 referral; | 380 base::string16 referral; |
307 delegate_->GetReferral(&referral); | 381 GoogleUpdateSettings::GetReferral(&referral); |
308 | 382 |
309 if (!delegate_->IsBrandOrganic(brand_) && | 383 if (!IsBrandOrganic(brand_) && SendFinancialPing(brand_, lang, referral)) { |
310 SendFinancialPing(brand_, lang, referral)) { | 384 GoogleUpdateSettings::ClearReferral(); |
311 delegate_->ClearReferral(); | |
312 | 385 |
313 { | 386 { |
314 base::AutoLock lock(cache_lock_); | 387 base::AutoLock lock(cache_lock_); |
315 rlz_cache_.clear(); | 388 rlz_cache_.clear(); |
316 } | 389 } |
317 | 390 |
318 // Prime the RLZ cache for the access points we are interested in. | 391 // Prime the RLZ cache for the access points we are interested in. |
319 GetAccessPointRlz(RLZTracker::ChromeOmnibox(), nullptr); | 392 GetAccessPointRlz(RLZTracker::ChromeOmnibox(), NULL); |
320 #if !defined(OS_IOS) | 393 #if !defined(OS_IOS) |
321 GetAccessPointRlz(RLZTracker::ChromeHomePage(), nullptr); | 394 GetAccessPointRlz(RLZTracker::ChromeHomePage(), NULL); |
322 GetAccessPointRlz(RLZTracker::ChromeAppList(), nullptr); | 395 GetAccessPointRlz(RLZTracker::ChromeAppList(), NULL); |
323 #endif // !defined(OS_IOS) | 396 #endif // !defined(OS_IOS) |
324 } | 397 } |
325 | 398 |
326 if (!delegate_->IsBrandOrganic(reactivation_brand_)) { | 399 if (!IsBrandOrganic(reactivation_brand_)) { |
327 rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); | 400 rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); |
328 SendFinancialPing(reactivation_brand_, lang, referral); | 401 SendFinancialPing(reactivation_brand_, lang, referral); |
329 } | 402 } |
330 } | 403 } |
331 | 404 |
332 bool RLZTracker::SendFinancialPing(const std::string& brand, | 405 bool RLZTracker::SendFinancialPing(const std::string& brand, |
333 const base::string16& lang, | 406 const base::string16& lang, |
334 const base::string16& referral) { | 407 const base::string16& referral) { |
335 return ::rlz::SendFinancialPing(brand, lang, referral); | 408 return ::SendFinancialPing(brand, lang, referral); |
| 409 } |
| 410 |
| 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 } |
336 } | 472 } |
337 | 473 |
338 // static | 474 // static |
339 bool RLZTracker::RecordProductEvent(rlz_lib::Product product, | 475 bool RLZTracker::RecordProductEvent(rlz_lib::Product product, |
340 rlz_lib::AccessPoint point, | 476 rlz_lib::AccessPoint point, |
341 rlz_lib::Event event_id) { | 477 rlz_lib::Event event_id) { |
342 return GetInstance()->RecordProductEventImpl(product, point, event_id); | 478 return GetInstance()->RecordProductEventImpl(product, point, event_id); |
343 } | 479 } |
344 | 480 |
345 bool RLZTracker::RecordProductEventImpl(rlz_lib::Product product, | 481 bool RLZTracker::RecordProductEventImpl(rlz_lib::Product product, |
(...skipping 11 matching lines...) Expand all Loading... |
357 rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); | 493 rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); |
358 ret &= rlz_lib::RecordProductEvent(product, point, event_id); | 494 ret &= rlz_lib::RecordProductEvent(product, point, event_id); |
359 } | 495 } |
360 | 496 |
361 return ret; | 497 return ret; |
362 } | 498 } |
363 | 499 |
364 bool RLZTracker::ScheduleRecordProductEvent(rlz_lib::Product product, | 500 bool RLZTracker::ScheduleRecordProductEvent(rlz_lib::Product product, |
365 rlz_lib::AccessPoint point, | 501 rlz_lib::AccessPoint point, |
366 rlz_lib::Event event_id) { | 502 rlz_lib::Event event_id) { |
367 if (!delegate_->IsOnUIThread()) | 503 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) |
368 return false; | 504 return false; |
369 | 505 |
370 delegate_->GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( | 506 BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( |
371 worker_pool_token_, FROM_HERE, | 507 worker_pool_token_, |
372 base::Bind(base::IgnoreResult(&RLZTracker::RecordProductEvent), product, | 508 FROM_HERE, |
373 point, event_id), | 509 base::Bind(base::IgnoreResult(&RLZTracker::RecordProductEvent), |
| 510 product, point, event_id), |
374 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 511 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
375 | 512 |
376 return true; | 513 return true; |
377 } | 514 } |
378 | 515 |
379 void RLZTracker::RecordFirstSearch(rlz_lib::AccessPoint point) { | 516 void RLZTracker::RecordFirstSearch(rlz_lib::AccessPoint point) { |
380 // Make sure we don't access disk outside of the I/O thread. | 517 // Make sure we don't access disk outside of the I/O thread. |
381 // In such case we repost the task on the right thread and return error. | 518 // In such case we repost the task on the right thread and return error. |
382 if (ScheduleRecordFirstSearch(point)) | 519 if (ScheduleRecordFirstSearch(point)) |
383 return; | 520 return; |
384 | 521 |
385 bool* record_used = GetAccessPointRecord(point); | 522 bool* record_used = GetAccessPointRecord(point); |
386 | 523 |
387 // Try to record event now, else set the flag to try later when we | 524 // Try to record event now, else set the flag to try later when we |
388 // attempt the ping. | 525 // attempt the ping. |
389 if (!RecordProductEvent(rlz_lib::CHROME, point, rlz_lib::FIRST_SEARCH)) | 526 if (!RecordProductEvent(rlz_lib::CHROME, point, rlz_lib::FIRST_SEARCH)) |
390 *record_used = true; | 527 *record_used = true; |
391 else if (send_ping_immediately_ && point == ChromeOmnibox()) | 528 else if (send_ping_immediately_ && point == ChromeOmnibox()) |
392 ScheduleDelayedInit(base::TimeDelta()); | 529 ScheduleDelayedInit(base::TimeDelta()); |
393 } | 530 } |
394 | 531 |
395 bool RLZTracker::ScheduleRecordFirstSearch(rlz_lib::AccessPoint point) { | 532 bool RLZTracker::ScheduleRecordFirstSearch(rlz_lib::AccessPoint point) { |
396 if (!delegate_->IsOnUIThread()) | 533 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) |
397 return false; | 534 return false; |
398 delegate_->GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( | 535 BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( |
399 worker_pool_token_, FROM_HERE, | 536 worker_pool_token_, |
400 base::Bind(&RLZTracker::RecordFirstSearch, base::Unretained(this), point), | 537 FROM_HERE, |
| 538 base::Bind(&RLZTracker::RecordFirstSearch, |
| 539 base::Unretained(this), point), |
401 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 540 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
402 return true; | 541 return true; |
403 } | 542 } |
404 | 543 |
405 bool* RLZTracker::GetAccessPointRecord(rlz_lib::AccessPoint point) { | 544 bool* RLZTracker::GetAccessPointRecord(rlz_lib::AccessPoint point) { |
406 if (point == ChromeOmnibox()) | 545 if (point == ChromeOmnibox()) |
407 return &omnibox_used_; | 546 return &omnibox_used_; |
408 #if !defined(OS_IOS) | 547 #if !defined(OS_IOS) |
409 if (point == ChromeHomePage()) | 548 if (point == ChromeHomePage()) |
410 return &homepage_used_; | 549 return &homepage_used_; |
411 if (point == ChromeAppList()) | 550 if (point == ChromeAppList()) |
412 return &app_list_used_; | 551 return &app_list_used_; |
413 #endif // !defined(OS_IOS) | 552 #endif // !defined(OS_IOS) |
414 NOTREACHED(); | 553 NOTREACHED(); |
415 return nullptr; | 554 return NULL; |
416 } | 555 } |
417 | 556 |
418 // static | 557 // static |
419 std::string RLZTracker::GetAccessPointHttpHeader(rlz_lib::AccessPoint point) { | 558 std::string RLZTracker::GetAccessPointHttpHeader(rlz_lib::AccessPoint point) { |
420 TRACE_EVENT0("RLZ", "RLZTracker::GetAccessPointHttpHeader"); | 559 TRACE_EVENT0("RLZ", "RLZTracker::GetAccessPointHttpHeader"); |
421 std::string extra_headers; | 560 std::string extra_headers; |
422 base::string16 rlz_string; | 561 base::string16 rlz_string; |
423 RLZTracker::GetAccessPointRlz(point, &rlz_string); | 562 RLZTracker::GetAccessPointRlz(point, &rlz_string); |
424 if (!rlz_string.empty()) { | 563 if (!rlz_string.empty()) { |
425 net::HttpUtil::AppendHeaderIfMissing("X-Rlz-String", | 564 net::HttpUtil::AppendHeaderIfMissing("X-Rlz-String", |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 base::string16 rlz_local(base::ASCIIToUTF16(str_rlz)); | 604 base::string16 rlz_local(base::ASCIIToUTF16(str_rlz)); |
466 if (rlz) | 605 if (rlz) |
467 *rlz = rlz_local; | 606 *rlz = rlz_local; |
468 | 607 |
469 base::AutoLock lock(cache_lock_); | 608 base::AutoLock lock(cache_lock_); |
470 rlz_cache_[point] = rlz_local; | 609 rlz_cache_[point] = rlz_local; |
471 return true; | 610 return true; |
472 } | 611 } |
473 | 612 |
474 bool RLZTracker::ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) { | 613 bool RLZTracker::ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) { |
475 if (!delegate_->IsOnUIThread()) | 614 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) |
476 return false; | 615 return false; |
477 | 616 |
478 base::string16* not_used = nullptr; | 617 base::string16* not_used = NULL; |
479 delegate_->GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( | 618 BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( |
480 worker_pool_token_, FROM_HERE, | 619 worker_pool_token_, |
| 620 FROM_HERE, |
481 base::Bind(base::IgnoreResult(&RLZTracker::GetAccessPointRlz), point, | 621 base::Bind(base::IgnoreResult(&RLZTracker::GetAccessPointRlz), point, |
482 not_used), | 622 not_used), |
483 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 623 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
484 return true; | 624 return true; |
485 } | 625 } |
486 | 626 |
487 #if defined(OS_CHROMEOS) | 627 #if defined(OS_CHROMEOS) |
488 // static | 628 // static |
489 void RLZTracker::ClearRlzState() { | 629 void RLZTracker::ClearRlzState() { |
490 GetInstance()->ClearRlzStateImpl(); | 630 GetInstance()->ClearRlzStateImpl(); |
491 } | 631 } |
492 | 632 |
493 void RLZTracker::ClearRlzStateImpl() { | 633 void RLZTracker::ClearRlzStateImpl() { |
494 if (ScheduleClearRlzState()) | 634 if (ScheduleClearRlzState()) |
495 return; | 635 return; |
496 rlz_lib::ClearAllProductEvents(rlz_lib::CHROME); | 636 rlz_lib::ClearAllProductEvents(rlz_lib::CHROME); |
497 } | 637 } |
498 | 638 |
499 bool RLZTracker::ScheduleClearRlzState() { | 639 bool RLZTracker::ScheduleClearRlzState() { |
500 if (!delegate_->IsOnUIThread()) | 640 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) |
501 return false; | 641 return false; |
502 | 642 |
503 delegate_->GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( | 643 BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( |
504 worker_pool_token_, FROM_HERE, | 644 worker_pool_token_, |
505 base::Bind(&RLZTracker::ClearRlzStateImpl, base::Unretained(this)), | 645 FROM_HERE, |
| 646 base::Bind(&RLZTracker::ClearRlzStateImpl, |
| 647 base::Unretained(this)), |
506 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 648 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
507 return true; | 649 return true; |
508 } | 650 } |
509 #endif | 651 #endif |
510 | 652 |
511 // static | 653 // static |
512 void RLZTracker::CleanupRlz() { | 654 void RLZTracker::CleanupRlz() { |
513 GetInstance()->Cleanup(); | 655 GetInstance()->rlz_cache_.clear(); |
514 rlz_lib::SetURLRequestContext(nullptr); | 656 GetInstance()->registrar_.RemoveAll(); |
| 657 rlz_lib::SetURLRequestContext(NULL); |
515 } | 658 } |
516 | 659 |
517 // static | 660 // static |
518 void RLZTracker::EnableZeroDelayForTesting() { | 661 void RLZTracker::EnableZeroDelayForTesting() { |
519 GetInstance()->min_init_delay_ = base::TimeDelta(); | 662 GetInstance()->min_init_delay_ = base::TimeDelta(); |
520 } | 663 } |
521 | 664 |
522 #if !defined(OS_IOS) | 665 #if !defined(OS_IOS) |
523 // static | 666 // static |
524 void RLZTracker::RecordAppListSearch() { | 667 void RLZTracker::RecordAppListSearch() { |
525 GetInstance()->RecordFirstSearch(RLZTracker::ChromeAppList()); | 668 GetInstance()->RecordFirstSearch(RLZTracker::ChromeAppList()); |
526 } | 669 } |
527 #endif | 670 #endif |
528 | |
529 } // namespace rlz | |
OLD | NEW |