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 |
11 #include <windows.h> | 11 #include <windows.h> |
12 #include <process.h> | 12 #include <process.h> |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 | 15 |
| 16 #include "base/bind.h" |
| 17 #include "base/bind_helpers.h" |
16 #include "base/file_path.h" | 18 #include "base/file_path.h" |
17 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
18 #include "base/path_service.h" | 20 #include "base/path_service.h" |
19 #include "base/string_util.h" | 21 #include "base/string_util.h" |
20 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
21 #include "base/task.h" | |
22 #include "base/threading/thread.h" | 23 #include "base/threading/thread.h" |
23 #include "base/threading/thread_restrictions.h" | 24 #include "base/threading/thread_restrictions.h" |
24 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
25 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
26 #include "chrome/browser/google/google_util.h" | 27 #include "chrome/browser/google/google_util.h" |
27 #include "chrome/browser/search_engines/template_url.h" | 28 #include "chrome/browser/search_engines/template_url.h" |
28 #include "chrome/browser/search_engines/template_url_service.h" | 29 #include "chrome/browser/search_engines/template_url_service.h" |
29 #include "chrome/browser/search_engines/template_url_service_factory.h" | 30 #include "chrome/browser/search_engines/template_url_service_factory.h" |
30 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
31 #include "chrome/common/chrome_paths.h" | 32 #include "chrome/common/chrome_paths.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // the home page. | 192 // the home page. |
192 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 193 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
193 content::NotificationService::AllSources()); | 194 content::NotificationService::AllSources()); |
194 | 195 |
195 ScheduleDelayedInit(delay); | 196 ScheduleDelayedInit(delay); |
196 | 197 |
197 return true; | 198 return true; |
198 } | 199 } |
199 | 200 |
200 void RLZTracker::ScheduleDelayedInit(int delay) { | 201 void RLZTracker::ScheduleDelayedInit(int delay) { |
| 202 // The RLZTracker is a singleton object that outlives any runnable tasks |
| 203 // that will be queued up. |
201 BrowserThread::PostDelayedTask( | 204 BrowserThread::PostDelayedTask( |
202 BrowserThread::FILE, | 205 BrowserThread::FILE, |
203 FROM_HERE, | 206 FROM_HERE, |
204 NewRunnableMethod(this, &RLZTracker::DelayedInit), | 207 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), |
205 delay); | 208 delay); |
206 } | 209 } |
207 | 210 |
208 void RLZTracker::DelayedInit() { | 211 void RLZTracker::DelayedInit() { |
209 // For organic brandcodes do not use rlz at all. Empty brandcode usually | 212 // For organic brandcodes do not use rlz at all. Empty brandcode usually |
210 // means a chromium install. This is ok. | 213 // means a chromium install. This is ok. |
211 std::string brand; | 214 std::string brand; |
212 if (!google_util::GetBrand(&brand) || brand.empty() || | 215 if (!google_util::GetBrand(&brand) || brand.empty() || |
213 google_util::IsOrganic(brand)) | 216 google_util::IsOrganic(brand)) |
214 return; | 217 return; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 return true; | 387 return true; |
385 } | 388 } |
386 | 389 |
387 bool RLZTracker::ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) { | 390 bool RLZTracker::ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) { |
388 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) | 391 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) |
389 return false; | 392 return false; |
390 | 393 |
391 string16* not_used = NULL; | 394 string16* not_used = NULL; |
392 BrowserThread::PostTask( | 395 BrowserThread::PostTask( |
393 BrowserThread::FILE, FROM_HERE, | 396 BrowserThread::FILE, FROM_HERE, |
394 NewRunnableFunction(&RLZTracker::GetAccessPointRlz, point, not_used)); | 397 base::IgnoreReturn<bool>( |
| 398 base::Bind(&RLZTracker::GetAccessPointRlz, point, not_used))); |
395 return true; | 399 return true; |
396 } | 400 } |
397 | 401 |
398 // static | 402 // static |
399 void RLZTracker::CleanupRlz() { | 403 void RLZTracker::CleanupRlz() { |
400 GetInstance()->rlz_cache_.clear(); | 404 GetInstance()->rlz_cache_.clear(); |
401 GetInstance()->registrar_.RemoveAll(); | 405 GetInstance()->registrar_.RemoveAll(); |
402 } | 406 } |
OLD | NEW |