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( |
47 prefs::kLastKnownGoogleURL)), | |
Peter Kasting
2014/05/16 23:21:08
Nit: Wrap like:
google_url_((mode == UNIT_T
blundell
2014/05/17 19:06:07
Done.
| |
44 fetcher_id_(0), | 48 fetcher_id_(0), |
45 in_startup_sleep_(true), | 49 in_startup_sleep_(true), |
46 already_fetched_(false), | 50 already_fetched_(false), |
47 need_to_fetch_(false), | 51 need_to_fetch_(false), |
48 need_to_prompt_(false), | 52 need_to_prompt_(false), |
49 search_committed_(false), | 53 search_committed_(false), |
50 weak_ptr_factory_(this) { | 54 weak_ptr_factory_(this) { |
51 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 55 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
56 client_->set_google_url_tracker(this); | |
52 nav_helper_->SetGoogleURLTracker(this); | 57 nav_helper_->SetGoogleURLTracker(this); |
53 | 58 |
54 // Because this function can be called during startup, when kicking off a URL | 59 // 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 | 60 // 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. | 61 // 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 | 62 // 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 | 63 // browser is starting up, and if so, come back later", but there is currently |
59 // no function to do this. | 64 // no function to do this. |
60 // | 65 // |
61 // In UNIT_TEST mode, where we want to explicitly control when the tracker | 66 // 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); | 199 CloseAllEntries(false); |
195 } | 200 } |
196 } | 201 } |
197 | 202 |
198 void GoogleURLTracker::OnIPAddressChanged() { | 203 void GoogleURLTracker::OnIPAddressChanged() { |
199 already_fetched_ = false; | 204 already_fetched_ = false; |
200 StartFetchIfDesirable(); | 205 StartFetchIfDesirable(); |
201 } | 206 } |
202 | 207 |
203 void GoogleURLTracker::Shutdown() { | 208 void GoogleURLTracker::Shutdown() { |
209 client_.reset(); | |
204 nav_helper_.reset(); | 210 nav_helper_.reset(); |
205 fetcher_.reset(); | 211 fetcher_.reset(); |
206 weak_ptr_factory_.InvalidateWeakPtrs(); | 212 weak_ptr_factory_.InvalidateWeakPtrs(); |
207 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 213 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
208 } | 214 } |
209 | 215 |
210 void GoogleURLTracker::DeleteMapEntryForService( | 216 void GoogleURLTracker::DeleteMapEntryForService( |
211 const InfoBarService* infobar_service) { | 217 const InfoBarService* infobar_service) { |
212 // WARNING: |infobar_service| may point to a deleted object. Do not | 218 // WARNING: |infobar_service| may point to a deleted object. Do not |
213 // dereference it! See OnTabClosed(). | 219 // dereference it! See OnTabClosed(). |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 fetcher_->SetMaxRetriesOn5xx(kMaxRetries); | 270 fetcher_->SetMaxRetriesOn5xx(kMaxRetries); |
265 | 271 |
266 fetcher_->Start(); | 272 fetcher_->Start(); |
267 } | 273 } |
268 | 274 |
269 void GoogleURLTracker::SearchCommitted() { | 275 void GoogleURLTracker::SearchCommitted() { |
270 if (need_to_prompt_) { | 276 if (need_to_prompt_) { |
271 search_committed_ = true; | 277 search_committed_ = true; |
272 // These notifications will fire a bit later in the same call chain we're | 278 // These notifications will fire a bit later in the same call chain we're |
273 // currently in. | 279 // currently in. |
274 if (!nav_helper_->IsListeningForNavigationStart()) | 280 if (!client_->IsListeningForNavigationStart()) |
275 nav_helper_->SetListeningForNavigationStart(true); | 281 client_->SetListeningForNavigationStart(true); |
276 } | 282 } |
277 } | 283 } |
278 | 284 |
279 void GoogleURLTracker::OnNavigationPending( | 285 void GoogleURLTracker::OnNavigationPending( |
280 content::NavigationController* navigation_controller, | 286 content::NavigationController* navigation_controller, |
281 InfoBarService* infobar_service, | 287 InfoBarService* infobar_service, |
282 int pending_id) { | 288 int pending_id) { |
283 EntryMap::iterator i(entry_map_.find(infobar_service)); | 289 EntryMap::iterator i(entry_map_.find(infobar_service)); |
284 | 290 |
285 if (search_committed_) { | 291 if (search_committed_) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 | 411 |
406 // Our global listeners for these other notifications should be in place iff | 412 // 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 | 413 // 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 | 414 // infobars or have received new pending searches atop existing infobars; in |
409 // either case we want to catch subsequent pending non-search navigations. | 415 // either case we want to catch subsequent pending non-search navigations. |
410 // See the various cases inside OnNavigationPending(). | 416 // See the various cases inside OnNavigationPending(). |
411 for (EntryMap::const_iterator i(entry_map_.begin()); i != entry_map_.end(); | 417 for (EntryMap::const_iterator i(entry_map_.begin()); i != entry_map_.end(); |
412 ++i) { | 418 ++i) { |
413 if (nav_helper_->IsListeningForNavigationCommit( | 419 if (nav_helper_->IsListeningForNavigationCommit( |
414 i->second->navigation_controller())) { | 420 i->second->navigation_controller())) { |
415 DCHECK(nav_helper_->IsListeningForNavigationStart()); | 421 DCHECK(client_->IsListeningForNavigationStart()); |
416 return; | 422 return; |
417 } | 423 } |
418 } | 424 } |
419 if (nav_helper_->IsListeningForNavigationStart()) { | 425 if (client_->IsListeningForNavigationStart()) { |
420 DCHECK(!search_committed_); | 426 DCHECK(!search_committed_); |
421 nav_helper_->SetListeningForNavigationStart(false); | 427 client_->SetListeningForNavigationStart(false); |
422 } | 428 } |
423 } | 429 } |
OLD | NEW |