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/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" |
11 #include "chrome/browser/google/google_url_tracker_factory.h" | 11 #include "chrome/browser/google/google_url_tracker_factory.h" |
12 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h" | 12 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h" |
13 #include "chrome/browser/google/google_util.h" | 13 #include "chrome/browser/google/google_util.h" |
14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
20 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
24 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
25 #include "net/url_request/url_fetcher.h" | 25 #include "net/url_request/url_fetcher.h" |
26 #include "net/url_request/url_request_status.h" | 26 #include "net/url_request/url_request_status.h" |
27 | 27 |
28 | 28 |
29 namespace { | |
30 | |
31 GoogleURLTrackerInfoBarDelegate* CreateInfoBar( | |
32 InfoBarService* infobar_service, | |
33 GoogleURLTracker* google_url_tracker, | |
34 const GURL& search_url) { | |
35 GoogleURLTrackerInfoBarDelegate* infobar = | |
36 new GoogleURLTrackerInfoBarDelegate(infobar_service, google_url_tracker, | |
37 search_url); | |
38 // AddInfoBar() takes ownership; it will delete |infobar| if it fails. | |
39 return infobar_service->AddInfoBar(infobar) ? infobar : NULL; | |
40 } | |
41 | |
42 } // namespace | |
43 | |
44 | |
45 // GoogleURLTracker ----------------------------------------------------------- | |
46 | |
47 const char GoogleURLTracker::kDefaultGoogleHomepage[] = | 29 const char GoogleURLTracker::kDefaultGoogleHomepage[] = |
48 "http://www.google.com/"; | 30 "http://www.google.com/"; |
49 const char GoogleURLTracker::kSearchDomainCheckURL[] = | 31 const char GoogleURLTracker::kSearchDomainCheckURL[] = |
50 "https://www.google.com/searchdomaincheck?format=url&type=chrome"; | 32 "https://www.google.com/searchdomaincheck?format=url&type=chrome"; |
51 | 33 |
52 GoogleURLTracker::GoogleURLTracker(Profile* profile, Mode mode) | 34 GoogleURLTracker::GoogleURLTracker(Profile* profile, Mode mode) |
53 : profile_(profile), | 35 : profile_(profile), |
54 infobar_creator_(base::Bind(&CreateInfoBar)), | 36 infobar_creator_(base::Bind(&GoogleURLTrackerInfoBarDelegate::Create)), |
55 google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage : | 37 google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage : |
56 profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)), | 38 profile->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)), |
57 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 39 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
58 fetcher_id_(0), | 40 fetcher_id_(0), |
59 in_startup_sleep_(true), | 41 in_startup_sleep_(true), |
60 already_fetched_(false), | 42 already_fetched_(false), |
61 need_to_fetch_(false), | 43 need_to_fetch_(false), |
62 need_to_prompt_(false), | 44 need_to_prompt_(false), |
63 search_committed_(false) { | 45 search_committed_(false) { |
64 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 46 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 } | 504 } |
523 if (registrar_.IsRegistered(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 505 if (registrar_.IsRegistered(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
524 content::NotificationService::AllBrowserContextsAndSources())) { | 506 content::NotificationService::AllBrowserContextsAndSources())) { |
525 DCHECK(!search_committed_); | 507 DCHECK(!search_committed_); |
526 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 508 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
527 content::NotificationService::AllBrowserContextsAndSources()); | 509 content::NotificationService::AllBrowserContextsAndSources()); |
528 registrar_.Remove(this, chrome::NOTIFICATION_INSTANT_COMMITTED, | 510 registrar_.Remove(this, chrome::NOTIFICATION_INSTANT_COMMITTED, |
529 content::NotificationService::AllBrowserContextsAndSources()); | 511 content::NotificationService::AllBrowserContextsAndSources()); |
530 } | 512 } |
531 } | 513 } |
OLD | NEW |