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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 // For organic brandcodes do not use rlz at all. Empty brandcode usually | 181 // For organic brandcodes do not use rlz at all. Empty brandcode usually |
| 181 // means a chromium install. This is ok. | 182 // means a chromium install. This is ok. |
| 182 std::wstring brand; | 183 std::wstring brand; |
| 183 if (!GoogleUpdateSettings::GetBrand(&brand) || brand.empty() || | 184 if (!GoogleUpdateSettings::GetBrand(&brand) || brand.empty() || |
| 184 GoogleUpdateSettings::IsOrganic(brand)) | 185 GoogleUpdateSettings::IsOrganic(brand)) |
| 185 return; | 186 return; |
| 186 | 187 |
| 187 // Do the initial event recording if is the first run or if we have an | 188 // Do the initial event recording if is the first run or if we have an |
| 188 // empty rlz which means we haven't got a chance to do it. | 189 // empty rlz which means we haven't got a chance to do it. |
| 189 std::wstring omnibox_rlz; | 190 std::wstring omnibox_rlz; |
| 190 RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &omnibox_rlz); | 191 RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &omnibox_rlz); |
|
Roger Tawa OOO till Jul 10th
2011/01/12 15:46:52
This call may return an empty string, since we're
jochen (gone - plz use gerrit)
2011/01/13 09:25:25
an alternative would be to add a callback paramete
Roger Tawa OOO till Jul 10th
2011/01/13 15:09:55
Thinking about it some, I don't think this is a pr
pastarmovj
2011/01/13 15:34:02
In general I am not happy leaving this function li
Roger Tawa OOO till Jul 10th
2011/01/13 15:42:17
Is there a need to post DelayedInitTask to the UI
| |
| 191 | 192 |
| 192 if (first_run_ || omnibox_rlz.empty()) { | 193 if (first_run_ || omnibox_rlz.empty()) { |
| 193 // Record the installation of chrome. | 194 // Record the installation of chrome. |
| 194 RLZTracker::RecordProductEvent(rlz_lib::CHROME, | 195 RLZTracker::RecordProductEvent(rlz_lib::CHROME, |
| 195 rlz_lib::CHROME_OMNIBOX, | 196 rlz_lib::CHROME_OMNIBOX, |
| 196 rlz_lib::INSTALL); | 197 rlz_lib::INSTALL); |
| 197 RLZTracker::RecordProductEvent(rlz_lib::CHROME, | 198 RLZTracker::RecordProductEvent(rlz_lib::CHROME, |
| 198 rlz_lib::CHROME_HOME_PAGE, | 199 rlz_lib::CHROME_HOME_PAGE, |
| 199 rlz_lib::INSTALL); | 200 rlz_lib::INSTALL); |
| 200 // Record if google is the initial search provider. | 201 // Record if google is the initial search provider. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 // cached value. | 279 // cached value. |
| 279 | 280 |
| 280 bool RLZTracker::GetAccessPointRlz(rlz_lib::AccessPoint point, | 281 bool RLZTracker::GetAccessPointRlz(rlz_lib::AccessPoint point, |
| 281 std::wstring* rlz) { | 282 std::wstring* rlz) { |
| 282 static std::wstring cached_ommibox_rlz; | 283 static std::wstring cached_ommibox_rlz; |
| 283 if ((rlz_lib::CHROME_OMNIBOX == point) && | 284 if ((rlz_lib::CHROME_OMNIBOX == point) && |
| 284 (access_values_state == ACCESS_VALUES_FRESH)) { | 285 (access_values_state == ACCESS_VALUES_FRESH)) { |
| 285 *rlz = cached_ommibox_rlz; | 286 *rlz = cached_ommibox_rlz; |
| 286 return true; | 287 return true; |
| 287 } | 288 } |
| 289 | |
| 290 // Make sure we don't access disk outside of the file context. | |
| 291 // In such case we repost the task on the right thread and return error. | |
| 292 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { | |
| 293 // Caching of access points is now only implemented for the CHROME_OMNIBOX. | |
| 294 // Thus it is not possible to call this function on another thread for | |
| 295 // other access points until proper caching for these has been implemented | |
| 296 // and the code that calls this function can handle synchronous fetching | |
| 297 // of the access point. | |
| 298 DCHECK_EQ(rlz_lib::CHROME_OMNIBOX, point); | |
| 299 | |
| 300 BrowserThread::PostTask( | |
| 301 BrowserThread::FILE, FROM_HERE, | |
| 302 NewRunnableFunction(&RLZTracker::GetAccessPointRlz, | |
| 303 point, &cached_ommibox_rlz)); | |
| 304 rlz->erase(); | |
| 305 return false; | |
| 306 } | |
| 307 | |
| 288 char str_rlz[kMaxRlzLength + 1]; | 308 char str_rlz[kMaxRlzLength + 1]; |
| 289 if (!rlz_lib::GetAccessPointRlz(point, str_rlz, rlz_lib::kMaxRlzLength, NULL)) | 309 if (!rlz_lib::GetAccessPointRlz(point, str_rlz, rlz_lib::kMaxRlzLength, NULL)) |
| 290 return false; | 310 return false; |
| 291 *rlz = ASCIIToWide(std::string(str_rlz)); | 311 *rlz = ASCIIToWide(std::string(str_rlz)); |
| 292 if (rlz_lib::CHROME_OMNIBOX == point) { | 312 if (rlz_lib::CHROME_OMNIBOX == point) { |
| 293 access_values_state = ACCESS_VALUES_FRESH; | 313 access_values_state = ACCESS_VALUES_FRESH; |
| 294 cached_ommibox_rlz.assign(*rlz); | 314 cached_ommibox_rlz.assign(*rlz); |
| 295 } | 315 } |
| 296 return true; | 316 return true; |
| 297 } | 317 } |
| 298 | 318 |
| 299 // static | 319 // static |
| 300 void RLZTracker::CleanupRlz() { | 320 void RLZTracker::CleanupRlz() { |
| 301 OmniBoxUsageObserver::DeleteInstance(); | 321 OmniBoxUsageObserver::DeleteInstance(); |
| 302 } | 322 } |
| OLD | NEW |