| OLD | NEW |
| 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/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 GoogleURLTracker::GoogleURLTracker( | 35 GoogleURLTracker::GoogleURLTracker( |
| 36 Profile* profile, | 36 Profile* profile, |
| 37 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, | 37 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, |
| 38 Mode mode) | 38 Mode mode) |
| 39 : profile_(profile), | 39 : profile_(profile), |
| 40 nav_helper_(nav_helper.Pass()), | 40 nav_helper_(nav_helper.Pass()), |
| 41 infobar_creator_(base::Bind(&GoogleURLTrackerInfoBarDelegate::Create)), | 41 infobar_creator_(base::Bind(&GoogleURLTrackerInfoBarDelegate::Create)), |
| 42 google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage : | 42 google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage : |
| 43 profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)), | 43 profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)), |
| 44 weak_ptr_factory_(this), | |
| 45 fetcher_id_(0), | 44 fetcher_id_(0), |
| 46 in_startup_sleep_(true), | 45 in_startup_sleep_(true), |
| 47 already_fetched_(false), | 46 already_fetched_(false), |
| 48 need_to_fetch_(false), | 47 need_to_fetch_(false), |
| 49 need_to_prompt_(false), | 48 need_to_prompt_(false), |
| 50 search_committed_(false) { | 49 search_committed_(false), |
| 50 weak_ptr_factory_(this) { |
| 51 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 51 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
| 52 nav_helper_->SetGoogleURLTracker(this); | 52 nav_helper_->SetGoogleURLTracker(this); |
| 53 | 53 |
| 54 // Because this function can be called during startup, when kicking off a URL | 54 // Because this function can be called during startup, when kicking off a URL |
| 55 // fetch can eat up 20 ms of time, we delay five seconds, which is hopefully | 55 // fetch can eat up 20 ms of time, we delay five seconds, which is hopefully |
| 56 // long enough to be after startup, but still get results back quickly. | 56 // long enough to be after startup, but still get results back quickly. |
| 57 // Ideally, instead of this timer, we'd do something like "check if the | 57 // Ideally, instead of this timer, we'd do something like "check if the |
| 58 // browser is starting up, and if so, come back later", but there is currently | 58 // browser is starting up, and if so, come back later", but there is currently |
| 59 // no function to do this. | 59 // no function to do this. |
| 60 // | 60 // |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 | 197 |
| 198 void GoogleURLTracker::OnIPAddressChanged() { | 198 void GoogleURLTracker::OnIPAddressChanged() { |
| 199 already_fetched_ = false; | 199 already_fetched_ = false; |
| 200 StartFetchIfDesirable(); | 200 StartFetchIfDesirable(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void GoogleURLTracker::Shutdown() { | 203 void GoogleURLTracker::Shutdown() { |
| 204 nav_helper_.reset(); | 204 nav_helper_.reset(); |
| 205 fetcher_.reset(); |
| 205 weak_ptr_factory_.InvalidateWeakPtrs(); | 206 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 206 fetcher_.reset(); | |
| 207 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 207 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void GoogleURLTracker::DeleteMapEntryForService( | 210 void GoogleURLTracker::DeleteMapEntryForService( |
| 211 const InfoBarService* infobar_service) { | 211 const InfoBarService* infobar_service) { |
| 212 // WARNING: |infobar_service| may point to a deleted object. Do not | 212 // WARNING: |infobar_service| may point to a deleted object. Do not |
| 213 // dereference it! See OnTabClosed(). | 213 // dereference it! See OnTabClosed(). |
| 214 EntryMap::iterator i(entry_map_.find(infobar_service)); | 214 EntryMap::iterator i(entry_map_.find(infobar_service)); |
| 215 DCHECK(i != entry_map_.end()); | 215 DCHECK(i != entry_map_.end()); |
| 216 GoogleURLTrackerMapEntry* map_entry = i->second; | 216 GoogleURLTrackerMapEntry* map_entry = i->second; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 i->second->navigation_controller())) { | 418 i->second->navigation_controller())) { |
| 419 DCHECK(nav_helper_->IsListeningForNavigationStart()); | 419 DCHECK(nav_helper_->IsListeningForNavigationStart()); |
| 420 return; | 420 return; |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 if (nav_helper_->IsListeningForNavigationStart()) { | 423 if (nav_helper_->IsListeningForNavigationStart()) { |
| 424 DCHECK(!search_committed_); | 424 DCHECK(!search_committed_); |
| 425 nav_helper_->SetListeningForNavigationStart(false); | 425 nav_helper_->SetListeningForNavigationStart(false); |
| 426 } | 426 } |
| 427 } | 427 } |
| OLD | NEW |