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 #include "chrome/browser/google/google_url_tracker.h" | 5 #include "chrome/browser/google/google_url_tracker.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/browser/profiles/profile.h" | |
16 #include "chrome/browser/search_engines/template_url.h" | 15 #include "chrome/browser/search_engines/template_url.h" |
17 #include "chrome/browser/tab_contents/navigation_controller.h" | 16 #include "chrome/browser/tab_contents/navigation_controller.h" |
18 #include "chrome/browser/tab_contents/tab_contents.h" | 17 #include "chrome/browser/tab_contents/tab_contents.h" |
19 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/notification_service.h" | 19 #include "chrome/common/notification_service.h" |
21 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
22 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
23 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
24 #include "net/url_request/url_request_status.h" | 23 #include "net/url_request/url_request_status.h" |
25 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 GoogleURLTracker::GoogleURLTracker() | 90 GoogleURLTracker::GoogleURLTracker() |
92 : infobar_creator_(&CreateInfobar), | 91 : infobar_creator_(&CreateInfobar), |
93 google_url_(g_browser_process->local_state()->GetString( | 92 google_url_(g_browser_process->local_state()->GetString( |
94 prefs::kLastKnownGoogleURL)), | 93 prefs::kLastKnownGoogleURL)), |
95 ALLOW_THIS_IN_INITIALIZER_LIST(runnable_method_factory_(this)), | 94 ALLOW_THIS_IN_INITIALIZER_LIST(runnable_method_factory_(this)), |
96 fetcher_id_(0), | 95 fetcher_id_(0), |
97 queue_wakeup_task_(true), | 96 queue_wakeup_task_(true), |
98 in_startup_sleep_(true), | 97 in_startup_sleep_(true), |
99 already_fetched_(false), | 98 already_fetched_(false), |
100 need_to_fetch_(false), | 99 need_to_fetch_(false), |
101 request_context_available_(!!Profile::GetDefaultRequestContext()), | 100 request_context_available_(!!g_browser_process->system_request_context()), |
102 need_to_prompt_(false), | 101 need_to_prompt_(false), |
103 controller_(NULL), | 102 controller_(NULL), |
104 infobar_(NULL) { | 103 infobar_(NULL) { |
105 registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, | 104 registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, |
106 NotificationService::AllSources()); | 105 NotificationService::AllSources()); |
107 | 106 |
108 net::NetworkChangeNotifier::AddObserver(this); | 107 net::NetworkChangeNotifier::AddObserver(this); |
109 | 108 |
110 MessageLoop::current()->PostTask(FROM_HERE, | 109 MessageLoop::current()->PostTask(FROM_HERE, |
111 runnable_method_factory_.NewRunnableMethod( | 110 runnable_method_factory_.NewRunnableMethod( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 return; | 185 return; |
187 | 186 |
188 if (CommandLine::ForCurrentProcess()->HasSwitch( | 187 if (CommandLine::ForCurrentProcess()->HasSwitch( |
189 switches::kDisableBackgroundNetworking)) | 188 switches::kDisableBackgroundNetworking)) |
190 return; | 189 return; |
191 | 190 |
192 already_fetched_ = true; | 191 already_fetched_ = true; |
193 fetcher_.reset(URLFetcher::Create(fetcher_id_, GURL(kSearchDomainCheckURL), | 192 fetcher_.reset(URLFetcher::Create(fetcher_id_, GURL(kSearchDomainCheckURL), |
194 URLFetcher::GET, this)); | 193 URLFetcher::GET, this)); |
195 ++fetcher_id_; | 194 ++fetcher_id_; |
196 // We don't want this fetch to affect existing state in the profile. For | 195 // We don't want this fetch to affect existing state in local_state. For |
197 // example, if a user has no Google cookies, this automatic check should not | 196 // example, if a user has no Google cookies, this automatic check should not |
198 // cause one to be set, lest we alarm the user. | 197 // cause one to be set, lest we alarm the user. |
199 fetcher_->set_load_flags(net::LOAD_DISABLE_CACHE | | 198 fetcher_->set_load_flags(net::LOAD_DISABLE_CACHE | |
200 net::LOAD_DO_NOT_SAVE_COOKIES); | 199 net::LOAD_DO_NOT_SAVE_COOKIES); |
201 fetcher_->set_request_context(Profile::GetDefaultRequestContext()); | 200 fetcher_->set_request_context(g_browser_process->system_request_context()); |
202 | 201 |
203 // Configure to max_retries at most kMaxRetries times for 5xx errors. | 202 // Configure to max_retries at most kMaxRetries times for 5xx errors. |
204 static const int kMaxRetries = 5; | 203 static const int kMaxRetries = 5; |
205 fetcher_->set_max_retries(kMaxRetries); | 204 fetcher_->set_max_retries(kMaxRetries); |
206 | 205 |
207 fetcher_->Start(); | 206 fetcher_->Start(); |
208 } | 207 } |
209 | 208 |
210 void GoogleURLTracker::OnURLFetchComplete(const URLFetcher* source, | 209 void GoogleURLTracker::OnURLFetchComplete(const URLFetcher* source, |
211 const GURL& url, | 210 const GURL& url, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 } | 366 } |
368 | 367 |
369 void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary( | 368 void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary( |
370 TabContents* tab_contents) { | 369 TabContents* tab_contents) { |
371 if (!need_to_prompt_) | 370 if (!need_to_prompt_) |
372 return; | 371 return; |
373 DCHECK(!fetched_google_url_.is_empty()); | 372 DCHECK(!fetched_google_url_.is_empty()); |
374 | 373 |
375 infobar_ = (*infobar_creator_)(tab_contents, this, fetched_google_url_); | 374 infobar_ = (*infobar_creator_)(tab_contents, this, fetched_google_url_); |
376 } | 375 } |
OLD | NEW |