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); |
| 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() { |
240 _beginthread(PingNow, 0, this); | 233 _beginthread(PingNow, 0, this); |
241 } | 234 } |
242 | 235 |
243 // static | 236 // static |
244 void _cdecl RLZTracker::PingNow(void* arg) { | 237 void _cdecl RLZTracker::PingNow(void* arg) { |
245 RLZTracker* tracker = reinterpret_cast<RLZTracker*>(arg); | 238 RLZTracker* tracker = reinterpret_cast<RLZTracker*>(arg); |
246 tracker->PingNowImpl(); | 239 tracker->PingNowImpl(); |
247 } | 240 } |
248 | 241 |
249 void RLZTracker::PingNowImpl() { | 242 void RLZTracker::PingNowImpl() { |
250 // This is the entry point of a background thread, so I/O is allowed. | 243 // This is the entry point of a background thread, so I/O is allowed. |
251 base::ThreadRestrictions::ScopedAllowIO allow_io; | 244 base::ThreadRestrictions::ScopedAllowIO allow_io; |
252 | 245 |
253 string16 lang; | 246 string16 lang; |
254 GoogleUpdateSettings::GetLanguage(&lang); | 247 GoogleUpdateSettings::GetLanguage(&lang); |
255 if (lang.empty()) | 248 if (lang.empty()) |
256 lang = L"en"; | 249 lang = L"en"; |
257 std::string brand; | |
258 google_util::GetBrand(&brand); | |
259 string16 referral; | 250 string16 referral; |
260 GoogleUpdateSettings::GetReferral(&referral); | 251 GoogleUpdateSettings::GetReferral(&referral); |
261 if (SendFinancialPing(brand, lang, referral)) { | 252 |
| 253 std::string brand; |
| 254 if (google_util::GetBrand(&brand) && !IsBrandOrganic(brand) && |
| 255 SendFinancialPing(brand, lang, referral)) { |
262 GoogleUpdateSettings::ClearReferral(); | 256 GoogleUpdateSettings::ClearReferral(); |
263 | 257 |
264 { | 258 { |
265 base::AutoLock lock(cache_lock_); | 259 base::AutoLock lock(cache_lock_); |
266 rlz_cache_.clear(); | 260 rlz_cache_.clear(); |
267 } | 261 } |
268 | 262 |
269 // Prime the RLZ cache for the access points we are interested in. | 263 // Prime the RLZ cache for the access points we are interested in. |
270 GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, NULL); | 264 GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, NULL); |
271 GetAccessPointRlz(rlz_lib::CHROME_HOME_PAGE, NULL); | 265 GetAccessPointRlz(rlz_lib::CHROME_HOME_PAGE, NULL); |
272 } | 266 } |
| 267 |
| 268 std::string reactivation_brand; |
| 269 if (google_util::GetReactivationBrand(&reactivation_brand) && |
| 270 !IsBrandOrganic(reactivation_brand)) { |
| 271 string16 reactivation_brand16 = UTF8ToUTF16(reactivation_brand); |
| 272 rlz_lib::SupplementaryBranding branding(reactivation_brand16.c_str()); |
| 273 SendFinancialPing(reactivation_brand, lang, referral); |
| 274 } |
273 } | 275 } |
274 | 276 |
275 bool RLZTracker::SendFinancialPing(const std::string& brand, | 277 bool RLZTracker::SendFinancialPing(const std::string& brand, |
276 const string16& lang, | 278 const string16& lang, |
277 const string16& referral) { | 279 const string16& referral) { |
278 return ::SendFinancialPing(brand, lang, referral); | 280 return ::SendFinancialPing(brand, lang, referral); |
279 } | 281 } |
280 | 282 |
281 void RLZTracker::Observe(int type, | 283 void RLZTracker::Observe(int type, |
282 const content::NotificationSource& source, | 284 const content::NotificationSource& source, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 base::IgnoreReturn<bool>( | 399 base::IgnoreReturn<bool>( |
398 base::Bind(&RLZTracker::GetAccessPointRlz, point, not_used))); | 400 base::Bind(&RLZTracker::GetAccessPointRlz, point, not_used))); |
399 return true; | 401 return true; |
400 } | 402 } |
401 | 403 |
402 // static | 404 // static |
403 void RLZTracker::CleanupRlz() { | 405 void RLZTracker::CleanupRlz() { |
404 GetInstance()->rlz_cache_.clear(); | 406 GetInstance()->rlz_cache_.clear(); |
405 GetInstance()->registrar_.RemoveAll(); | 407 GetInstance()->registrar_.RemoveAll(); |
406 } | 408 } |
OLD | NEW |