Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 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/file_path.h" | 16 #include "base/file_path.h" |
| 17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/task.h" | 20 #include "base/task.h" |
| 21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 22 #include "base/threading/thread_restrictions.h" | 22 #include "base/threading/thread_restrictions.h" |
| 23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/browser_thread.h" | |
| 25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 27 #include "chrome/browser/profiles/profile_manager.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_model.h" | 29 #include "chrome/browser/search_engines/template_url_model.h" |
| 29 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
| 30 #include "chrome/common/env_vars.h" | 31 #include "chrome/common/env_vars.h" |
| 31 #include "chrome/common/notification_registrar.h" | 32 #include "chrome/common/notification_registrar.h" |
| 32 #include "chrome/common/notification_service.h" | 33 #include "chrome/common/notification_service.h" |
| 33 #include "chrome/installer/util/google_update_settings.h" | 34 #include "chrome/installer/util/google_update_settings.h" |
| 34 | 35 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 // Performs late RLZ initialization and RLZ event recording for chrome. | 162 // Performs late RLZ initialization and RLZ event recording for chrome. |
| 162 // This task needs to run on the UI thread. | 163 // This task needs to run on the UI thread. |
| 163 class DelayedInitTask : public Task { | 164 class DelayedInitTask : public Task { |
| 164 public: | 165 public: |
| 165 explicit DelayedInitTask(bool first_run) | 166 explicit DelayedInitTask(bool first_run) |
| 166 : first_run_(first_run) { | 167 : first_run_(first_run) { |
| 167 } | 168 } |
| 168 virtual ~DelayedInitTask() { | 169 virtual ~DelayedInitTask() { |
| 169 } | 170 } |
| 170 virtual void Run() { | 171 virtual void Run() { |
| 171 // Needs to be evaluated. See http://crbug.com/62328. | |
| 172 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 173 | |
| 174 // For non-interactive tests we don't do the rest of the initialization | 172 // For non-interactive tests we don't do the rest of the initialization |
| 175 // because sometimes the very act of loading the dll causes QEMU to crash. | 173 // because sometimes the very act of loading the dll causes QEMU to crash. |
| 176 if (::GetEnvironmentVariableW(ASCIIToWide(env_vars::kHeadless).c_str(), | 174 if (::GetEnvironmentVariableW(ASCIIToWide(env_vars::kHeadless).c_str(), |
| 177 NULL, 0)) { | 175 NULL, 0)) { |
| 178 return; | 176 return; |
| 179 } | 177 } |
| 180 // For organic brandcodes do not use rlz at all. Empty brandcode usually | 178 // For organic brandcodes do not use rlz at all. Empty brandcode usually |
| 181 // means a chromium install. This is ok. | 179 // means a chromium install. This is ok. |
| 182 std::wstring brand; | 180 std::wstring brand; |
| 183 if (!GoogleUpdateSettings::GetBrand(&brand) || brand.empty() || | 181 if (!GoogleUpdateSettings::GetBrand(&brand) || brand.empty() || |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 205 } | 203 } |
| 206 } | 204 } |
| 207 // Record first user interaction with the omnibox. We call this all the | 205 // Record first user interaction with the omnibox. We call this all the |
| 208 // time but the rlz lib should ingore all but the first one. | 206 // time but the rlz lib should ingore all but the first one. |
| 209 if (OmniBoxUsageObserver::used()) { | 207 if (OmniBoxUsageObserver::used()) { |
| 210 RLZTracker::RecordProductEvent(rlz_lib::CHROME, | 208 RLZTracker::RecordProductEvent(rlz_lib::CHROME, |
| 211 rlz_lib::CHROME_OMNIBOX, | 209 rlz_lib::CHROME_OMNIBOX, |
| 212 rlz_lib::FIRST_SEARCH); | 210 rlz_lib::FIRST_SEARCH); |
| 213 } | 211 } |
| 214 // Schedule the daily RLZ ping. | 212 // Schedule the daily RLZ ping. |
| 215 base::Thread* thread = g_browser_process->file_thread(); | 213 MessageLoop::current()->PostTask(FROM_HERE, new DailyPingTask()); |
| 216 if (thread) | |
| 217 thread->message_loop()->PostTask(FROM_HERE, new DailyPingTask()); | |
| 218 } | 214 } |
| 219 | 215 |
| 220 private: | 216 private: |
| 221 bool IsGoogleDefaultSearch() { | 217 bool IsGoogleDefaultSearch() { |
| 222 if (!g_browser_process) | 218 if (!g_browser_process) |
| 223 return false; | 219 return false; |
| 224 FilePath user_data_dir; | 220 FilePath user_data_dir; |
| 225 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) | 221 if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) |
| 226 return false; | 222 return false; |
| 227 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 223 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 251 const int kMinDelay = 20 * 1000; | 247 const int kMinDelay = 20 * 1000; |
| 252 | 248 |
| 253 delay *= 1000; | 249 delay *= 1000; |
| 254 delay = (delay < kMinDelay) ? kMinDelay : delay; | 250 delay = (delay < kMinDelay) ? kMinDelay : delay; |
| 255 delay = (delay > kMaxDelay) ? kMaxDelay : delay; | 251 delay = (delay > kMaxDelay) ? kMaxDelay : delay; |
| 256 | 252 |
| 257 if (!OmniBoxUsageObserver::used()) | 253 if (!OmniBoxUsageObserver::used()) |
| 258 new OmniBoxUsageObserver(); | 254 new OmniBoxUsageObserver(); |
| 259 | 255 |
| 260 // Schedule the delayed init items. | 256 // Schedule the delayed init items. |
| 261 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 257 BrowserThread::PostDelayedTask( |
| 262 new DelayedInitTask(first_run), delay); | 258 BrowserThread::FILE, FROM_HERE, new DelayedInitTask(first_run), delay); |
| 263 return true; | 259 return true; |
| 264 } | 260 } |
| 265 | 261 |
| 266 bool RLZTracker::RecordProductEvent(rlz_lib::Product product, | 262 bool RLZTracker::RecordProductEvent(rlz_lib::Product product, |
| 267 rlz_lib::AccessPoint point, | 263 rlz_lib::AccessPoint point, |
| 268 rlz_lib::Event event_id) { | 264 rlz_lib::Event event_id) { |
| 269 return rlz_lib::RecordProductEvent(product, point, event_id); | 265 return rlz_lib::RecordProductEvent(product, point, event_id); |
| 270 } | 266 } |
| 271 | 267 |
| 272 bool RLZTracker::ClearAllProductEvents(rlz_lib::Product product) { | 268 bool RLZTracker::ClearAllProductEvents(rlz_lib::Product product) { |
| 273 return rlz_lib::ClearAllProductEvents(product); | 269 return rlz_lib::ClearAllProductEvents(product); |
| 274 } | 270 } |
| 275 | 271 |
| 276 // We implement caching of the answer of get_access_point() if the request | 272 // We implement caching of the answer of get_access_point() if the request |
| 277 // is for CHROME_OMNIBOX. If we had a successful ping, then we update the | 273 // is for CHROME_OMNIBOX. If we had a successful ping, then we update the |
| 278 // cached value. | 274 // cached value. |
| 279 | 275 |
| 280 bool RLZTracker::GetAccessPointRlz(rlz_lib::AccessPoint point, | 276 bool RLZTracker::GetAccessPointRlz(rlz_lib::AccessPoint point, |
| 281 std::wstring* rlz) { | 277 std::wstring* rlz) { |
| 282 static std::wstring cached_ommibox_rlz; | 278 static std::wstring cached_ommibox_rlz; |
| 283 if ((rlz_lib::CHROME_OMNIBOX == point) && | 279 if ((rlz_lib::CHROME_OMNIBOX == point) && |
| 284 (access_values_state == ACCESS_VALUES_FRESH)) { | 280 (access_values_state == ACCESS_VALUES_FRESH)) { |
| 285 *rlz = cached_ommibox_rlz; | 281 *rlz = cached_ommibox_rlz; |
| 286 return true; | 282 return true; |
| 287 } | 283 } |
| 284 | |
| 285 // Make sure we don't access disk outside of the file context. | |
| 286 // In such case we repost the task on the right thread and return error. | |
| 287 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { | |
| 288 // Caching of access points is now only implemented for the CHROME_OMNIBOX. | |
| 289 // Thus it is not possible to call this function on another thread for | |
| 290 // other access points until proper caching for these has been implemented | |
| 291 // and the code that calls this function can handle synchronous fetching | |
| 292 // of the access point. | |
| 293 DCHECK_EQ(rlz_lib::CHROME_OMNIBOX, point); | |
| 294 | |
| 295 BrowserThread::PostTask( | |
| 296 BrowserThread::FILE, FROM_HERE, | |
| 297 NewRunnableFunction(&RLZTracker::GetAccessPointRlz, | |
| 298 point, &cached_ommibox_rlz)); | |
| 299 rlz->erase(); | |
| 300 return false; | |
| 301 } | |
| 302 | |
| 288 char str_rlz[kMaxRlzLength + 1]; | 303 char str_rlz[kMaxRlzLength + 1]; |
| 289 if (!rlz_lib::GetAccessPointRlz(point, str_rlz, rlz_lib::kMaxRlzLength, NULL)) | 304 if (!rlz_lib::GetAccessPointRlz(point, str_rlz, rlz_lib::kMaxRlzLength, NULL)) |
| 290 return false; | 305 return false; |
| 291 *rlz = ASCIIToWide(std::string(str_rlz)); | 306 *rlz = ASCIIToWide(std::string(str_rlz)); |
| 292 if (rlz_lib::CHROME_OMNIBOX == point) { | 307 if (rlz_lib::CHROME_OMNIBOX == point) { |
| 293 access_values_state = ACCESS_VALUES_FRESH; | 308 access_values_state = ACCESS_VALUES_FRESH; |
|
Roger Tawa OOO till Jul 10th
2011/01/18 21:00:14
there is now the possibility that multiple threads
pastarmovj
2011/01/18 21:10:20
I don't think this is possible. This code is only
Roger Tawa OOO till Jul 10th
2011/01/19 01:57:52
The ui thread can access access_values_state and c
pastarmovj
2011/01/19 08:34:18
Ah you meant between read and write access in the
| |
| 294 cached_ommibox_rlz.assign(*rlz); | 309 cached_ommibox_rlz.assign(*rlz); |
| 295 } | 310 } |
| 296 return true; | 311 return true; |
| 297 } | 312 } |
| 298 | 313 |
| 299 // static | 314 // static |
| 300 void RLZTracker::CleanupRlz() { | 315 void RLZTracker::CleanupRlz() { |
| 301 OmniBoxUsageObserver::DeleteInstance(); | 316 OmniBoxUsageObserver::DeleteInstance(); |
| 302 } | 317 } |
| OLD | NEW |