Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 22 matching lines...) Expand all Loading... | |
| 33 #include "chrome/common/env_vars.h" | 33 #include "chrome/common/env_vars.h" |
| 34 #include "chrome/installer/util/google_update_settings.h" | 34 #include "chrome/installer/util/google_update_settings.h" |
| 35 #include "content/browser/tab_contents/navigation_entry.h" | 35 #include "content/browser/tab_contents/navigation_entry.h" |
| 36 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 37 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 38 | 38 |
| 39 using content::BrowserThread; | 39 using content::BrowserThread; |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 bool IsBrandOrganic(const std::string& brand) { | |
| 44 return brand.empty() || google_util::IsOrganic(brand); | |
|
Glenn Wilson
2011/12/02 21:35:02
It's been a while, this is is pass-by-value, right
Roger Tawa OOO till Jul 10th
2011/12/02 22:00:20
Right, no need to check for null.
| |
| 45 } | |
| 46 | |
| 43 void RecordProductEvents(bool first_run, bool google_default_search, | 47 void RecordProductEvents(bool first_run, bool google_default_search, |
| 44 bool google_default_homepage, bool already_ran, | 48 bool google_default_homepage, bool already_ran, |
| 45 bool omnibox_used, bool homepage_used) { | 49 bool omnibox_used, bool homepage_used) { |
| 46 // Record the installation of chrome. We call this all the time but the rlz | 50 // Record the installation of chrome. We call this all the time but the rlz |
| 47 // lib should ingore all but the first one. | 51 // lib should ingore all but the first one. |
| 48 rlz_lib::RecordProductEvent(rlz_lib::CHROME, | 52 rlz_lib::RecordProductEvent(rlz_lib::CHROME, |
| 49 rlz_lib::CHROME_OMNIBOX, | 53 rlz_lib::CHROME_OMNIBOX, |
| 50 rlz_lib::INSTALL); | 54 rlz_lib::INSTALL); |
| 51 rlz_lib::RecordProductEvent(rlz_lib::CHROME, | 55 rlz_lib::RecordProductEvent(rlz_lib::CHROME, |
| 52 rlz_lib::CHROME_HOME_PAGE, | 56 rlz_lib::CHROME_HOME_PAGE, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 } | 103 } |
| 100 | 104 |
| 101 bool SendFinancialPing(const std::string& brand, | 105 bool SendFinancialPing(const std::string& brand, |
| 102 const string16& lang, | 106 const string16& lang, |
| 103 const string16& referral) { | 107 const string16& referral) { |
| 104 rlz_lib::AccessPoint points[] = {rlz_lib::CHROME_OMNIBOX, | 108 rlz_lib::AccessPoint points[] = {rlz_lib::CHROME_OMNIBOX, |
| 105 rlz_lib::CHROME_HOME_PAGE, | 109 rlz_lib::CHROME_HOME_PAGE, |
| 106 rlz_lib::NO_ACCESS_POINT}; | 110 rlz_lib::NO_ACCESS_POINT}; |
| 107 std::string lang_ascii(WideToASCII(lang)); | 111 std::string lang_ascii(WideToASCII(lang)); |
| 108 std::string referral_ascii(WideToASCII(referral)); | 112 std::string referral_ascii(WideToASCII(referral)); |
| 109 | |
| 110 // If chrome has been reactivated, send a ping for this brand as well. | |
| 111 // We ignore the return value of SendFinancialPing() since we'll try again | |
| 112 // later anyway. Callers of this function are only interested in whether | |
| 113 // the ping for the main brand succeeded or not. | |
| 114 std::string reactivation_brand; | |
| 115 if (google_util::GetReactivationBrand(&reactivation_brand)) { | |
| 116 string16 reactivation_brand16 = UTF8ToUTF16(reactivation_brand); | |
| 117 rlz_lib::SupplementaryBranding branding(reactivation_brand16.c_str()); | |
| 118 rlz_lib::SendFinancialPing(rlz_lib::CHROME, points, "chrome", | |
| 119 reactivation_brand.c_str(), | |
| 120 referral_ascii.c_str(), lang_ascii.c_str(), | |
| 121 false, NULL, true); | |
| 122 } | |
| 123 | |
| 124 return rlz_lib::SendFinancialPing(rlz_lib::CHROME, points, "chrome", | 113 return rlz_lib::SendFinancialPing(rlz_lib::CHROME, points, "chrome", |
| 125 brand.c_str(), referral_ascii.c_str(), | 114 brand.c_str(), referral_ascii.c_str(), |
| 126 lang_ascii.c_str(), false, NULL, true); | 115 lang_ascii.c_str(), false, NULL, true); |
| 127 } | 116 } |
| 128 | 117 |
| 129 } // namespace | 118 } // namespace |
| 130 | 119 |
| 131 RLZTracker* RLZTracker::tracker_ = NULL; | 120 RLZTracker* RLZTracker::tracker_ = NULL; |
| 132 | 121 |
| 133 // static | 122 // static |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 // The RLZTracker is a singleton object that outlives any runnable tasks | 191 // The RLZTracker is a singleton object that outlives any runnable tasks |
| 203 // that will be queued up. | 192 // that will be queued up. |
| 204 BrowserThread::PostDelayedTask( | 193 BrowserThread::PostDelayedTask( |
| 205 BrowserThread::FILE, | 194 BrowserThread::FILE, |
| 206 FROM_HERE, | 195 FROM_HERE, |
| 207 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), | 196 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), |
| 208 delay); | 197 delay); |
| 209 } | 198 } |
| 210 | 199 |
| 211 void RLZTracker::DelayedInit() { | 200 void RLZTracker::DelayedInit() { |
| 201 bool schedule_ping = false; | |
| 202 | |
| 212 // For organic brandcodes do not use rlz at all. Empty brandcode usually | 203 // For organic brandcodes do not use rlz at all. Empty brandcode usually |
| 213 // means a chromium install. This is ok. | 204 // means a chromium install. This is ok. |
| 214 std::string brand; | 205 std::string brand; |
| 215 if (!google_util::GetBrand(&brand) || brand.empty() || | 206 if (google_util::GetBrand(&brand) && !IsBrandOrganic(brand)) { |
| 216 google_util::IsOrganic(brand)) | 207 RecordProductEvents(first_run_, google_default_search_, |
| 217 return; | 208 google_default_homepage_, already_ran_, |
| 218 | 209 omnibox_used_, homepage_used_); |
| 219 RecordProductEvents(first_run_, google_default_search_, | 210 schedule_ping = true; |
| 220 google_default_homepage_, already_ran_, | 211 } |
| 221 omnibox_used_, homepage_used_); | |
| 222 | 212 |
| 223 // If chrome has been reactivated, record the events for this brand | 213 // If chrome has been reactivated, record the events for this brand |
| 224 // as well. | 214 // as well. |
| 225 std::string reactivation_brand; | 215 std::string reactivation_brand; |
| 226 if (google_util::GetReactivationBrand(&reactivation_brand)) { | 216 if (google_util::GetReactivationBrand(&reactivation_brand) && |
| 217 !IsBrandOrganic(reactivation_brand)) { | |
| 227 string16 reactivation_brand16 = UTF8ToUTF16(reactivation_brand); | 218 string16 reactivation_brand16 = UTF8ToUTF16(reactivation_brand); |
| 228 rlz_lib::SupplementaryBranding branding(reactivation_brand16.c_str()); | 219 rlz_lib::SupplementaryBranding branding(reactivation_brand16.c_str()); |
| 229 RecordProductEvents(first_run_, google_default_search_, | 220 RecordProductEvents(first_run_, google_default_search_, |
| 230 google_default_homepage_, already_ran_, | 221 google_default_homepage_, already_ran_, |
| 231 omnibox_used_, homepage_used_); | 222 omnibox_used_, homepage_used_); |
| 223 schedule_ping = true; | |
| 232 } | 224 } |
| 233 | 225 |
| 234 already_ran_ = true; | 226 already_ran_ = true; |
| 235 | 227 |
| 236 ScheduleFinancialPing(); | 228 if (schedule_ping) |
| 229 ScheduleFinancialPing(); | |
| 237 } | 230 } |
| 238 | 231 |
| 239 void RLZTracker::ScheduleFinancialPing() { | 232 void RLZTracker::ScheduleFinancialPing() { |
| 233 // Investigate why _beginthread() is used here, and not chrome's threading | |
| 234 // API. Tracked in bug http://crbug.com/106213 | |
| 240 _beginthread(PingNow, 0, this); | 235 _beginthread(PingNow, 0, this); |
| 241 } | 236 } |
| 242 | 237 |
| 243 // static | 238 // static |
| 244 void _cdecl RLZTracker::PingNow(void* arg) { | 239 void _cdecl RLZTracker::PingNow(void* arg) { |
| 245 RLZTracker* tracker = reinterpret_cast<RLZTracker*>(arg); | 240 RLZTracker* tracker = reinterpret_cast<RLZTracker*>(arg); |
| 246 tracker->PingNowImpl(); | 241 tracker->PingNowImpl(); |
| 247 } | 242 } |
| 248 | 243 |
| 249 void RLZTracker::PingNowImpl() { | 244 void RLZTracker::PingNowImpl() { |
| 250 // This is the entry point of a background thread, so I/O is allowed. | 245 // This is the entry point of a background thread, so I/O is allowed. |
| 251 base::ThreadRestrictions::ScopedAllowIO allow_io; | 246 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 252 | 247 |
| 253 string16 lang; | 248 string16 lang; |
| 254 GoogleUpdateSettings::GetLanguage(&lang); | 249 GoogleUpdateSettings::GetLanguage(&lang); |
| 255 if (lang.empty()) | 250 if (lang.empty()) |
| 256 lang = L"en"; | 251 lang = L"en"; |
| 257 std::string brand; | |
| 258 google_util::GetBrand(&brand); | |
| 259 string16 referral; | 252 string16 referral; |
| 260 GoogleUpdateSettings::GetReferral(&referral); | 253 GoogleUpdateSettings::GetReferral(&referral); |
| 261 if (SendFinancialPing(brand, lang, referral)) { | 254 |
| 255 std::string brand; | |
| 256 if (google_util::GetBrand(&brand) && !IsBrandOrganic(brand) && | |
| 257 SendFinancialPing(brand, lang, referral)) { | |
| 262 GoogleUpdateSettings::ClearReferral(); | 258 GoogleUpdateSettings::ClearReferral(); |
| 263 | 259 |
| 264 { | 260 { |
| 265 base::AutoLock lock(cache_lock_); | 261 base::AutoLock lock(cache_lock_); |
| 266 rlz_cache_.clear(); | 262 rlz_cache_.clear(); |
| 267 } | 263 } |
| 268 | 264 |
| 269 // Prime the RLZ cache for the access points we are interested in. | 265 // Prime the RLZ cache for the access points we are interested in. |
| 270 GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, NULL); | 266 GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, NULL); |
| 271 GetAccessPointRlz(rlz_lib::CHROME_HOME_PAGE, NULL); | 267 GetAccessPointRlz(rlz_lib::CHROME_HOME_PAGE, NULL); |
| 272 } | 268 } |
| 269 | |
| 270 std::string reactivation_brand; | |
| 271 if (google_util::GetReactivationBrand(&reactivation_brand) && | |
| 272 !IsBrandOrganic(reactivation_brand)) { | |
| 273 string16 reactivation_brand16 = UTF8ToUTF16(reactivation_brand); | |
| 274 rlz_lib::SupplementaryBranding branding(reactivation_brand16.c_str()); | |
| 275 SendFinancialPing(reactivation_brand, lang, referral); | |
| 276 } | |
| 273 } | 277 } |
| 274 | 278 |
| 275 bool RLZTracker::SendFinancialPing(const std::string& brand, | 279 bool RLZTracker::SendFinancialPing(const std::string& brand, |
| 276 const string16& lang, | 280 const string16& lang, |
| 277 const string16& referral) { | 281 const string16& referral) { |
| 278 return ::SendFinancialPing(brand, lang, referral); | 282 return ::SendFinancialPing(brand, lang, referral); |
| 279 } | 283 } |
| 280 | 284 |
| 281 void RLZTracker::Observe(int type, | 285 void RLZTracker::Observe(int type, |
| 282 const content::NotificationSource& source, | 286 const content::NotificationSource& source, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 base::IgnoreReturn<bool>( | 401 base::IgnoreReturn<bool>( |
| 398 base::Bind(&RLZTracker::GetAccessPointRlz, point, not_used))); | 402 base::Bind(&RLZTracker::GetAccessPointRlz, point, not_used))); |
| 399 return true; | 403 return true; |
| 400 } | 404 } |
| 401 | 405 |
| 402 // static | 406 // static |
| 403 void RLZTracker::CleanupRlz() { | 407 void RLZTracker::CleanupRlz() { |
| 404 GetInstance()->rlz_cache_.clear(); | 408 GetInstance()->rlz_cache_.clear(); |
| 405 GetInstance()->registrar_.RemoveAll(); | 409 GetInstance()->registrar_.RemoveAll(); |
| 406 } | 410 } |
| OLD | NEW |