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 typedef base::CallbackList<void(GURL, GURL)> CallbackList; | |
57 typedef CallbackList::Subscription Subscription; | |
58 | |
52 // The contents of the Details for a NOTIFICATION_GOOGLE_URL_UPDATED. | 59 // The contents of the Details for a NOTIFICATION_GOOGLE_URL_UPDATED. |
53 typedef std::pair<GURL, GURL> UpdatedDetails; | 60 typedef std::pair<GURL, GURL> UpdatedDetails; |
54 | 61 |
55 // The constructor does different things depending on which of these values | 62 // The constructor does different things depending on which of these values |
56 // you pass it. Hopefully these are self-explanatory. | 63 // you pass it. Hopefully these are self-explanatory. |
57 enum Mode { | 64 enum Mode { |
58 NORMAL_MODE, | 65 NORMAL_MODE, |
59 UNIT_TEST_MODE, | 66 UNIT_TEST_MODE, |
60 }; | 67 }; |
61 | 68 |
(...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. | 125 // Called by the navigation observer once a load we're watching commits. |
119 // |infobar_service| is the same as for OnNavigationPending(); | 126 // |infobar_service| is the same as for OnNavigationPending(); |
120 // |search_url| is guaranteed to be valid. | 127 // |search_url| is guaranteed to be valid. |
121 virtual void OnNavigationCommitted(InfoBarService* infobar_service, | 128 virtual void OnNavigationCommitted(InfoBarService* infobar_service, |
122 const GURL& search_url); | 129 const GURL& search_url); |
123 | 130 |
124 // Called by the navigation observer when a tab closes. | 131 // Called by the navigation observer when a tab closes. |
125 virtual void OnTabClosed( | 132 virtual void OnTabClosed( |
126 content::NavigationController* navigation_controller); | 133 content::NavigationController* navigation_controller); |
127 | 134 |
135 scoped_ptr<Subscription> RegisterCallback( | |
136 const OnGoogleURLUpdatedCallback& cb); | |
137 | |
128 static const char kDefaultGoogleHomepage[]; | 138 static const char kDefaultGoogleHomepage[]; |
Peter Kasting
2014/05/16 22:24:23
Nit: While here: Google style guide says static co
blundell
2014/05/17 11:32:53
Done.
| |
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; |
138 | 148 |
(...skipping 29 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 | |
190 CallbackList callback_list_; | |
191 | |
178 Profile* profile_; | 192 Profile* profile_; |
179 | 193 |
180 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper_; | 194 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper_; |
181 | 195 |
182 // Creates an infobar and adds it to the provided InfoBarService. Returns the | 196 // 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 | 197 // infobar on success or NULL on failure. The caller does not own the |
184 // returned object, the InfoBarService does. | 198 // returned object, the InfoBarService does. |
185 base::Callback< | 199 base::Callback< |
186 infobars::InfoBar*(InfoBarService*, GoogleURLTracker*, const GURL&)> | 200 infobars::InfoBar*(InfoBarService*, GoogleURLTracker*, const GURL&)> |
187 infobar_creator_; | 201 infobar_creator_; |
(...skipping 16 matching lines...) Expand all Loading... | |
204 // nor the last prompted Google URL. | 218 // nor the last prompted Google URL. |
205 bool search_committed_; // True when we're expecting a notification of a new | 219 bool search_committed_; // True when we're expecting a notification of a new |
206 // pending search navigation. | 220 // pending search navigation. |
207 EntryMap entry_map_; | 221 EntryMap entry_map_; |
208 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; | 222 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; |
209 | 223 |
210 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); | 224 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); |
211 }; | 225 }; |
212 | 226 |
213 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ | 227 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ |
OLD | NEW |