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

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

Issue 285193002: Create GoogleURLTrackerClient interface and //chrome implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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/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 ?
46 kDefaultGoogleHomepage :
43 profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)), 47 profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)),
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 CloseAllEntries(false); 197 CloseAllEntries(false);
193 } 198 }
194 } 199 }
195 200
196 void GoogleURLTracker::OnIPAddressChanged() { 201 void GoogleURLTracker::OnIPAddressChanged() {
197 already_fetched_ = false; 202 already_fetched_ = false;
198 StartFetchIfDesirable(); 203 StartFetchIfDesirable();
199 } 204 }
200 205
201 void GoogleURLTracker::Shutdown() { 206 void GoogleURLTracker::Shutdown() {
207 client_.reset();
202 nav_helper_.reset(); 208 nav_helper_.reset();
203 fetcher_.reset(); 209 fetcher_.reset();
204 weak_ptr_factory_.InvalidateWeakPtrs(); 210 weak_ptr_factory_.InvalidateWeakPtrs();
205 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 211 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
206 } 212 }
207 213
208 void GoogleURLTracker::DeleteMapEntryForService( 214 void GoogleURLTracker::DeleteMapEntryForService(
209 const InfoBarService* infobar_service) { 215 const InfoBarService* infobar_service) {
210 // WARNING: |infobar_service| may point to a deleted object. Do not 216 // WARNING: |infobar_service| may point to a deleted object. Do not
211 // dereference it! See OnTabClosed(). 217 // dereference it! See OnTabClosed().
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 fetcher_->SetMaxRetriesOn5xx(kMaxRetries); 268 fetcher_->SetMaxRetriesOn5xx(kMaxRetries);
263 269
264 fetcher_->Start(); 270 fetcher_->Start();
265 } 271 }
266 272
267 void GoogleURLTracker::SearchCommitted() { 273 void GoogleURLTracker::SearchCommitted() {
268 if (need_to_prompt_) { 274 if (need_to_prompt_) {
269 search_committed_ = true; 275 search_committed_ = true;
270 // These notifications will fire a bit later in the same call chain we're 276 // These notifications will fire a bit later in the same call chain we're
271 // currently in. 277 // currently in.
272 if (!nav_helper_->IsListeningForNavigationStart()) 278 if (!client_->IsListeningForNavigationStart())
273 nav_helper_->SetListeningForNavigationStart(true); 279 client_->SetListeningForNavigationStart(true);
274 } 280 }
275 } 281 }
276 282
277 void GoogleURLTracker::OnNavigationPending( 283 void GoogleURLTracker::OnNavigationPending(
278 content::NavigationController* navigation_controller, 284 content::NavigationController* navigation_controller,
279 InfoBarService* infobar_service, 285 InfoBarService* infobar_service,
280 int pending_id) { 286 int pending_id) {
281 EntryMap::iterator i(entry_map_.find(infobar_service)); 287 EntryMap::iterator i(entry_map_.find(infobar_service));
282 288
283 if (search_committed_) { 289 if (search_committed_) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 414
409 // Our global listeners for these other notifications should be in place iff 415 // Our global listeners for these other notifications should be in place iff
410 // we have any tabs still listening for commits. These tabs either have no 416 // we have any tabs still listening for commits. These tabs either have no
411 // infobars or have received new pending searches atop existing infobars; in 417 // infobars or have received new pending searches atop existing infobars; in
412 // either case we want to catch subsequent pending non-search navigations. 418 // either case we want to catch subsequent pending non-search navigations.
413 // See the various cases inside OnNavigationPending(). 419 // See the various cases inside OnNavigationPending().
414 for (EntryMap::const_iterator i(entry_map_.begin()); i != entry_map_.end(); 420 for (EntryMap::const_iterator i(entry_map_.begin()); i != entry_map_.end();
415 ++i) { 421 ++i) {
416 if (nav_helper_->IsListeningForNavigationCommit( 422 if (nav_helper_->IsListeningForNavigationCommit(
417 i->second->navigation_controller())) { 423 i->second->navigation_controller())) {
418 DCHECK(nav_helper_->IsListeningForNavigationStart()); 424 DCHECK(client_->IsListeningForNavigationStart());
419 return; 425 return;
420 } 426 }
421 } 427 }
422 if (nav_helper_->IsListeningForNavigationStart()) { 428 if (client_->IsListeningForNavigationStart()) {
423 DCHECK(!search_committed_); 429 DCHECK(!search_committed_);
424 nav_helper_->SetListeningForNavigationStart(false); 430 client_->SetListeningForNavigationStart(false);
425 } 431 }
426 } 432 }
427 433
428 void GoogleURLTracker::NotifyGoogleURLUpdated(GURL old_url, GURL new_url) { 434 void GoogleURLTracker::NotifyGoogleURLUpdated(GURL old_url, GURL new_url) {
429 callback_list_.Notify(old_url, new_url); 435 callback_list_.Notify(old_url, new_url);
430 } 436 }
OLDNEW
« no previous file with comments | « chrome/browser/google/google_url_tracker.h ('k') | chrome/browser/google/google_url_tracker_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698