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

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

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

Powered by Google App Engine
This is Rietveld 408576698