Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1332)

Side by Side Diff: chrome/browser/google/google_url_tracker.h

Issue 283413002: Turn GoogleURLTrackerNavigationHelper(Impl) into a per-tab object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Unittest fix Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/callback_list.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "chrome/browser/google/google_url_tracker_map_entry.h" 17 #include "chrome/browser/google/google_url_tracker_map_entry.h"
18 #include "components/keyed_service/core/keyed_service.h" 18 #include "components/keyed_service/core/keyed_service.h"
19 #include "net/base/network_change_notifier.h" 19 #include "net/base/network_change_notifier.h"
20 #include "net/url_request/url_fetcher.h" 20 #include "net/url_request/url_fetcher.h"
21 #include "net/url_request/url_fetcher_delegate.h" 21 #include "net/url_request/url_fetcher_delegate.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 class GoogleURLTrackerClient; 24 class GoogleURLTrackerClient;
25 class GoogleURLTrackerNavigationHelper; 25 class GoogleURLTrackerNavigationHelper;
26 class PrefService; 26 class PrefService;
27 class Profile; 27 class Profile;
28 28
29 namespace content {
30 class NavigationController;
31 }
32
33 namespace infobars { 29 namespace infobars {
34 class InfoBar; 30 class InfoBar;
35 } 31 }
36 32
37 // This object is responsible for checking the Google URL once per network 33 // This object is responsible for checking the Google URL once per network
38 // change, and if necessary prompting the user to see if they want to change to 34 // change, and if necessary prompting the user to see if they want to change to
39 // using it. The current and last prompted values are saved to prefs. 35 // using it. The current and last prompted values are saved to prefs.
40 // 36 //
41 // Most consumers should only call GoogleURL(), which is guaranteed to 37 // Most consumers should only call GoogleURL(), which is guaranteed to
42 // synchronously return a value at all times (even during startup or in unittest 38 // synchronously return a value at all times (even during startup or in unittest
(...skipping 22 matching lines...) Expand all
65 }; 61 };
66 62
67 static const char kDefaultGoogleHomepage[]; 63 static const char kDefaultGoogleHomepage[];
68 static const char kSearchDomainCheckURL[]; 64 static const char kSearchDomainCheckURL[];
69 65
70 // Only the GoogleURLTrackerFactory and tests should call this. No code other 66 // Only the GoogleURLTrackerFactory and tests should call this. No code other
71 // than the GoogleURLTracker itself should actually use 67 // than the GoogleURLTracker itself should actually use
72 // GoogleURLTrackerFactory::GetForProfile(). 68 // GoogleURLTrackerFactory::GetForProfile().
73 GoogleURLTracker(Profile* profile, 69 GoogleURLTracker(Profile* profile,
74 scoped_ptr<GoogleURLTrackerClient> client, 70 scoped_ptr<GoogleURLTrackerClient> client,
75 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper,
76 Mode mode); 71 Mode mode);
77 72
78 virtual ~GoogleURLTracker(); 73 virtual ~GoogleURLTracker();
79 74
80 // Returns the current Google URL. This will return a valid URL even if 75 // Returns the current Google URL. This will return a valid URL even if
81 // |profile| is NULL or a testing profile. 76 // |profile| is NULL or a testing profile.
82 // 77 //
83 // This is the only function most code should ever call. 78 // This is the only function most code should ever call.
84 static GURL GoogleURL(Profile* profile); 79 static GURL GoogleURL(Profile* profile);
85 80
(...skipping 20 matching lines...) Expand all
106 void AcceptGoogleURL(bool redo_searches); 101 void AcceptGoogleURL(bool redo_searches);
107 void CancelGoogleURL(); 102 void CancelGoogleURL();
108 const GURL& google_url() const { return google_url_; } 103 const GURL& google_url() const { return google_url_; }
109 const GURL& fetched_google_url() const { return fetched_google_url_; } 104 const GURL& fetched_google_url() const { return fetched_google_url_; }
110 105
111 // No one but GoogleURLTrackerMapEntry should call this. 106 // No one but GoogleURLTrackerMapEntry should call this.
112 void DeleteMapEntryForService(const InfoBarService* infobar_service); 107 void DeleteMapEntryForService(const InfoBarService* infobar_service);
113 108
114 // Called by the client after SearchCommitted() registers listeners, to 109 // Called by the client after SearchCommitted() registers listeners, to
115 // indicate that we've received the "load now pending" notification. 110 // indicate that we've received the "load now pending" notification.
116 // |navigation_controller| is the NavigationController for this load; 111 // |nav_helper| is the GoogleURLTrackerNavigationHelper associated with this
117 // |infobar_service| is the InfoBarService of the associated tab; and 112 // navigation; |infobar_service| is the InfoBarService of the associated tab;
118 // |pending_id| is the unique ID of the newly pending NavigationEntry. If 113 // and |pending_id| is the unique ID of the newly pending NavigationEntry.
119 // there is already a visible GoogleURLTracker infobar for this tab, this 114 // If there is already a visible GoogleURLTracker infobar for this tab, this
120 // function resets its associated pending entry ID to the new ID. Otherwise 115 // function resets its associated pending entry ID to the new ID. Otherwise
121 // this function creates a map entry for the associated tab. 116 // this function creates a map entry for the associated tab.
122 virtual void OnNavigationPending( 117 virtual void OnNavigationPending(
123 content::NavigationController* navigation_controller, 118 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper,
124 InfoBarService* infobar_service, 119 InfoBarService* infobar_service,
125 int pending_id); 120 int pending_id);
126 121
127 // Called by the navigation observer once a load we're watching commits. 122 // Called by the navigation observer once a load we're watching commits.
128 // |infobar_service| is the same as for OnNavigationPending(); 123 // |infobar_service| is the same as for OnNavigationPending();
129 // |search_url| is guaranteed to be valid. 124 // |search_url| is guaranteed to be valid.
130 virtual void OnNavigationCommitted(InfoBarService* infobar_service, 125 virtual void OnNavigationCommitted(InfoBarService* infobar_service,
131 const GURL& search_url); 126 const GURL& search_url);
132 127
133 // Called by the navigation observer when a tab closes. 128 // Called by the navigation observer when a tab closes.
134 virtual void OnTabClosed( 129 virtual void OnTabClosed(GoogleURLTrackerNavigationHelper* nav_helper);
135 content::NavigationController* navigation_controller);
136 130
137 scoped_ptr<Subscription> RegisterCallback( 131 scoped_ptr<Subscription> RegisterCallback(
138 const OnGoogleURLUpdatedCallback& cb); 132 const OnGoogleURLUpdatedCallback& cb);
139 133
140 private: 134 private:
141 friend class GoogleURLTrackerTest; 135 friend class GoogleURLTrackerTest;
142 136
143 typedef std::map<const InfoBarService*, GoogleURLTrackerMapEntry*> EntryMap; 137 typedef std::map<const InfoBarService*, GoogleURLTrackerMapEntry*> EntryMap;
144 138
145 // net::URLFetcherDelegate: 139 // net::URLFetcherDelegate:
(...skipping 21 matching lines...) Expand all
167 // Called each time the user performs a search. This checks whether we need 161 // Called each time the user performs a search. This checks whether we need
168 // to prompt the user about a domain change, and if so, starts listening for 162 // to prompt the user about a domain change, and if so, starts listening for
169 // the notifications sent when the actual load is triggered. 163 // the notifications sent when the actual load is triggered.
170 void SearchCommitted(); 164 void SearchCommitted();
171 165
172 // Closes all map entries. If |redo_searches| is true, this also triggers 166 // Closes all map entries. If |redo_searches| is true, this also triggers
173 // each tab with an infobar to re-perform the user's search, but on the new 167 // each tab with an infobar to re-perform the user's search, but on the new
174 // Google TLD. 168 // Google TLD.
175 void CloseAllEntries(bool redo_searches); 169 void CloseAllEntries(bool redo_searches);
176 170
177 // Unregisters any listeners for the navigation controller in |map_entry|. 171 // Unregisters any listeners for the navigation helper in |map_entry|.
178 // This sanity-DCHECKs that these are registered (or not) in the specific 172 // This sanity-DCHECKs that these are registered (or not) in the specific
179 // cases we expect. (|must_be_listening_for_commit| is used purely for this 173 // cases we expect. (|must_be_listening_for_commit| is used purely for this
180 // sanity-checking.) This also unregisters the global navigation pending 174 // sanity-checking.) This also unregisters the global navigation pending
181 // listener if there are no remaining listeners for navigation commits, as we 175 // listener if there are no remaining listeners for navigation commits, as we
182 // no longer need them until another search is committed. 176 // no longer need them until another search is committed.
183 void UnregisterForEntrySpecificNotifications( 177 void UnregisterForEntrySpecificNotifications(
184 const GoogleURLTrackerMapEntry& map_entry, 178 GoogleURLTrackerMapEntry* map_entry,
185 bool must_be_listening_for_commit); 179 bool must_be_listening_for_commit);
186 180
187 void NotifyGoogleURLUpdated(GURL old_url, GURL new_url); 181 void NotifyGoogleURLUpdated(GURL old_url, GURL new_url);
188 182
189 CallbackList callback_list_; 183 CallbackList callback_list_;
190 184
191 Profile* profile_; 185 Profile* profile_;
192 186
193 scoped_ptr<GoogleURLTrackerClient> client_; 187 scoped_ptr<GoogleURLTrackerClient> client_;
194 188
195 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper_;
196
197 // Creates an infobar and adds it to the provided InfoBarService. Returns the 189 // Creates an infobar and adds it to the provided InfoBarService. Returns the
198 // infobar on success or NULL on failure. The caller does not own the 190 // infobar on success or NULL on failure. The caller does not own the
199 // returned object, the InfoBarService does. 191 // returned object, the InfoBarService does.
200 base::Callback< 192 base::Callback<
201 infobars::InfoBar*(InfoBarService*, GoogleURLTracker*, const GURL&)> 193 infobars::InfoBar*(InfoBarService*, GoogleURLTracker*, const GURL&)>
202 infobar_creator_; 194 infobar_creator_;
203 195
204 GURL google_url_; 196 GURL google_url_;
205 GURL fetched_google_url_; 197 GURL fetched_google_url_;
206 scoped_ptr<net::URLFetcher> fetcher_; 198 scoped_ptr<net::URLFetcher> fetcher_;
(...skipping 12 matching lines...) Expand all
219 // nor the last prompted Google URL. 211 // nor the last prompted Google URL.
220 bool search_committed_; // True when we're expecting a notification of a new 212 bool search_committed_; // True when we're expecting a notification of a new
221 // pending search navigation. 213 // pending search navigation.
222 EntryMap entry_map_; 214 EntryMap entry_map_;
223 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; 215 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_;
224 216
225 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); 217 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker);
226 }; 218 };
227 219
228 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ 220 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698