| 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/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/threading/sequenced_worker_pool.h" |
| 17 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/google/google_util.h" | 20 #include "chrome/browser/google/google_util.h" |
| 20 #include "chrome/browser/search_engines/template_url.h" | 21 #include "chrome/browser/search_engines/template_url.h" |
| 21 #include "chrome/browser/search_engines/template_url_service.h" | 22 #include "chrome/browser/search_engines/template_url_service.h" |
| 22 #include "chrome/browser/search_engines/template_url_service_factory.h" | 23 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 23 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/navigation_entry.h" | 26 #include "content/public/browser/navigation_entry.h" |
| 26 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 27 #include "net/http/http_util.h" | 28 #include "net/http/http_util.h" |
| 28 | 29 |
| 29 #if defined(OS_CHROMEOS) | |
| 30 #include "base/threading/sequenced_worker_pool.h" | |
| 31 #endif | |
| 32 | |
| 33 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 34 #include "chrome/installer/util/google_update_settings.h" | 31 #include "chrome/installer/util/google_update_settings.h" |
| 35 #else | 32 #else |
| 36 namespace GoogleUpdateSettings { | 33 namespace GoogleUpdateSettings { |
| 37 static bool GetLanguage(string16* language) { | 34 static bool GetLanguage(string16* language) { |
| 38 // TODO(thakis): Implement. | 35 // TODO(thakis): Implement. |
| 39 NOTIMPLEMENTED(); | 36 NOTIMPLEMENTED(); |
| 40 return false; | 37 return false; |
| 41 } | 38 } |
| 42 | 39 |
| 43 // The referral program is defunct and not used. No need to implement these | 40 // The referral program is defunct and not used. No need to implement these |
| 44 // functions on non-Win platforms. | 41 // functions on non-Win platforms. |
| 45 static bool GetReferral(string16* referral) { | 42 static bool GetReferral(string16* referral) { |
| 46 return true; | 43 return true; |
| 47 } | 44 } |
| 48 static bool ClearReferral() { | 45 static bool ClearReferral() { |
| 49 return true; | 46 return true; |
| 50 } | 47 } |
| 51 } // namespace GoogleUpdateSettings | 48 } // namespace GoogleUpdateSettings |
| 52 #endif | 49 #endif |
| 53 | 50 |
| 54 using content::BrowserThread; | 51 using content::BrowserThread; |
| 55 using content::NavigationEntry; | 52 using content::NavigationEntry; |
| 56 | 53 |
| 57 namespace { | 54 namespace { |
| 58 | 55 |
| 59 const char kRlzThreadName[] = "RLZ_thread"; | |
| 60 | |
| 61 bool IsBrandOrganic(const std::string& brand) { | 56 bool IsBrandOrganic(const std::string& brand) { |
| 62 return brand.empty() || google_util::IsOrganic(brand); | 57 return brand.empty() || google_util::IsOrganic(brand); |
| 63 } | 58 } |
| 64 | 59 |
| 65 void RecordProductEvents(bool first_run, | 60 void RecordProductEvents(bool first_run, |
| 66 bool is_google_default_search, | 61 bool is_google_default_search, |
| 67 bool is_google_homepage, | 62 bool is_google_homepage, |
| 68 bool is_google_in_startpages, | 63 bool is_google_in_startpages, |
| 69 bool already_ran, | 64 bool already_ran, |
| 70 bool omnibox_used, | 65 bool omnibox_used, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 RLZTracker* RLZTracker::GetInstance() { | 165 RLZTracker* RLZTracker::GetInstance() { |
| 171 return tracker_ ? tracker_ : Singleton<RLZTracker>::get(); | 166 return tracker_ ? tracker_ : Singleton<RLZTracker>::get(); |
| 172 } | 167 } |
| 173 | 168 |
| 174 RLZTracker::RLZTracker() | 169 RLZTracker::RLZTracker() |
| 175 : first_run_(false), | 170 : first_run_(false), |
| 176 send_ping_immediately_(false), | 171 send_ping_immediately_(false), |
| 177 is_google_default_search_(false), | 172 is_google_default_search_(false), |
| 178 is_google_homepage_(false), | 173 is_google_homepage_(false), |
| 179 is_google_in_startpages_(false), | 174 is_google_in_startpages_(false), |
| 180 rlz_thread_(kRlzThreadName), | |
| 181 blocking_task_runner_(NULL), | 175 blocking_task_runner_(NULL), |
| 182 url_request_context_(NULL), | 176 url_request_context_(NULL), |
| 183 already_ran_(false), | 177 already_ran_(false), |
| 184 omnibox_used_(false), | 178 omnibox_used_(false), |
| 185 homepage_used_(false) { | 179 homepage_used_(false) { |
| 186 } | 180 } |
| 187 | 181 |
| 188 RLZTracker::~RLZTracker() { | 182 RLZTracker::~RLZTracker() { |
| 189 } | 183 } |
| 190 | 184 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 void RLZTracker::ScheduleDelayedInit(int delay) { | 249 void RLZTracker::ScheduleDelayedInit(int delay) { |
| 256 // The RLZTracker is a singleton object that outlives any runnable tasks | 250 // The RLZTracker is a singleton object that outlives any runnable tasks |
| 257 // that will be queued up. | 251 // that will be queued up. |
| 258 blocking_task_runner_->PostDelayedTask( | 252 blocking_task_runner_->PostDelayedTask( |
| 259 FROM_HERE, | 253 FROM_HERE, |
| 260 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), | 254 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), |
| 261 base::TimeDelta::FromMilliseconds(delay)); | 255 base::TimeDelta::FromMilliseconds(delay)); |
| 262 } | 256 } |
| 263 | 257 |
| 264 bool RLZTracker::InitWorkers() { | 258 bool RLZTracker::InitWorkers() { |
| 265 base::Thread::Options options; | |
| 266 options.message_loop_type = MessageLoop::TYPE_IO; | |
| 267 if (!rlz_thread_.StartWithOptions(options)) | |
| 268 return false; | |
| 269 blocking_task_runner_ = rlz_thread_.message_loop_proxy(); | |
| 270 | |
| 271 #if defined(OS_CHROMEOS) | |
| 272 base::SequencedWorkerPool* worker_pool = | 259 base::SequencedWorkerPool* worker_pool = |
| 273 content::BrowserThread::GetBlockingPool(); | 260 content::BrowserThread::GetBlockingPool(); |
| 274 if (!worker_pool) | 261 if (!worker_pool) |
| 275 return false; | 262 return false; |
| 276 rlz_lib::SetIOTaskRunner( | 263 blocking_task_runner_ = |
| 277 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( | 264 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 278 worker_pool->GetSequenceToken(), | 265 worker_pool->GetSequenceToken(), |
| 279 base::SequencedWorkerPool::BLOCK_SHUTDOWN)); | 266 base::SequencedWorkerPool::BLOCK_SHUTDOWN); |
| 280 #endif | |
| 281 return true; | 267 return true; |
| 282 } | 268 } |
| 283 | 269 |
| 284 void RLZTracker::DelayedInit() { | 270 void RLZTracker::DelayedInit() { |
| 285 if (!already_ran_) | 271 if (!already_ran_) |
| 286 rlz_lib::SetURLRequestContext(url_request_context_); | 272 rlz_lib::SetURLRequestContext(url_request_context_); |
| 287 | 273 |
| 288 bool schedule_ping = false; | 274 bool schedule_ping = false; |
| 289 | 275 |
| 290 // For organic brandcodes do not use rlz at all. Empty brandcode usually | 276 // For organic brandcodes do not use rlz at all. Empty brandcode usually |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 base::Bind(base::IgnoreResult(&RLZTracker::GetAccessPointRlz), point, | 513 base::Bind(base::IgnoreResult(&RLZTracker::GetAccessPointRlz), point, |
| 528 not_used)); | 514 not_used)); |
| 529 return true; | 515 return true; |
| 530 } | 516 } |
| 531 | 517 |
| 532 // static | 518 // static |
| 533 void RLZTracker::CleanupRlz() { | 519 void RLZTracker::CleanupRlz() { |
| 534 GetInstance()->rlz_cache_.clear(); | 520 GetInstance()->rlz_cache_.clear(); |
| 535 GetInstance()->registrar_.RemoveAll(); | 521 GetInstance()->registrar_.RemoveAll(); |
| 536 } | 522 } |
| OLD | NEW |