Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ |
| 6 #define CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ | 6 #define CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 13 #include "base/callback_list.h" | |
| 13 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #include "chrome/browser/google/google_url_tracker_map_entry.h" | 17 #include "chrome/browser/google/google_url_tracker_map_entry.h" |
| 17 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
| 18 #include "net/base/network_change_notifier.h" | 19 #include "net/base/network_change_notifier.h" |
| 19 #include "net/url_request/url_fetcher.h" | 20 #include "net/url_request/url_fetcher.h" |
| 20 #include "net/url_request/url_fetcher_delegate.h" | 21 #include "net/url_request/url_fetcher_delegate.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 42 // the notification service for NOTIFICATION_GOOGLE_URL_UPDATED, which provides | 43 // the notification service for NOTIFICATION_GOOGLE_URL_UPDATED, which provides |
| 43 // the original and updated values. | 44 // the original and updated values. |
| 44 // | 45 // |
| 45 // To protect users' privacy and reduce server load, no updates will be | 46 // To protect users' privacy and reduce server load, no updates will be |
| 46 // performed (ever) unless at least one consumer registers interest by calling | 47 // performed (ever) unless at least one consumer registers interest by calling |
| 47 // RequestServerCheck(). | 48 // RequestServerCheck(). |
| 48 class GoogleURLTracker : public net::URLFetcherDelegate, | 49 class GoogleURLTracker : public net::URLFetcherDelegate, |
| 49 public net::NetworkChangeNotifier::IPAddressObserver, | 50 public net::NetworkChangeNotifier::IPAddressObserver, |
| 50 public KeyedService { | 51 public KeyedService { |
| 51 public: | 52 public: |
| 53 // Callback that is called when the Google URL is updated. The arguments are | |
| 54 // the old and new URLs. | |
| 55 typedef base::Callback<void(GURL, GURL)> OnGoogleURLUpdatedCallback; | |
| 56 | |
| 52 // The contents of the Details for a NOTIFICATION_GOOGLE_URL_UPDATED. | 57 // The contents of the Details for a NOTIFICATION_GOOGLE_URL_UPDATED. |
| 53 typedef std::pair<GURL, GURL> UpdatedDetails; | 58 typedef std::pair<GURL, GURL> UpdatedDetails; |
| 54 | 59 |
| 55 // The constructor does different things depending on which of these values | 60 // The constructor does different things depending on which of these values |
| 56 // you pass it. Hopefully these are self-explanatory. | 61 // you pass it. Hopefully these are self-explanatory. |
| 57 enum Mode { | 62 enum Mode { |
| 58 NORMAL_MODE, | 63 NORMAL_MODE, |
| 59 UNIT_TEST_MODE, | 64 UNIT_TEST_MODE, |
| 60 }; | 65 }; |
| 61 | 66 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 // Called by the navigation observer once a load we're watching commits. | 123 // Called by the navigation observer once a load we're watching commits. |
| 119 // |infobar_service| is the same as for OnNavigationPending(); | 124 // |infobar_service| is the same as for OnNavigationPending(); |
| 120 // |search_url| is guaranteed to be valid. | 125 // |search_url| is guaranteed to be valid. |
| 121 virtual void OnNavigationCommitted(InfoBarService* infobar_service, | 126 virtual void OnNavigationCommitted(InfoBarService* infobar_service, |
| 122 const GURL& search_url); | 127 const GURL& search_url); |
| 123 | 128 |
| 124 // Called by the navigation observer when a tab closes. | 129 // Called by the navigation observer when a tab closes. |
| 125 virtual void OnTabClosed( | 130 virtual void OnTabClosed( |
| 126 content::NavigationController* navigation_controller); | 131 content::NavigationController* navigation_controller); |
| 127 | 132 |
| 133 scoped_ptr<base::CallbackList<void(GURL, GURL)>::Subscription> | |
| 134 RegisterCallback(const OnGoogleURLUpdatedCallback& cb) { | |
| 135 return callback_list_.Add(cb); | |
|
Peter Kasting
2014/05/15 21:12:52
Add() is not a cheap accessor (based on its name),
blundell
2014/05/16 09:09:55
Done.
| |
| 136 } | |
| 137 | |
| 128 static const char kDefaultGoogleHomepage[]; | 138 static const char kDefaultGoogleHomepage[]; |
| 129 static const char kSearchDomainCheckURL[]; | 139 static const char kSearchDomainCheckURL[]; |
| 130 | 140 |
| 131 private: | 141 private: |
| 132 friend class GoogleURLTrackerTest; | 142 friend class GoogleURLTrackerTest; |
| 133 | 143 |
| 134 typedef std::map<const InfoBarService*, GoogleURLTrackerMapEntry*> EntryMap; | 144 typedef std::map<const InfoBarService*, GoogleURLTrackerMapEntry*> EntryMap; |
| 135 | 145 |
| 136 // net::URLFetcherDelegate: | 146 // net::URLFetcherDelegate: |
| 137 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 147 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 168 // Unregisters any listeners for the navigation controller in |map_entry|. | 178 // Unregisters any listeners for the navigation controller in |map_entry|. |
| 169 // This sanity-DCHECKs that these are registered (or not) in the specific | 179 // This sanity-DCHECKs that these are registered (or not) in the specific |
| 170 // cases we expect. (|must_be_listening_for_commit| is used purely for this | 180 // cases we expect. (|must_be_listening_for_commit| is used purely for this |
| 171 // sanity-checking.) This also unregisters the global navigation pending | 181 // sanity-checking.) This also unregisters the global navigation pending |
| 172 // listener if there are no remaining listeners for navigation commits, as we | 182 // listener if there are no remaining listeners for navigation commits, as we |
| 173 // no longer need them until another search is committed. | 183 // no longer need them until another search is committed. |
| 174 void UnregisterForEntrySpecificNotifications( | 184 void UnregisterForEntrySpecificNotifications( |
| 175 const GoogleURLTrackerMapEntry& map_entry, | 185 const GoogleURLTrackerMapEntry& map_entry, |
| 176 bool must_be_listening_for_commit); | 186 bool must_be_listening_for_commit); |
| 177 | 187 |
| 188 void NotifyGoogleURLUpdated(GURL old_url, GURL new_url) { | |
| 189 callback_list_.Notify(old_url, new_url); | |
|
Peter Kasting
2014/05/15 21:12:52
Again, define this out-of-line.
blundell
2014/05/16 09:09:55
Done.
| |
| 190 } | |
| 191 | |
| 192 base::CallbackList<void(GURL, GURL)> callback_list_; | |
|
Peter Kasting
2014/05/15 21:12:52
Nit: Consider a typedef for this type and/or base:
blundell
2014/05/16 09:09:55
Done.
| |
| 193 | |
| 178 Profile* profile_; | 194 Profile* profile_; |
| 179 | 195 |
| 180 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper_; | 196 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper_; |
| 181 | 197 |
| 182 // Creates an infobar and adds it to the provided InfoBarService. Returns the | 198 // Creates an infobar and adds it to the provided InfoBarService. Returns the |
| 183 // infobar on success or NULL on failure. The caller does not own the | 199 // infobar on success or NULL on failure. The caller does not own the |
| 184 // returned object, the InfoBarService does. | 200 // returned object, the InfoBarService does. |
| 185 base::Callback< | 201 base::Callback< |
| 186 infobars::InfoBar*(InfoBarService*, GoogleURLTracker*, const GURL&)> | 202 infobars::InfoBar*(InfoBarService*, GoogleURLTracker*, const GURL&)> |
| 187 infobar_creator_; | 203 infobar_creator_; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 204 // nor the last prompted Google URL. | 220 // nor the last prompted Google URL. |
| 205 bool search_committed_; // True when we're expecting a notification of a new | 221 bool search_committed_; // True when we're expecting a notification of a new |
| 206 // pending search navigation. | 222 // pending search navigation. |
| 207 EntryMap entry_map_; | 223 EntryMap entry_map_; |
| 208 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; | 224 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; |
| 209 | 225 |
| 210 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); | 226 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); |
| 211 }; | 227 }; |
| 212 | 228 |
| 213 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ | 229 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ |
| OLD | NEW |