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> |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // When |profile| is NULL or a testing profile, this function does nothing. | 90 // When |profile| is NULL or a testing profile, this function does nothing. |
91 static void GoogleURLSearchCommitted(Profile* profile); | 91 static void GoogleURLSearchCommitted(Profile* profile); |
92 | 92 |
93 // No one but GoogleURLTrackerInfoBarDelegate or test code should call these. | 93 // No one but GoogleURLTrackerInfoBarDelegate or test code should call these. |
94 void AcceptGoogleURL(bool redo_searches); | 94 void AcceptGoogleURL(bool redo_searches); |
95 void CancelGoogleURL(); | 95 void CancelGoogleURL(); |
96 const GURL& google_url() const { return google_url_; } | 96 const GURL& google_url() const { return google_url_; } |
97 const GURL& fetched_google_url() const { return fetched_google_url_; } | 97 const GURL& fetched_google_url() const { return fetched_google_url_; } |
98 | 98 |
99 // No one but GoogleURLTrackerMapEntry should call this. | 99 // No one but GoogleURLTrackerMapEntry should call this. |
100 void DeleteMapEntryForService(const InfoBarService* infobar_service); | 100 void DeleteMapEntryForManager( |
| 101 const infobars::InfoBarManager* infobar_manager); |
101 | 102 |
102 // Called by the client after SearchCommitted() registers listeners, to | 103 // Called by the client after SearchCommitted() registers listeners, to |
103 // indicate that we've received the "load now pending" notification. | 104 // indicate that we've received the "load now pending" notification. |
104 // |nav_helper| is the GoogleURLTrackerNavigationHelper associated with this | 105 // |nav_helper| is the GoogleURLTrackerNavigationHelper associated with this |
105 // navigation; |infobar_service| is the InfoBarService of the associated tab; | 106 // navigation; |infobar_manager| is the InfoBarManager of the associated tab; |
106 // and |pending_id| is the unique ID of the newly pending NavigationEntry. | 107 // and |pending_id| is the unique ID of the newly pending NavigationEntry. |
107 // If there is already a visible GoogleURLTracker infobar for this tab, this | 108 // If there is already a visible GoogleURLTracker infobar for this tab, this |
108 // function resets its associated pending entry ID to the new ID. Otherwise | 109 // function resets its associated pending entry ID to the new ID. Otherwise |
109 // this function creates a map entry for the associated tab. | 110 // this function creates a map entry for the associated tab. |
110 virtual void OnNavigationPending( | 111 virtual void OnNavigationPending( |
111 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, | 112 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, |
112 InfoBarService* infobar_service, | 113 infobars::InfoBarManager* infobar_manager, |
113 int pending_id); | 114 int pending_id); |
114 | 115 |
115 // Called by the navigation observer once a load we're watching commits. | 116 // Called by the navigation observer once a load we're watching commits. |
116 // |infobar_service| is the same as for OnNavigationPending(); | 117 // |infobar_manager| is the same as for OnNavigationPending(); |
117 // |search_url| is guaranteed to be valid. | 118 // |search_url| is guaranteed to be valid. |
118 virtual void OnNavigationCommitted(InfoBarService* infobar_service, | 119 virtual void OnNavigationCommitted(infobars::InfoBarManager* infobar_manager, |
119 const GURL& search_url); | 120 const GURL& search_url); |
120 | 121 |
121 // Called by the navigation observer when a tab closes. | 122 // Called by the navigation observer when a tab closes. |
122 virtual void OnTabClosed(GoogleURLTrackerNavigationHelper* nav_helper); | 123 virtual void OnTabClosed(GoogleURLTrackerNavigationHelper* nav_helper); |
123 | 124 |
124 static const char kDefaultGoogleHomepage[]; | 125 static const char kDefaultGoogleHomepage[]; |
125 static const char kSearchDomainCheckURL[]; | 126 static const char kSearchDomainCheckURL[]; |
126 | 127 |
127 private: | 128 private: |
128 friend class GoogleURLTrackerTest; | 129 friend class GoogleURLTrackerTest; |
129 | 130 |
130 typedef std::map<const InfoBarService*, GoogleURLTrackerMapEntry*> EntryMap; | 131 typedef std::map<const infobars::InfoBarManager*, GoogleURLTrackerMapEntry*> |
| 132 EntryMap; |
131 | 133 |
132 // net::URLFetcherDelegate: | 134 // net::URLFetcherDelegate: |
133 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 135 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
134 | 136 |
135 // NetworkChangeNotifier::IPAddressObserver: | 137 // NetworkChangeNotifier::IPAddressObserver: |
136 virtual void OnIPAddressChanged() OVERRIDE; | 138 virtual void OnIPAddressChanged() OVERRIDE; |
137 | 139 |
138 // KeyedService: | 140 // KeyedService: |
139 virtual void Shutdown() OVERRIDE; | 141 virtual void Shutdown() OVERRIDE; |
140 | 142 |
(...skipping 27 matching lines...) Expand all Loading... |
168 // listener if there are no remaining listeners for navigation commits, as we | 170 // listener if there are no remaining listeners for navigation commits, as we |
169 // no longer need them until another search is committed. | 171 // no longer need them until another search is committed. |
170 void UnregisterForEntrySpecificNotifications( | 172 void UnregisterForEntrySpecificNotifications( |
171 GoogleURLTrackerMapEntry* map_entry, | 173 GoogleURLTrackerMapEntry* map_entry, |
172 bool must_be_listening_for_commit); | 174 bool must_be_listening_for_commit); |
173 | 175 |
174 Profile* profile_; | 176 Profile* profile_; |
175 | 177 |
176 scoped_ptr<GoogleURLTrackerClient> client_; | 178 scoped_ptr<GoogleURLTrackerClient> client_; |
177 | 179 |
178 // Creates an infobar and adds it to the provided InfoBarService. Returns the | 180 // Creates an infobar and adds it to the provided InfoBarManager. Returns |
179 // infobar on success or NULL on failure. The caller does not own the | 181 // the infobar on success or NULL on failure. The caller does not own the |
180 // returned object, the InfoBarService does. | 182 // returned object, the InfoBarManager does. |
181 base::Callback< | 183 base::Callback<infobars::InfoBar*(infobars::InfoBarManager*, |
182 infobars::InfoBar*(InfoBarService*, GoogleURLTracker*, const GURL&)> | 184 GoogleURLTracker*, |
183 infobar_creator_; | 185 GoogleURLTrackerNavigationHelper*, |
| 186 const GURL&)> infobar_creator_; |
184 | 187 |
185 GURL google_url_; | 188 GURL google_url_; |
186 GURL fetched_google_url_; | 189 GURL fetched_google_url_; |
187 scoped_ptr<net::URLFetcher> fetcher_; | 190 scoped_ptr<net::URLFetcher> fetcher_; |
188 int fetcher_id_; | 191 int fetcher_id_; |
189 bool in_startup_sleep_; // True if we're in the five-second "no fetching" | 192 bool in_startup_sleep_; // True if we're in the five-second "no fetching" |
190 // period that begins at browser start. | 193 // period that begins at browser start. |
191 bool already_fetched_; // True if we've already fetched a URL once this run; | 194 bool already_fetched_; // True if we've already fetched a URL once this run; |
192 // we won't fetch again until after a restart. | 195 // we won't fetch again until after a restart. |
193 bool need_to_fetch_; // True if a consumer actually wants us to fetch an | 196 bool need_to_fetch_; // True if a consumer actually wants us to fetch an |
194 // updated URL. If this is never set, we won't | 197 // updated URL. If this is never set, we won't |
195 // bother to fetch anything. | 198 // bother to fetch anything. |
196 // Consumers should observe | 199 // Consumers should observe |
197 // chrome::NOTIFICATION_GOOGLE_URL_UPDATED. | 200 // chrome::NOTIFICATION_GOOGLE_URL_UPDATED. |
198 bool need_to_prompt_; // True if the last fetched Google URL is not | 201 bool need_to_prompt_; // True if the last fetched Google URL is not |
199 // matched with current user's default Google URL | 202 // matched with current user's default Google URL |
200 // nor the last prompted Google URL. | 203 // nor the last prompted Google URL. |
201 bool search_committed_; // True when we're expecting a notification of a new | 204 bool search_committed_; // True when we're expecting a notification of a new |
202 // pending search navigation. | 205 // pending search navigation. |
203 EntryMap entry_map_; | 206 EntryMap entry_map_; |
204 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; | 207 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; |
205 | 208 |
206 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); | 209 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); |
207 }; | 210 }; |
208 | 211 |
209 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ | 212 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ |
OLD | NEW |