Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: chrome/browser/rlz/rlz.cc

Issue 9699054: rlz: Hook up on mac, switch to chrome's network stack on win. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 return GetInstance()->Init(first_run, delay, google_default_search, 154 return GetInstance()->Init(first_run, delay, google_default_search,
142 google_default_homepage); 155 google_default_homepage);
143 } 156 }
144 157
145 bool RLZTracker::Init(bool first_run, int delay, bool google_default_search, 158 bool RLZTracker::Init(bool first_run, int delay, bool google_default_search,
146 bool google_default_homepage) { 159 bool google_default_homepage) {
147 first_run_ = first_run; 160 first_run_ = first_run;
148 google_default_search_ = google_default_search; 161 google_default_search_ = google_default_search;
149 google_default_homepage_ = google_default_homepage; 162 google_default_homepage_ = google_default_homepage;
150 163
164 worker_pool_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken();
Roger Tawa OOO till Jul 10th 2012/03/24 01:10:42 The idea is to delay rlz initialization as much as
Nico 2012/03/24 01:29:47 Done. (This is just an atomic increment behind the
165
151 // A negative delay means that a financial ping should be sent immediately 166 // A negative delay means that a financial ping should be sent immediately
152 // after a first search is recorded, without waiting for the next restart 167 // after a first search is recorded, without waiting for the next restart
153 // of chrome. However, we only want this behaviour on first run. 168 // of chrome. However, we only want this behaviour on first run.
154 send_ping_immediately_ = false; 169 send_ping_immediately_ = false;
155 if (delay < 0) { 170 if (delay < 0) {
156 send_ping_immediately_ = true; 171 send_ping_immediately_ = true;
157 delay = -delay; 172 delay = -delay;
158 } 173 }
159 174
160 // Maximum and minimum delay we would allow to be set through master 175 // Maximum and minimum delay we would allow to be set through master
(...skipping 20 matching lines...) Expand all
181 content::NotificationService::AllSources()); 196 content::NotificationService::AllSources());
182 197
183 ScheduleDelayedInit(delay); 198 ScheduleDelayedInit(delay);
184 199
185 return true; 200 return true;
186 } 201 }
187 202
188 void RLZTracker::ScheduleDelayedInit(int delay) { 203 void RLZTracker::ScheduleDelayedInit(int delay) {
189 // The RLZTracker is a singleton object that outlives any runnable tasks 204 // The RLZTracker is a singleton object that outlives any runnable tasks
190 // that will be queued up. 205 // that will be queued up.
206 // TODO: Move to SequencedWorkerPool once http://crbug.com/119657 is fixed.
191 BrowserThread::PostDelayedTask( 207 BrowserThread::PostDelayedTask(
192 BrowserThread::FILE, 208 BrowserThread::FILE,
193 FROM_HERE, 209 FROM_HERE,
194 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)), 210 base::Bind(&RLZTracker::DelayedInit, base::Unretained(this)),
195 delay); 211 delay);
196 } 212 }
197 213
198 void RLZTracker::DelayedInit() { 214 void RLZTracker::DelayedInit() {
199 bool schedule_ping = false; 215 bool schedule_ping = false;
200 216
217 rlz_lib::SetURLRequestContext(g_browser_process->system_request_context());
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698