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