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/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "chrome/browser/google/google_url_tracker_map_entry.h" | 16 #include "chrome/browser/google/google_url_tracker_map_entry.h" |
17 #include "components/keyed_service/core/keyed_service.h" | 17 #include "components/keyed_service/core/keyed_service.h" |
18 #include "net/base/network_change_notifier.h" | 18 #include "net/base/network_change_notifier.h" |
19 #include "net/url_request/url_fetcher.h" | 19 #include "net/url_request/url_fetcher.h" |
20 #include "net/url_request/url_fetcher_delegate.h" | 20 #include "net/url_request/url_fetcher_delegate.h" |
21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
22 | 22 |
23 class GoogleURLTrackerClient; | 23 class GoogleURLTrackerClient; |
24 class GoogleURLTrackerNavigationHelper; | 24 class GoogleURLTrackerNavigationHelper; |
25 class PrefService; | 25 class PrefService; |
26 class Profile; | 26 class Profile; |
27 | 27 |
28 namespace content { | |
29 class NavigationController; | |
30 } | |
31 | |
32 namespace infobars { | 28 namespace infobars { |
33 class InfoBar; | 29 class InfoBar; |
34 } | 30 } |
35 | 31 |
36 // This object is responsible for checking the Google URL once per network | 32 // This object is responsible for checking the Google URL once per network |
37 // change, and if necessary prompting the user to see if they want to change to | 33 // change, and if necessary prompting the user to see if they want to change to |
38 // using it. The current and last prompted values are saved to prefs. | 34 // using it. The current and last prompted values are saved to prefs. |
39 // | 35 // |
40 // Most consumers should only call GoogleURL(), which is guaranteed to | 36 // Most consumers should only call GoogleURL(), which is guaranteed to |
41 // synchronously return a value at all times (even during startup or in unittest | 37 // synchronously return a value at all times (even during startup or in unittest |
(...skipping 16 matching lines...) Expand all Loading... | |
58 enum Mode { | 54 enum Mode { |
59 NORMAL_MODE, | 55 NORMAL_MODE, |
60 UNIT_TEST_MODE, | 56 UNIT_TEST_MODE, |
61 }; | 57 }; |
62 | 58 |
63 // Only the GoogleURLTrackerFactory and tests should call this. No code other | 59 // Only the GoogleURLTrackerFactory and tests should call this. No code other |
64 // than the GoogleURLTracker itself should actually use | 60 // than the GoogleURLTracker itself should actually use |
65 // GoogleURLTrackerFactory::GetForProfile(). | 61 // GoogleURLTrackerFactory::GetForProfile(). |
66 GoogleURLTracker(Profile* profile, | 62 GoogleURLTracker(Profile* profile, |
67 scoped_ptr<GoogleURLTrackerClient> client, | 63 scoped_ptr<GoogleURLTrackerClient> client, |
68 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, | |
69 Mode mode); | 64 Mode mode); |
70 | 65 |
71 virtual ~GoogleURLTracker(); | 66 virtual ~GoogleURLTracker(); |
72 | 67 |
73 // Returns the current Google URL. This will return a valid URL even if | 68 // Returns the current Google URL. This will return a valid URL even if |
74 // |profile| is NULL or a testing profile. | 69 // |profile| is NULL or a testing profile. |
75 // | 70 // |
76 // This is the only function most code should ever call. | 71 // This is the only function most code should ever call. |
77 static GURL GoogleURL(Profile* profile); | 72 static GURL GoogleURL(Profile* profile); |
78 | 73 |
(...skipping 20 matching lines...) Expand all Loading... | |
99 void AcceptGoogleURL(bool redo_searches); | 94 void AcceptGoogleURL(bool redo_searches); |
100 void CancelGoogleURL(); | 95 void CancelGoogleURL(); |
101 const GURL& google_url() const { return google_url_; } | 96 const GURL& google_url() const { return google_url_; } |
102 const GURL& fetched_google_url() const { return fetched_google_url_; } | 97 const GURL& fetched_google_url() const { return fetched_google_url_; } |
103 | 98 |
104 // No one but GoogleURLTrackerMapEntry should call this. | 99 // No one but GoogleURLTrackerMapEntry should call this. |
105 void DeleteMapEntryForService(const InfoBarService* infobar_service); | 100 void DeleteMapEntryForService(const InfoBarService* infobar_service); |
106 | 101 |
107 // Called by the client after SearchCommitted() registers listeners, to | 102 // Called by the client after SearchCommitted() registers listeners, to |
108 // indicate that we've received the "load now pending" notification. | 103 // indicate that we've received the "load now pending" notification. |
109 // |navigation_controller| is the NavigationController for this load; | 104 // |nav_helper| is the GoogleURLTrackerNavigationHelper for this load; |
110 // |infobar_service| is the InfoBarService of the associated tab; and | 105 // |infobar_service| is the InfoBarService of the associated tab; and |
111 // |pending_id| is the unique ID of the newly pending NavigationEntry. If | 106 // |pending_id| is the unique ID of the newly pending NavigationEntry. If |
112 // there is already a visible GoogleURLTracker infobar for this tab, this | 107 // there is already a visible GoogleURLTracker infobar for this tab, this |
113 // function resets its associated pending entry ID to the new ID. Otherwise | 108 // function resets its associated pending entry ID to the new ID. Otherwise |
114 // this function creates a map entry for the associated tab. | 109 // this function creates a map entry for the associated tab. |
115 virtual void OnNavigationPending( | 110 virtual void OnNavigationPending(GoogleURLTrackerNavigationHelper* nav_helper, |
116 content::NavigationController* navigation_controller, | 111 InfoBarService* infobar_service, |
117 InfoBarService* infobar_service, | 112 int pending_id); |
118 int pending_id); | |
119 | 113 |
120 // Called by the navigation observer once a load we're watching commits. | 114 // Called by the navigation observer once a load we're watching commits. |
121 // |infobar_service| is the same as for OnNavigationPending(); | 115 // |infobar_service| is the same as for OnNavigationPending(); |
122 // |search_url| is guaranteed to be valid. | 116 // |search_url| is guaranteed to be valid. |
123 virtual void OnNavigationCommitted(InfoBarService* infobar_service, | 117 virtual void OnNavigationCommitted(InfoBarService* infobar_service, |
124 const GURL& search_url); | 118 const GURL& search_url); |
125 | 119 |
126 // Called by the navigation observer when a tab closes. | 120 // Called by the navigation observer when a tab closes. |
127 virtual void OnTabClosed( | 121 virtual void OnTabClosed(GoogleURLTrackerNavigationHelper* nav_helper); |
128 content::NavigationController* navigation_controller); | |
129 | 122 |
130 static const char kDefaultGoogleHomepage[]; | 123 static const char kDefaultGoogleHomepage[]; |
131 static const char kSearchDomainCheckURL[]; | 124 static const char kSearchDomainCheckURL[]; |
132 | 125 |
133 private: | 126 private: |
134 friend class GoogleURLTrackerTest; | 127 friend class GoogleURLTrackerTest; |
135 | 128 |
136 typedef std::map<const InfoBarService*, GoogleURLTrackerMapEntry*> EntryMap; | 129 typedef std::map<const InfoBarService*, GoogleURLTrackerMapEntry*> EntryMap; |
137 | 130 |
138 // net::URLFetcherDelegate: | 131 // net::URLFetcherDelegate: |
(...skipping 28 matching lines...) Expand all Loading... | |
167 // Google TLD. | 160 // Google TLD. |
168 void CloseAllEntries(bool redo_searches); | 161 void CloseAllEntries(bool redo_searches); |
169 | 162 |
170 // Unregisters any listeners for the navigation controller in |map_entry|. | 163 // Unregisters any listeners for the navigation controller in |map_entry|. |
171 // This sanity-DCHECKs that these are registered (or not) in the specific | 164 // This sanity-DCHECKs that these are registered (or not) in the specific |
172 // cases we expect. (|must_be_listening_for_commit| is used purely for this | 165 // cases we expect. (|must_be_listening_for_commit| is used purely for this |
173 // sanity-checking.) This also unregisters the global navigation pending | 166 // sanity-checking.) This also unregisters the global navigation pending |
174 // listener if there are no remaining listeners for navigation commits, as we | 167 // listener if there are no remaining listeners for navigation commits, as we |
175 // no longer need them until another search is committed. | 168 // no longer need them until another search is committed. |
176 void UnregisterForEntrySpecificNotifications( | 169 void UnregisterForEntrySpecificNotifications( |
177 const GoogleURLTrackerMapEntry& map_entry, | 170 GoogleURLTrackerMapEntry& map_entry, |
blundell
2014/05/15 15:24:14
The reason for the removal of const several places
Peter Kasting
2014/05/15 21:29:52
OK, but then you need to pass these objects as poi
blundell
2014/05/16 11:54:18
Done.
| |
178 bool must_be_listening_for_commit); | 171 bool must_be_listening_for_commit); |
179 | 172 |
180 Profile* profile_; | 173 Profile* profile_; |
181 | 174 |
182 scoped_ptr<GoogleURLTrackerClient> client_; | 175 scoped_ptr<GoogleURLTrackerClient> client_; |
183 | 176 |
184 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper_; | |
185 | |
186 // Creates an infobar and adds it to the provided InfoBarService. Returns the | 177 // Creates an infobar and adds it to the provided InfoBarService. Returns the |
187 // infobar on success or NULL on failure. The caller does not own the | 178 // infobar on success or NULL on failure. The caller does not own the |
188 // returned object, the InfoBarService does. | 179 // returned object, the InfoBarService does. |
189 base::Callback< | 180 base::Callback< |
190 infobars::InfoBar*(InfoBarService*, GoogleURLTracker*, const GURL&)> | 181 infobars::InfoBar*(InfoBarService*, GoogleURLTracker*, const GURL&)> |
191 infobar_creator_; | 182 infobar_creator_; |
192 | 183 |
193 GURL google_url_; | 184 GURL google_url_; |
194 GURL fetched_google_url_; | 185 GURL fetched_google_url_; |
195 scoped_ptr<net::URLFetcher> fetcher_; | 186 scoped_ptr<net::URLFetcher> fetcher_; |
(...skipping 12 matching lines...) Expand all Loading... | |
208 // nor the last prompted Google URL. | 199 // nor the last prompted Google URL. |
209 bool search_committed_; // True when we're expecting a notification of a new | 200 bool search_committed_; // True when we're expecting a notification of a new |
210 // pending search navigation. | 201 // pending search navigation. |
211 EntryMap entry_map_; | 202 EntryMap entry_map_; |
212 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; | 203 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; |
213 | 204 |
214 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); | 205 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); |
215 }; | 206 }; |
216 | 207 |
217 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ | 208 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ |
OLD | NEW |