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

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: Response to review 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/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
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
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 associated with this
110 // |infobar_service| is the InfoBarService of the associated tab; and 105 // navigation; |infobar_service| is the InfoBarService of the associated tab;
111 // |pending_id| is the unique ID of the newly pending NavigationEntry. If 106 // and |pending_id| is the unique ID of the newly pending NavigationEntry.
112 // there is already a visible GoogleURLTracker infobar for this tab, this 107 // If 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(
116 content::NavigationController* navigation_controller, 111 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper,
117 InfoBarService* infobar_service, 112 InfoBarService* infobar_service,
118 int pending_id); 113 int pending_id);
119 114
120 // Called by the navigation observer once a load we're watching commits. 115 // Called by the navigation observer once a load we're watching commits.
121 // |infobar_service| is the same as for OnNavigationPending(); 116 // |infobar_service| is the same as for OnNavigationPending();
122 // |search_url| is guaranteed to be valid. 117 // |search_url| is guaranteed to be valid.
123 virtual void OnNavigationCommitted(InfoBarService* infobar_service, 118 virtual void OnNavigationCommitted(InfoBarService* infobar_service,
124 const GURL& search_url); 119 const GURL& search_url);
125 120
126 // Called by the navigation observer when a tab closes. 121 // Called by the navigation observer when a tab closes.
127 virtual void OnTabClosed( 122 virtual void OnTabClosed(GoogleURLTrackerNavigationHelper* nav_helper);
128 content::NavigationController* navigation_controller);
129 123
130 static const char kDefaultGoogleHomepage[]; 124 static const char kDefaultGoogleHomepage[];
131 static const char kSearchDomainCheckURL[]; 125 static const char kSearchDomainCheckURL[];
132 126
133 private: 127 private:
134 friend class GoogleURLTrackerTest; 128 friend class GoogleURLTrackerTest;
135 129
136 typedef std::map<const InfoBarService*, GoogleURLTrackerMapEntry*> EntryMap; 130 typedef std::map<const InfoBarService*, GoogleURLTrackerMapEntry*> EntryMap;
137 131
138 // net::URLFetcherDelegate: 132 // net::URLFetcherDelegate:
(...skipping 21 matching lines...) Expand all
160 // Called each time the user performs a search. This checks whether we need 154 // Called each time the user performs a search. This checks whether we need
161 // to prompt the user about a domain change, and if so, starts listening for 155 // to prompt the user about a domain change, and if so, starts listening for
162 // the notifications sent when the actual load is triggered. 156 // the notifications sent when the actual load is triggered.
163 void SearchCommitted(); 157 void SearchCommitted();
164 158
165 // Closes all map entries. If |redo_searches| is true, this also triggers 159 // Closes all map entries. If |redo_searches| is true, this also triggers
166 // each tab with an infobar to re-perform the user's search, but on the new 160 // each tab with an infobar to re-perform the user's search, but on the new
167 // Google TLD. 161 // Google TLD.
168 void CloseAllEntries(bool redo_searches); 162 void CloseAllEntries(bool redo_searches);
169 163
170 // Unregisters any listeners for the navigation controller in |map_entry|. 164 // Unregisters any listeners for the navigation helper in |map_entry|.
171 // This sanity-DCHECKs that these are registered (or not) in the specific 165 // 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 166 // cases we expect. (|must_be_listening_for_commit| is used purely for this
173 // sanity-checking.) This also unregisters the global navigation pending 167 // sanity-checking.) This also unregisters the global navigation pending
174 // listener if there are no remaining listeners for navigation commits, as we 168 // listener if there are no remaining listeners for navigation commits, as we
175 // no longer need them until another search is committed. 169 // no longer need them until another search is committed.
176 void UnregisterForEntrySpecificNotifications( 170 void UnregisterForEntrySpecificNotifications(
177 const GoogleURLTrackerMapEntry& map_entry, 171 GoogleURLTrackerMapEntry* map_entry,
178 bool must_be_listening_for_commit); 172 bool must_be_listening_for_commit);
179 173
180 Profile* profile_; 174 Profile* profile_;
181 175
182 scoped_ptr<GoogleURLTrackerClient> client_; 176 scoped_ptr<GoogleURLTrackerClient> client_;
183 177
184 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper_;
185
186 // Creates an infobar and adds it to the provided InfoBarService. Returns the 178 // 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 179 // infobar on success or NULL on failure. The caller does not own the
188 // returned object, the InfoBarService does. 180 // returned object, the InfoBarService does.
189 base::Callback< 181 base::Callback<
190 infobars::InfoBar*(InfoBarService*, GoogleURLTracker*, const GURL&)> 182 infobars::InfoBar*(InfoBarService*, GoogleURLTracker*, const GURL&)>
191 infobar_creator_; 183 infobar_creator_;
192 184
193 GURL google_url_; 185 GURL google_url_;
194 GURL fetched_google_url_; 186 GURL fetched_google_url_;
195 scoped_ptr<net::URLFetcher> fetcher_; 187 scoped_ptr<net::URLFetcher> fetcher_;
(...skipping 12 matching lines...) Expand all
208 // nor the last prompted Google URL. 200 // nor the last prompted Google URL.
209 bool search_committed_; // True when we're expecting a notification of a new 201 bool search_committed_; // True when we're expecting a notification of a new
210 // pending search navigation. 202 // pending search navigation.
211 EntryMap entry_map_; 203 EntryMap entry_map_;
212 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; 204 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_;
213 205
214 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); 206 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker);
215 }; 207 };
216 208
217 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ 209 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698