Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: chrome/browser/rlz/rlz.cc

Issue 11506006: [cros] RLZ tracking can be turned off via a flag file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-apply ps#16, it got lost Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 return true; 50 return true;
51 } 51 }
52 } // namespace GoogleUpdateSettings 52 } // namespace GoogleUpdateSettings
53 #endif 53 #endif
54 54
55 using content::BrowserThread; 55 using content::BrowserThread;
56 using content::NavigationEntry; 56 using content::NavigationEntry;
57 57
58 namespace { 58 namespace {
59 59
60 // Maximum and minimum delay for financial ping we would allow to be set through
61 // master preferences. Somewhat arbitrary, may need to be adjusted in future.
62 const int kMaxDelay = 200 * 1000;
63 const int kMinDelay = 20 * 1000;
64
60 bool IsGoogleUrl(const GURL& url) { 65 bool IsGoogleUrl(const GURL& url) {
61 return google_util::IsGoogleHomePageUrl(url.possibly_invalid_spec()); 66 return google_util::IsGoogleHomePageUrl(url.possibly_invalid_spec());
62 } 67 }
63 68
64 bool IsBrandOrganic(const std::string& brand) { 69 bool IsBrandOrganic(const std::string& brand) {
65 return brand.empty() || google_util::IsOrganic(brand); 70 return brand.empty() || google_util::IsOrganic(brand);
66 } 71 }
67 72
68 void RecordProductEvents(bool first_run, 73 void RecordProductEvents(bool first_run,
69 bool is_google_default_search, 74 bool is_google_default_search,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 RLZTracker* RLZTracker::GetInstance() { 178 RLZTracker* RLZTracker::GetInstance() {
174 return tracker_ ? tracker_ : Singleton<RLZTracker>::get(); 179 return tracker_ ? tracker_ : Singleton<RLZTracker>::get();
175 } 180 }
176 181
177 RLZTracker::RLZTracker() 182 RLZTracker::RLZTracker()
178 : first_run_(false), 183 : first_run_(false),
179 send_ping_immediately_(false), 184 send_ping_immediately_(false),
180 is_google_default_search_(false), 185 is_google_default_search_(false),
181 is_google_homepage_(false), 186 is_google_homepage_(false),
182 is_google_in_startpages_(false), 187 is_google_in_startpages_(false),
188 worker_pool_token_(BrowserThread::GetBlockingPool()->GetSequenceToken()),
183 already_ran_(false), 189 already_ran_(false),
184 omnibox_used_(false), 190 omnibox_used_(false),
185 homepage_used_(false) { 191 homepage_used_(false),
192 min_delay_(kMinDelay) {
186 } 193 }
187 194
188 RLZTracker::~RLZTracker() { 195 RLZTracker::~RLZTracker() {
189 } 196 }
190 197
191 // static 198 // static
192 bool RLZTracker::InitRlzDelayed(bool first_run, 199 bool RLZTracker::InitRlzDelayed(bool first_run,
193 int delay, 200 int delay,
194 bool is_google_default_search, 201 bool is_google_default_search,
195 bool is_google_homepage, 202 bool is_google_homepage,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 241
235 // Prime the RLZ cache for the home page access point so that its avaiable 242 // Prime the RLZ cache for the home page access point so that its avaiable
236 // for the startup page if needed (i.e., when the startup page is set to 243 // for the startup page if needed (i.e., when the startup page is set to
237 // the home page). 244 // the home page).
238 GetAccessPointRlz(CHROME_HOME_PAGE, NULL); 245 GetAccessPointRlz(CHROME_HOME_PAGE, NULL);
239 246
240 return true; 247 return true;
241 } 248 }
242 249
243 bool RLZTracker::Init(bool first_run, 250 bool RLZTracker::Init(bool first_run,
244 int delay, 251 int delay,
Peter Kasting 2012/12/17 20:14:03 This should be a TimeDelta, as should |min_delay_|
Ivan Korotkov 2012/12/20 09:20:42 Done.
245 bool is_google_default_search, 252 bool is_google_default_search,
246 bool is_google_homepage, 253 bool is_google_homepage,
247 bool is_google_in_startpages) { 254 bool is_google_in_startpages) {
248 first_run_ = first_run; 255 first_run_ = first_run;
249 is_google_default_search_ = is_google_default_search; 256 is_google_default_search_ = is_google_default_search;
250 is_google_homepage_ = is_google_homepage; 257 is_google_homepage_ = is_google_homepage;
251 is_google_in_startpages_ = is_google_in_startpages; 258 is_google_in_startpages_ = is_google_in_startpages;
252 259
253 // A negative delay means that a financial ping should be sent immediately 260 // A negative delay means that a financial ping should be sent immediately
254 // after a first search is recorded, without waiting for the next restart 261 // after a first search is recorded, without waiting for the next restart
255 // of chrome. However, we only want this behaviour on first run. 262 // of chrome. However, we only want this behaviour on first run.
256 send_ping_immediately_ = false; 263 send_ping_immediately_ = false;
257 if (delay < 0) { 264 if (delay < 0) {
258 send_ping_immediately_ = true; 265 send_ping_immediately_ = true;
259 delay = -delay; 266 delay = -delay;
260 } 267 }
261 268
262 // Maximum and minimum delay we would allow to be set through master
263 // preferences. Somewhat arbitrary, may need to be adjusted in future.
264 const int kMaxDelay = 200 * 1000;
265 const int kMinDelay = 20 * 1000;
266
267 delay *= 1000; 269 delay *= 1000;
268 delay = (delay < kMinDelay) ? kMinDelay : delay; 270 delay = (delay < min_delay_) ? min_delay_ : delay;
269 delay = (delay > kMaxDelay) ? kMaxDelay : delay; 271 delay = (delay > kMaxDelay) ? kMaxDelay : delay;
270 272
271 if (google_util::GetBrand(&brand_) && !IsBrandOrganic(brand_)) { 273 if (google_util::GetBrand(&brand_) && !IsBrandOrganic(brand_)) {
272 // Register for notifications from the omnibox so that we can record when 274 // Register for notifications from the omnibox so that we can record when
273 // the user performs a first search. 275 // the user performs a first search.
274 registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, 276 registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
275 content::NotificationService::AllSources()); 277 content::NotificationService::AllSources());
276 // If instant is enabled we'll start searching as soon as the user starts 278 // If instant is enabled we'll start searching as soon as the user starts
277 // typing in the omnibox (which triggers INSTANT_CONTROLLER_UPDATED). 279 // typing in the omnibox (which triggers INSTANT_CONTROLLER_UPDATED).
278 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, 280 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED,
279 content::NotificationService::AllSources()); 281 content::NotificationService::AllSources());
280 282
281 // Register for notifications from navigations, to see if the user has used 283 // Register for notifications from navigations, to see if the user has used
282 // the home page. 284 // the home page.
283 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, 285 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
284 content::NotificationService::AllSources()); 286 content::NotificationService::AllSources());
285 } 287 }
286 google_util::GetReactivationBrand(&reactivation_brand_); 288 google_util::GetReactivationBrand(&reactivation_brand_);
287 289
288 rlz_lib::SetURLRequestContext(g_browser_process->system_request_context()); 290 rlz_lib::SetURLRequestContext(g_browser_process->system_request_context());
289 ScheduleDelayedInit(delay); 291 ScheduleDelayedInit(delay);
290 292
291 return true; 293 return true;
292 } 294 }
293 295
294 void RLZTracker::ScheduleDelayedInit(int delay) { 296 void RLZTracker::ScheduleDelayedInit(int delay) {
295 // The RLZTracker is a singleton object that outlives any runnable tasks 297 // The RLZTracker is a singleton object that outlives any runnable tasks
296 // that will be queued up. 298 // that will be queued up.
297 BrowserThread::GetBlockingPool()->PostDelayedTask( 299 BrowserThread::GetBlockingPool()->PostDelayedSequencedWorkerTask(
300 worker_pool_token_,
298 FROM_HERE, 301 FROM_HERE,
299 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), 302 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)),
300 base::TimeDelta::FromMilliseconds(delay)); 303 base::TimeDelta::FromMilliseconds(delay));
301 } 304 }
302 305
303 void RLZTracker::DelayedInit() { 306 void RLZTracker::DelayedInit() {
304 worker_pool_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken();
305
306 bool schedule_ping = false; 307 bool schedule_ping = false;
307 308
308 // For organic brandcodes do not use rlz at all. Empty brandcode usually 309 // For organic brandcodes do not use rlz at all. Empty brandcode usually
309 // means a chromium install. This is ok. 310 // means a chromium install. This is ok.
310 if (!IsBrandOrganic(brand_)) { 311 if (!IsBrandOrganic(brand_)) {
311 RecordProductEvents(first_run_, is_google_default_search_, 312 RecordProductEvents(first_run_, is_google_default_search_,
312 is_google_homepage_, is_google_in_startpages_, 313 is_google_homepage_, is_google_in_startpages_,
313 already_ran_, omnibox_used_, homepage_used_); 314 already_ran_, omnibox_used_, homepage_used_);
314 schedule_ping = true; 315 schedule_ping = true;
315 } 316 }
316 317
317 // If chrome has been reactivated, record the events for this brand 318 // If chrome has been reactivated, record the events for this brand
318 // as well. 319 // as well.
319 if (!IsBrandOrganic(reactivation_brand_)) { 320 if (!IsBrandOrganic(reactivation_brand_)) {
320 rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str()); 321 rlz_lib::SupplementaryBranding branding(reactivation_brand_.c_str());
321 RecordProductEvents(first_run_, is_google_default_search_, 322 RecordProductEvents(first_run_, is_google_default_search_,
322 is_google_homepage_, is_google_in_startpages_, 323 is_google_homepage_, is_google_in_startpages_,
323 already_ran_, omnibox_used_, homepage_used_); 324 already_ran_, omnibox_used_, homepage_used_);
324 schedule_ping = true; 325 schedule_ping = true;
325 } 326 }
326 327
327 already_ran_ = true; 328 already_ran_ = true;
328 329
329 if (schedule_ping) 330 if (schedule_ping)
330 ScheduleFinancialPing(); 331 ScheduleFinancialPing();
331 } 332 }
332 333
334 void RLZTracker::EnableZeroDelayForTesting() {
335 GetInstance()->min_delay_ = 0;
336 }
337
333 void RLZTracker::ScheduleFinancialPing() { 338 void RLZTracker::ScheduleFinancialPing() {
334 BrowserThread::GetBlockingPool()->PostSequencedWorkerTask( 339 BrowserThread::GetBlockingPool()->PostSequencedWorkerTask(
335 worker_pool_token_, 340 worker_pool_token_,
336 FROM_HERE, 341 FROM_HERE,
337 base::Bind(&RLZTracker::PingNowImpl, base::Unretained(this))); 342 base::Bind(&RLZTracker::PingNowImpl, base::Unretained(this)));
338 } 343 }
339 344
340 void RLZTracker::PingNowImpl() { 345 void RLZTracker::PingNowImpl() {
341 TRACE_EVENT0("RLZ", "RLZTracker::PingNowImpl"); 346 TRACE_EVENT0("RLZ", "RLZTracker::PingNowImpl");
342 string16 lang; 347 string16 lang;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 } 430 }
426 431
427 return ret; 432 return ret;
428 } 433 }
429 434
430 bool RLZTracker::ScheduleRecordProductEvent(rlz_lib::Product product, 435 bool RLZTracker::ScheduleRecordProductEvent(rlz_lib::Product product,
431 rlz_lib::AccessPoint point, 436 rlz_lib::AccessPoint point,
432 rlz_lib::Event event_id) { 437 rlz_lib::Event event_id) {
433 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) 438 if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
434 return false; 439 return false;
435 if (!already_ran_) {
436 LOG(ERROR) << "Attempted recording RLZ event before RLZ init.";
437 return true;
438 }
439 440
440 BrowserThread::GetBlockingPool()->PostSequencedWorkerTask( 441 BrowserThread::GetBlockingPool()->PostSequencedWorkerTask(
441 worker_pool_token_, 442 worker_pool_token_,
442 FROM_HERE, 443 FROM_HERE,
443 base::Bind(base::IgnoreResult(&RLZTracker::RecordProductEvent), 444 base::Bind(base::IgnoreResult(&RLZTracker::RecordProductEvent),
444 product, point, event_id)); 445 product, point, event_id));
445 446
446 return true; 447 return true;
447 } 448 }
448 449
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 base::Bind(base::IgnoreResult(&RLZTracker::GetAccessPointRlz), point, 542 base::Bind(base::IgnoreResult(&RLZTracker::GetAccessPointRlz), point,
542 not_used)); 543 not_used));
543 return true; 544 return true;
544 } 545 }
545 546
546 // static 547 // static
547 void RLZTracker::CleanupRlz() { 548 void RLZTracker::CleanupRlz() {
548 GetInstance()->rlz_cache_.clear(); 549 GetInstance()->rlz_cache_.clear();
549 GetInstance()->registrar_.RemoveAll(); 550 GetInstance()->registrar_.RemoveAll();
550 } 551 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698