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

Side by Side Diff: chrome/browser/google/google_url_tracker.cc

Issue 6292017: Extended: Add "system" URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to ToT Created 9 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) 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/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/net/url_request_context_getter.h"
18 #include "chrome/common/notification_service.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "content/browser/tab_contents/navigation_controller.h" 20 #include "content/browser/tab_contents/navigation_controller.h"
20 #include "content/browser/tab_contents/tab_contents.h" 21 #include "content/browser/tab_contents/tab_contents.h"
21 #include "content/common/notification_service.h" 22 #include "content/common/notification_service.h"
22 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
23 #include "net/base/load_flags.h" 24 #include "net/base/load_flags.h"
24 #include "net/url_request/url_request_status.h" 25 #include "net/url_request/url_request_status.h"
25 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
26 27
27 namespace { 28 namespace {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 GoogleURLTracker::GoogleURLTracker() 92 GoogleURLTracker::GoogleURLTracker()
92 : infobar_creator_(&CreateInfobar), 93 : infobar_creator_(&CreateInfobar),
93 google_url_(g_browser_process->local_state()->GetString( 94 google_url_(g_browser_process->local_state()->GetString(
94 prefs::kLastKnownGoogleURL)), 95 prefs::kLastKnownGoogleURL)),
95 ALLOW_THIS_IN_INITIALIZER_LIST(runnable_method_factory_(this)), 96 ALLOW_THIS_IN_INITIALIZER_LIST(runnable_method_factory_(this)),
96 fetcher_id_(0), 97 fetcher_id_(0),
97 queue_wakeup_task_(true), 98 queue_wakeup_task_(true),
98 in_startup_sleep_(true), 99 in_startup_sleep_(true),
99 already_fetched_(false), 100 already_fetched_(false),
100 need_to_fetch_(false), 101 need_to_fetch_(false),
101 request_context_available_(!!Profile::GetDefaultRequestContext()),
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,
106 NotificationService::AllSources());
107
108 net::NetworkChangeNotifier::AddIPAddressObserver(this); 105 net::NetworkChangeNotifier::AddIPAddressObserver(this);
109 106
110 MessageLoop::current()->PostTask(FROM_HERE, 107 MessageLoop::current()->PostTask(FROM_HERE,
111 runnable_method_factory_.NewRunnableMethod( 108 runnable_method_factory_.NewRunnableMethod(
112 &GoogleURLTracker::QueueWakeupTask)); 109 &GoogleURLTracker::QueueWakeupTask));
113 } 110 }
114 111
115 GoogleURLTracker::~GoogleURLTracker() { 112 GoogleURLTracker::~GoogleURLTracker() {
116 runnable_method_factory_.RevokeAll(); 113 runnable_method_factory_.RevokeAll();
117 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 114 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 StartFetchIfDesirable(); 171 StartFetchIfDesirable();
175 } 172 }
176 173
177 void GoogleURLTracker::StartFetchIfDesirable() { 174 void GoogleURLTracker::StartFetchIfDesirable() {
178 // Bail if a fetch isn't appropriate right now. This function will be called 175 // Bail if a fetch isn't appropriate right now. This function will be called
179 // again each time one of the preconditions changes, so we'll fetch 176 // again each time one of the preconditions changes, so we'll fetch
180 // immediately once all of them are met. 177 // immediately once all of them are met.
181 // 178 //
182 // See comments in header on the class, on RequestServerCheck(), and on the 179 // See comments in header on the class, on RequestServerCheck(), and on the
183 // various members here for more detail on exactly what the conditions are. 180 // various members here for more detail on exactly what the conditions are.
184 if (in_startup_sleep_ || already_fetched_ || !need_to_fetch_ || 181 if (in_startup_sleep_ || already_fetched_ || !need_to_fetch_)
185 !request_context_available_)
186 return; 182 return;
187 183
188 if (CommandLine::ForCurrentProcess()->HasSwitch( 184 if (CommandLine::ForCurrentProcess()->HasSwitch(
189 switches::kDisableBackgroundNetworking)) 185 switches::kDisableBackgroundNetworking))
190 return; 186 return;
191 187
192 already_fetched_ = true; 188 already_fetched_ = true;
193 fetcher_.reset(URLFetcher::Create(fetcher_id_, GURL(kSearchDomainCheckURL), 189 fetcher_.reset(URLFetcher::Create(fetcher_id_, GURL(kSearchDomainCheckURL),
194 URLFetcher::GET, this)); 190 URLFetcher::GET, this));
195 ++fetcher_id_; 191 ++fetcher_id_;
196 // We don't want this fetch to affect existing state in the profile. For 192 // 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 193 // example, if a user has no Google cookies, this automatic check should not
198 // cause one to be set, lest we alarm the user. 194 // cause one to be set, lest we alarm the user.
199 fetcher_->set_load_flags(net::LOAD_DISABLE_CACHE | 195 fetcher_->set_load_flags(net::LOAD_DISABLE_CACHE |
200 net::LOAD_DO_NOT_SAVE_COOKIES); 196 net::LOAD_DO_NOT_SAVE_COOKIES);
201 fetcher_->set_request_context(Profile::GetDefaultRequestContext()); 197 fetcher_->set_request_context(g_browser_process->system_request_context());
202 198
203 // Configure to max_retries at most kMaxRetries times for 5xx errors. 199 // Configure to max_retries at most kMaxRetries times for 5xx errors.
204 static const int kMaxRetries = 5; 200 static const int kMaxRetries = 5;
205 fetcher_->set_max_retries(kMaxRetries); 201 fetcher_->set_max_retries(kMaxRetries);
206 202
207 fetcher_->Start(); 203 fetcher_->Start();
208 } 204 }
209 205
210 void GoogleURLTracker::OnURLFetchComplete(const URLFetcher* source, 206 void GoogleURLTracker::OnURLFetchComplete(const URLFetcher* source,
211 const GURL& url, 207 const GURL& url,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 GURL new_search_url(search_url_.ReplaceComponents(replacements)); 287 GURL new_search_url(search_url_.ReplaceComponents(replacements));
292 if (new_search_url.is_valid()) 288 if (new_search_url.is_valid())
293 controller_->tab_contents()->OpenURL(new_search_url, GURL(), CURRENT_TAB, 289 controller_->tab_contents()->OpenURL(new_search_url, GURL(), CURRENT_TAB,
294 PageTransition::GENERATED); 290 PageTransition::GENERATED);
295 } 291 }
296 292
297 void GoogleURLTracker::Observe(NotificationType type, 293 void GoogleURLTracker::Observe(NotificationType type,
298 const NotificationSource& source, 294 const NotificationSource& source,
299 const NotificationDetails& details) { 295 const NotificationDetails& details) {
300 switch (type.value) { 296 switch (type.value) {
301 case NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE:
302 registrar_.Remove(this,
303 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
304 NotificationService::AllSources());
305 request_context_available_ = true;
306 StartFetchIfDesirable();
307 break;
308
309 case NotificationType::NAV_ENTRY_PENDING: { 297 case NotificationType::NAV_ENTRY_PENDING: {
310 NavigationController* controller = 298 NavigationController* controller =
311 Source<NavigationController>(source).ptr(); 299 Source<NavigationController>(source).ptr();
312 OnNavigationPending(source, controller->pending_entry()->url()); 300 OnNavigationPending(source, controller->pending_entry()->url());
313 break; 301 break;
314 } 302 }
315 303
316 case NotificationType::NAV_ENTRY_COMMITTED: 304 case NotificationType::NAV_ENTRY_COMMITTED:
317 case NotificationType::TAB_CLOSED: 305 case NotificationType::TAB_CLOSED:
318 OnNavigationCommittedOrTabClosed( 306 OnNavigationCommittedOrTabClosed(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 355 }
368 356
369 void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary( 357 void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary(
370 TabContents* tab_contents) { 358 TabContents* tab_contents) {
371 if (!need_to_prompt_) 359 if (!need_to_prompt_)
372 return; 360 return;
373 DCHECK(!fetched_google_url_.is_empty()); 361 DCHECK(!fetched_google_url_.is_empty());
374 362
375 infobar_ = (*infobar_creator_)(tab_contents, this, fetched_google_url_); 363 infobar_ = (*infobar_creator_)(tab_contents, this, fetched_google_url_);
376 } 364 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698