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 "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/bind_helpers.h" | |
15 #include "base/file_path.h" | |
16 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
17 #include "base/path_service.h" | |
18 #include "base/string_util.h" | 15 #include "base/string_util.h" |
19 #include "base/synchronization/lock.h" | |
20 #include "base/threading/thread.h" | |
21 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
22 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
23 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/google/google_util.h" | 19 #include "chrome/browser/google/google_util.h" |
25 #include "chrome/browser/search_engines/template_url.h" | 20 #include "chrome/browser/search_engines/template_url.h" |
26 #include "chrome/browser/search_engines/template_url_service.h" | 21 #include "chrome/browser/search_engines/template_url_service.h" |
27 #include "chrome/browser/search_engines/template_url_service_factory.h" | 22 #include "chrome/browser/search_engines/template_url_service_factory.h" |
28 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/chrome_paths.h" | |
30 #include "chrome/common/env_vars.h" | |
31 #include "chrome/installer/util/google_update_settings.h" | |
32 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
34 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
35 | 27 |
28 #if defined(OS_WIN) | |
29 #include "chrome/installer/util/google_update_settings.h" | |
30 #else | |
31 namespace GoogleUpdateSettings { | |
32 static bool GetLanguage(string16* language) { | |
33 // TODO(thakis): Implement. | |
34 NOTIMPLEMENTED(); | |
35 return false; | |
36 } | |
37 | |
38 // The referral program is defunct and not used. No need to implement these | |
39 // functions on mac. | |
40 static bool GetReferral(string16* referral) { | |
41 return true; | |
42 } | |
43 static bool ClearReferral() { | |
44 return true; | |
45 } | |
46 } // namespace GoogleUpdateSettings | |
47 #endif | |
48 | |
36 using content::BrowserThread; | 49 using content::BrowserThread; |
37 using content::NavigationEntry; | 50 using content::NavigationEntry; |
38 | 51 |
39 namespace { | 52 namespace { |
40 | 53 |
41 bool IsBrandOrganic(const std::string& brand) { | 54 bool IsBrandOrganic(const std::string& brand) { |
42 return brand.empty() || google_util::IsOrganic(brand); | 55 return brand.empty() || google_util::IsOrganic(brand); |
43 } | 56 } |
44 | 57 |
45 void RecordProductEvents(bool first_run, bool google_default_search, | 58 void RecordProductEvents(bool first_run, bool google_default_search, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 content::NotificationService::AllSources()); | 194 content::NotificationService::AllSources()); |
182 | 195 |
183 ScheduleDelayedInit(delay); | 196 ScheduleDelayedInit(delay); |
184 | 197 |
185 return true; | 198 return true; |
186 } | 199 } |
187 | 200 |
188 void RLZTracker::ScheduleDelayedInit(int delay) { | 201 void RLZTracker::ScheduleDelayedInit(int delay) { |
189 // The RLZTracker is a singleton object that outlives any runnable tasks | 202 // The RLZTracker is a singleton object that outlives any runnable tasks |
190 // that will be queued up. | 203 // that will be queued up. |
204 // TODO: Move to SequencedWorkerPool once http://crbug.com/119657 is fixed. | |
191 BrowserThread::PostDelayedTask( | 205 BrowserThread::PostDelayedTask( |
192 BrowserThread::FILE, | 206 BrowserThread::FILE, |
193 FROM_HERE, | 207 FROM_HERE, |
194 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), | 208 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), |
195 delay); | 209 delay); |
196 } | 210 } |
197 | 211 |
198 void RLZTracker::DelayedInit() { | 212 void RLZTracker::DelayedInit() { |
213 worker_pool_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken(); | |
214 | |
199 bool schedule_ping = false; | 215 bool schedule_ping = false; |
200 | 216 |
217 rlz_lib::SetURLRequestContext(g_browser_process->system_request_context()); | |
willchan no longer on Chromium
2012/03/27 12:14:53
This is a race. This runs on the FILE thread. g_br
Nico
2012/03/28 19:47:37
https://chromiumcodereview.appspot.com/9877017/
| |
218 | |
201 // For organic brandcodes do not use rlz at all. Empty brandcode usually | 219 // For organic brandcodes do not use rlz at all. Empty brandcode usually |
202 // means a chromium install. This is ok. | 220 // means a chromium install. This is ok. |
203 std::string brand; | 221 std::string brand; |
204 if (google_util::GetBrand(&brand) && !IsBrandOrganic(brand)) { | 222 if (google_util::GetBrand(&brand) && !IsBrandOrganic(brand)) { |
205 RecordProductEvents(first_run_, google_default_search_, | 223 RecordProductEvents(first_run_, google_default_search_, |
206 google_default_homepage_, already_ran_, | 224 google_default_homepage_, already_ran_, |
207 omnibox_used_, homepage_used_); | 225 omnibox_used_, homepage_used_); |
208 schedule_ping = true; | 226 schedule_ping = true; |
209 } | 227 } |
210 | 228 |
211 // If chrome has been reactivated, record the events for this brand | 229 // If chrome has been reactivated, record the events for this brand |
212 // as well. | 230 // as well. |
213 std::string reactivation_brand; | 231 std::string reactivation_brand; |
214 if (google_util::GetReactivationBrand(&reactivation_brand) && | 232 if (google_util::GetReactivationBrand(&reactivation_brand) && |
215 !IsBrandOrganic(reactivation_brand)) { | 233 !IsBrandOrganic(reactivation_brand)) { |
216 rlz_lib::SupplementaryBranding branding(reactivation_brand.c_str()); | 234 rlz_lib::SupplementaryBranding branding(reactivation_brand.c_str()); |
217 RecordProductEvents(first_run_, google_default_search_, | 235 RecordProductEvents(first_run_, google_default_search_, |
218 google_default_homepage_, already_ran_, | 236 google_default_homepage_, already_ran_, |
219 omnibox_used_, homepage_used_); | 237 omnibox_used_, homepage_used_); |
220 schedule_ping = true; | 238 schedule_ping = true; |
221 } | 239 } |
222 | 240 |
223 already_ran_ = true; | 241 already_ran_ = true; |
224 | 242 |
225 if (schedule_ping) | 243 if (schedule_ping) |
226 ScheduleFinancialPing(); | 244 ScheduleFinancialPing(); |
227 } | 245 } |
228 | 246 |
229 void RLZTracker::ScheduleFinancialPing() { | 247 void RLZTracker::ScheduleFinancialPing() { |
230 // TODO(thakis): Once akalin's TaskRunner around PostTask() is done, | 248 BrowserThread::GetBlockingPool()->PostSequencedWorkerTask( |
231 // use that instead of the file thread. | 249 worker_pool_token_, |
232 BrowserThread::PostTask( | |
233 BrowserThread::FILE, | |
234 FROM_HERE, | 250 FROM_HERE, |
235 base::Bind(&RLZTracker::PingNowImpl, base::Unretained(this))); | 251 base::Bind(&RLZTracker::PingNowImpl, base::Unretained(this))); |
236 } | 252 } |
237 | 253 |
238 void RLZTracker::PingNowImpl() { | 254 void RLZTracker::PingNowImpl() { |
239 string16 lang; | 255 string16 lang; |
240 GoogleUpdateSettings::GetLanguage(&lang); | 256 GoogleUpdateSettings::GetLanguage(&lang); |
241 if (lang.empty()) | 257 if (lang.empty()) |
242 lang = ASCIIToUTF16("en"); | 258 lang = ASCIIToUTF16("en"); |
243 string16 referral; | 259 string16 referral; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 base::AutoLock lock(cache_lock_); | 394 base::AutoLock lock(cache_lock_); |
379 rlz_cache_[point] = rlz_local; | 395 rlz_cache_[point] = rlz_local; |
380 return true; | 396 return true; |
381 } | 397 } |
382 | 398 |
383 bool RLZTracker::ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) { | 399 bool RLZTracker::ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) { |
384 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) | 400 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) |
385 return false; | 401 return false; |
386 | 402 |
387 string16* not_used = NULL; | 403 string16* not_used = NULL; |
388 BrowserThread::PostTask( | 404 BrowserThread::GetBlockingPool()->PostSequencedWorkerTask( |
389 BrowserThread::FILE, FROM_HERE, | 405 worker_pool_token_, |
406 FROM_HERE, | |
390 base::Bind(base::IgnoreResult(&RLZTracker::GetAccessPointRlz), point, | 407 base::Bind(base::IgnoreResult(&RLZTracker::GetAccessPointRlz), point, |
391 not_used)); | 408 not_used)); |
392 return true; | 409 return true; |
393 } | 410 } |
394 | 411 |
395 // static | 412 // static |
396 void RLZTracker::CleanupRlz() { | 413 void RLZTracker::CleanupRlz() { |
397 GetInstance()->rlz_cache_.clear(); | 414 GetInstance()->rlz_cache_.clear(); |
398 GetInstance()->registrar_.RemoveAll(); | 415 GetInstance()->registrar_.RemoveAll(); |
399 } | 416 } |
OLD | NEW |