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

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

Issue 11620007: Switch from OnIPAddressChanged and OnConnectionTypeChange to OnNetworkChanged Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 #include "chrome/browser/google/google_url_tracker.h" 5 #include "chrome/browser/google/google_url_tracker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "chrome/browser/api/infobars/infobar_service.h" 10 #include "chrome/browser/api/infobars/infobar_service.h"
(...skipping 25 matching lines...) Expand all
36 infobar_creator_(base::Bind(&GoogleURLTrackerInfoBarDelegate::Create)), 36 infobar_creator_(base::Bind(&GoogleURLTrackerInfoBarDelegate::Create)),
37 google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage : 37 google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage :
38 profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)), 38 profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)),
39 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 39 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
40 fetcher_id_(0), 40 fetcher_id_(0),
41 in_startup_sleep_(true), 41 in_startup_sleep_(true),
42 already_fetched_(false), 42 already_fetched_(false),
43 need_to_fetch_(false), 43 need_to_fetch_(false),
44 need_to_prompt_(false), 44 need_to_prompt_(false),
45 search_committed_(false) { 45 search_committed_(false) {
46 net::NetworkChangeNotifier::AddIPAddressObserver(this); 46 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
47 47
48 // Because this function can be called during startup, when kicking off a URL 48 // Because this function can be called during startup, when kicking off a URL
49 // fetch can eat up 20 ms of time, we delay five seconds, which is hopefully 49 // fetch can eat up 20 ms of time, we delay five seconds, which is hopefully
50 // long enough to be after startup, but still get results back quickly. 50 // long enough to be after startup, but still get results back quickly.
51 // Ideally, instead of this timer, we'd do something like "check if the 51 // Ideally, instead of this timer, we'd do something like "check if the
52 // browser is starting up, and if so, come back later", but there is currently 52 // browser is starting up, and if so, come back later", but there is currently
53 // no function to do this. 53 // no function to do this.
54 // 54 //
55 // In UNIT_TEST mode, where we want to explicitly control when the tracker 55 // In UNIT_TEST mode, where we want to explicitly control when the tracker
56 // "wakes up", we do nothing at all. 56 // "wakes up", we do nothing at all.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 &web_contents->GetController()), 237 &web_contents->GetController()),
238 source, InfoBarService::FromWebContents(web_contents), search_url); 238 source, InfoBarService::FromWebContents(web_contents), search_url);
239 break; 239 break;
240 } 240 }
241 241
242 default: 242 default:
243 NOTREACHED() << "Unknown notification received:" << type; 243 NOTREACHED() << "Unknown notification received:" << type;
244 } 244 }
245 } 245 }
246 246
247 void GoogleURLTracker::OnIPAddressChanged() { 247 void GoogleURLTracker::OnNetworkChanged(
248 already_fetched_ = false; 248 net::NetworkChangeNotifier::ConnectionType type) {
249 StartFetchIfDesirable(); 249 if (type != net::NetworkChangeNotifier::CONNECTION_NONE) {
250 already_fetched_ = false;
251 StartFetchIfDesirable();
252 }
250 } 253 }
251 254
252 void GoogleURLTracker::Shutdown() { 255 void GoogleURLTracker::Shutdown() {
253 registrar_.RemoveAll(); 256 registrar_.RemoveAll();
254 weak_ptr_factory_.InvalidateWeakPtrs(); 257 weak_ptr_factory_.InvalidateWeakPtrs();
255 fetcher_.reset(); 258 fetcher_.reset();
256 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 259 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
257 } 260 }
258 261
259 void GoogleURLTracker::DeleteMapEntryForService( 262 void GoogleURLTracker::DeleteMapEntryForService(
260 const InfoBarService* infobar_service) { 263 const InfoBarService* infobar_service) {
261 // WARNING: |infobar_service| may point to a deleted object. Do not 264 // WARNING: |infobar_service| may point to a deleted object. Do not
262 // dereference it! See OnTabClosed(). 265 // dereference it! See OnTabClosed().
263 EntryMap::iterator i(entry_map_.find(infobar_service)); 266 EntryMap::iterator i(entry_map_.find(infobar_service));
264 DCHECK(i != entry_map_.end()); 267 DCHECK(i != entry_map_.end());
265 GoogleURLTrackerMapEntry* map_entry = i->second; 268 GoogleURLTrackerMapEntry* map_entry = i->second;
266 269
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 507 }
505 if (registrar_.IsRegistered(this, content::NOTIFICATION_NAV_ENTRY_PENDING, 508 if (registrar_.IsRegistered(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
506 content::NotificationService::AllBrowserContextsAndSources())) { 509 content::NotificationService::AllBrowserContextsAndSources())) {
507 DCHECK(!search_committed_); 510 DCHECK(!search_committed_);
508 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, 511 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
509 content::NotificationService::AllBrowserContextsAndSources()); 512 content::NotificationService::AllBrowserContextsAndSources());
510 registrar_.Remove(this, chrome::NOTIFICATION_INSTANT_COMMITTED, 513 registrar_.Remove(this, chrome::NOTIFICATION_INSTANT_COMMITTED,
511 content::NotificationService::AllBrowserContextsAndSources()); 514 content::NotificationService::AllBrowserContextsAndSources());
512 } 515 }
513 } 516 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698