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" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/google/google_url_tracker_factory.h" | 12 #include "chrome/browser/google/google_url_tracker_factory.h" |
13 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h" | 13 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h" |
14 #include "chrome/browser/google/google_url_tracker_navigation_helper.h" | 14 #include "chrome/browser/google/google_url_tracker_navigation_helper.h" |
15 #include "chrome/browser/google/google_util.h" | 15 #include "chrome/browser/google/google_util.h" |
16 #include "chrome/browser/infobars/infobar_service.h" | 16 #include "chrome/browser/infobars/infobar_service.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "components/google/core/browser/google_url_tracker_client.h" | |
20 #include "components/infobars/core/infobar.h" | 21 #include "components/infobars/core/infobar.h" |
21 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
22 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
23 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
24 #include "net/base/load_flags.h" | 25 #include "net/base/load_flags.h" |
25 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
26 #include "net/url_request/url_fetcher.h" | 27 #include "net/url_request/url_fetcher.h" |
27 #include "net/url_request/url_request_status.h" | 28 #include "net/url_request/url_request_status.h" |
28 | 29 |
29 | 30 |
30 const char GoogleURLTracker::kDefaultGoogleHomepage[] = | 31 const char GoogleURLTracker::kDefaultGoogleHomepage[] = |
31 "http://www.google.com/"; | 32 "http://www.google.com/"; |
32 const char GoogleURLTracker::kSearchDomainCheckURL[] = | 33 const char GoogleURLTracker::kSearchDomainCheckURL[] = |
33 "https://www.google.com/searchdomaincheck?format=url&type=chrome"; | 34 "https://www.google.com/searchdomaincheck?format=url&type=chrome"; |
34 | 35 |
35 GoogleURLTracker::GoogleURLTracker( | 36 GoogleURLTracker::GoogleURLTracker( |
36 Profile* profile, | 37 Profile* profile, |
38 scoped_ptr<GoogleURLTrackerClient> client, | |
37 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, | 39 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, |
38 Mode mode) | 40 Mode mode) |
39 : profile_(profile), | 41 : profile_(profile), |
42 client_(client.Pass()), | |
40 nav_helper_(nav_helper.Pass()), | 43 nav_helper_(nav_helper.Pass()), |
41 infobar_creator_(base::Bind(&GoogleURLTrackerInfoBarDelegate::Create)), | 44 infobar_creator_(base::Bind(&GoogleURLTrackerInfoBarDelegate::Create)), |
42 google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage : | 45 google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage : |
43 profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)), | 46 profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)), |
44 fetcher_id_(0), | 47 fetcher_id_(0), |
45 in_startup_sleep_(true), | 48 in_startup_sleep_(true), |
46 already_fetched_(false), | 49 already_fetched_(false), |
47 need_to_fetch_(false), | 50 need_to_fetch_(false), |
48 need_to_prompt_(false), | 51 need_to_prompt_(false), |
49 search_committed_(false), | 52 search_committed_(false), |
50 weak_ptr_factory_(this) { | 53 weak_ptr_factory_(this) { |
51 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 54 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
55 client_->SetGoogleURLTracker(this); | |
52 nav_helper_->SetGoogleURLTracker(this); | 56 nav_helper_->SetGoogleURLTracker(this); |
53 | 57 |
54 // Because this function can be called during startup, when kicking off a URL | 58 // 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 | 59 // 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. | 60 // 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 | 61 // 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 | 62 // browser is starting up, and if so, come back later", but there is currently |
59 // no function to do this. | 63 // no function to do this. |
60 // | 64 // |
61 // In UNIT_TEST mode, where we want to explicitly control when the tracker | 65 // In UNIT_TEST mode, where we want to explicitly control when the tracker |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 CloseAllEntries(false); | 198 CloseAllEntries(false); |
195 } | 199 } |
196 } | 200 } |
197 | 201 |
198 void GoogleURLTracker::OnIPAddressChanged() { | 202 void GoogleURLTracker::OnIPAddressChanged() { |
199 already_fetched_ = false; | 203 already_fetched_ = false; |
200 StartFetchIfDesirable(); | 204 StartFetchIfDesirable(); |
201 } | 205 } |
202 | 206 |
203 void GoogleURLTracker::Shutdown() { | 207 void GoogleURLTracker::Shutdown() { |
208 client_.reset(); | |
204 nav_helper_.reset(); | 209 nav_helper_.reset(); |
205 fetcher_.reset(); | 210 fetcher_.reset(); |
206 weak_ptr_factory_.InvalidateWeakPtrs(); | 211 weak_ptr_factory_.InvalidateWeakPtrs(); |
Peter Kasting
2014/05/14 23:30:28
Why are the four lines above necessary?
blundell
2014/05/15 07:58:03
I'm not familiar with this code. For KeyedServices
Peter Kasting
2014/05/15 21:19:21
Ah, I overlooked that this is Shutdown() instead o
| |
207 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 212 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
208 } | 213 } |
209 | 214 |
210 void GoogleURLTracker::DeleteMapEntryForService( | 215 void GoogleURLTracker::DeleteMapEntryForService( |
211 const InfoBarService* infobar_service) { | 216 const InfoBarService* infobar_service) { |
212 // WARNING: |infobar_service| may point to a deleted object. Do not | 217 // WARNING: |infobar_service| may point to a deleted object. Do not |
213 // dereference it! See OnTabClosed(). | 218 // dereference it! See OnTabClosed(). |
214 EntryMap::iterator i(entry_map_.find(infobar_service)); | 219 EntryMap::iterator i(entry_map_.find(infobar_service)); |
215 DCHECK(i != entry_map_.end()); | 220 DCHECK(i != entry_map_.end()); |
216 GoogleURLTrackerMapEntry* map_entry = i->second; | 221 GoogleURLTrackerMapEntry* map_entry = i->second; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 fetcher_->SetMaxRetriesOn5xx(kMaxRetries); | 269 fetcher_->SetMaxRetriesOn5xx(kMaxRetries); |
265 | 270 |
266 fetcher_->Start(); | 271 fetcher_->Start(); |
267 } | 272 } |
268 | 273 |
269 void GoogleURLTracker::SearchCommitted() { | 274 void GoogleURLTracker::SearchCommitted() { |
270 if (need_to_prompt_) { | 275 if (need_to_prompt_) { |
271 search_committed_ = true; | 276 search_committed_ = true; |
272 // These notifications will fire a bit later in the same call chain we're | 277 // These notifications will fire a bit later in the same call chain we're |
273 // currently in. | 278 // currently in. |
274 if (!nav_helper_->IsListeningForNavigationStart()) | 279 if (!client_->IsListeningForNavigationStart()) |
275 nav_helper_->SetListeningForNavigationStart(true); | 280 client_->SetListeningForNavigationStart(true); |
276 } | 281 } |
277 } | 282 } |
278 | 283 |
279 void GoogleURLTracker::OnNavigationPending( | 284 void GoogleURLTracker::OnNavigationPending( |
280 content::NavigationController* navigation_controller, | 285 content::NavigationController* navigation_controller, |
281 InfoBarService* infobar_service, | 286 InfoBarService* infobar_service, |
282 int pending_id) { | 287 int pending_id) { |
283 EntryMap::iterator i(entry_map_.find(infobar_service)); | 288 EntryMap::iterator i(entry_map_.find(infobar_service)); |
284 | 289 |
285 if (search_committed_) { | 290 if (search_committed_) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 | 410 |
406 // Our global listeners for these other notifications should be in place iff | 411 // Our global listeners for these other notifications should be in place iff |
407 // we have any tabs still listening for commits. These tabs either have no | 412 // we have any tabs still listening for commits. These tabs either have no |
408 // infobars or have received new pending searches atop existing infobars; in | 413 // infobars or have received new pending searches atop existing infobars; in |
409 // either case we want to catch subsequent pending non-search navigations. | 414 // either case we want to catch subsequent pending non-search navigations. |
410 // See the various cases inside OnNavigationPending(). | 415 // See the various cases inside OnNavigationPending(). |
411 for (EntryMap::const_iterator i(entry_map_.begin()); i != entry_map_.end(); | 416 for (EntryMap::const_iterator i(entry_map_.begin()); i != entry_map_.end(); |
412 ++i) { | 417 ++i) { |
413 if (nav_helper_->IsListeningForNavigationCommit( | 418 if (nav_helper_->IsListeningForNavigationCommit( |
414 i->second->navigation_controller())) { | 419 i->second->navigation_controller())) { |
415 DCHECK(nav_helper_->IsListeningForNavigationStart()); | 420 DCHECK(client_->IsListeningForNavigationStart()); |
416 return; | 421 return; |
417 } | 422 } |
418 } | 423 } |
419 if (nav_helper_->IsListeningForNavigationStart()) { | 424 if (client_->IsListeningForNavigationStart()) { |
420 DCHECK(!search_committed_); | 425 DCHECK(!search_committed_); |
421 nav_helper_->SetListeningForNavigationStart(false); | 426 client_->SetListeningForNavigationStart(false); |
422 } | 427 } |
423 } | 428 } |
OLD | NEW |