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 16 matching lines...) Expand all Loading... | |
27 class Profile; | 27 class Profile; |
28 | 28 |
29 namespace infobars { | 29 namespace infobars { |
30 class InfoBar; | 30 class InfoBar; |
31 } | 31 } |
32 | 32 |
33 // 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 |
34 // 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 |
35 // 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. |
36 // | 36 // |
37 // Most consumers should only call GoogleURL(), which is guaranteed to | 37 // Most consumers should only call |
38 // synchronously return a value at all times (even during startup or in unittest | 38 // google_profile_helper::GetGoogleHomePageURL(), which is guaranteed to |
Peter Kasting
2014/05/30 20:50:39
Nit: Maybe "Most consumers should not use this cla
blundell
2014/06/02 15:42:26
Yep, you're right re: the layering violation. Chan
| |
39 // mode). Consumers who need to be notified when things change should register | 39 // synchronously return a value at all times (even during startup or in |
40 // a callback that provides the original and updated values via | 40 // unittest mode). Consumers who need to be notified when things change should |
41 // register a callback that provides the original and updated values via | |
41 // RegisterCallback(). | 42 // RegisterCallback(). |
42 // | 43 // |
43 // To protect users' privacy and reduce server load, no updates will be | 44 // To protect users' privacy and reduce server load, no updates will be |
44 // performed (ever) unless at least one consumer registers interest by calling | 45 // performed (ever) unless at least one consumer registers interest by calling |
45 // RequestServerCheck(). | 46 // RequestServerCheck(). |
46 class GoogleURLTracker : public net::URLFetcherDelegate, | 47 class GoogleURLTracker : public net::URLFetcherDelegate, |
47 public net::NetworkChangeNotifier::IPAddressObserver, | 48 public net::NetworkChangeNotifier::IPAddressObserver, |
48 public KeyedService { | 49 public KeyedService { |
49 public: | 50 public: |
50 // Callback that is called when the Google URL is updated. The arguments are | 51 // Callback that is called when the Google URL is updated. The arguments are |
51 // the old and new URLs. | 52 // the old and new URLs. |
52 typedef base::Callback<void(GURL, GURL)> OnGoogleURLUpdatedCallback; | 53 typedef base::Callback<void(GURL, GURL)> OnGoogleURLUpdatedCallback; |
53 typedef base::CallbackList<void(GURL, GURL)> CallbackList; | 54 typedef base::CallbackList<void(GURL, GURL)> CallbackList; |
54 typedef CallbackList::Subscription Subscription; | 55 typedef CallbackList::Subscription Subscription; |
55 | 56 |
56 // The constructor does different things depending on which of these values | 57 // The constructor does different things depending on which of these values |
57 // you pass it. Hopefully these are self-explanatory. | 58 // you pass it. Hopefully these are self-explanatory. |
58 enum Mode { | 59 enum Mode { |
59 NORMAL_MODE, | 60 NORMAL_MODE, |
60 UNIT_TEST_MODE, | 61 UNIT_TEST_MODE, |
61 }; | 62 }; |
62 | 63 |
63 static const char kDefaultGoogleHomepage[]; | 64 static const char kDefaultGoogleHomepage[]; |
Peter Kasting
2014/05/30 20:50:39
Now that you have DefaultGogoleHomepage(), I think
blundell
2014/06/02 15:42:26
Oops, I hadn't noticed that this was already publi
| |
64 static const char kSearchDomainCheckURL[]; | 65 static const char kSearchDomainCheckURL[]; |
Peter Kasting
2014/05/30 20:50:39
It looks like this is only exposed for tests, so p
blundell
2014/06/02 15:42:26
Done.
| |
65 | 66 |
66 // Only the GoogleURLTrackerFactory and tests should call this. No code other | 67 // Only the GoogleURLTrackerFactory and tests should call this. |
67 // than the GoogleURLTracker itself should actually use | |
68 // GoogleURLTrackerFactory::GetForProfile(). | |
69 GoogleURLTracker(Profile* profile, | 68 GoogleURLTracker(Profile* profile, |
70 scoped_ptr<GoogleURLTrackerClient> client, | 69 scoped_ptr<GoogleURLTrackerClient> client, |
71 Mode mode); | 70 Mode mode); |
72 | 71 |
73 virtual ~GoogleURLTracker(); | 72 virtual ~GoogleURLTracker(); |
74 | 73 |
75 // Returns the current Google URL. This will return a valid URL even if | 74 // Returns the URL corresponding to the default Google homepage. |
76 // |profile| is NULL or a testing profile. | 75 static GURL DefaultGoogleHomepage(); |
77 // | |
78 // This is the only function most code should ever call. | |
79 static GURL GoogleURL(Profile* profile); | |
80 | 76 |
81 // Requests that the tracker perform a server check to update the Google URL | 77 // Requests that the tracker perform a server check to update the Google URL |
82 // as necessary. If |force| is false, this will happen at most once per | 78 // as necessary. If |force| is false, this will happen at most once per |
83 // network change, not sooner than five seconds after startup (checks | 79 // network change, not sooner than five seconds after startup (checks |
84 // requested before that time will occur then; checks requested afterwards | 80 // requested before that time will occur then; checks requested afterwards |
85 // will occur immediately, if no other checks have been made during this run). | 81 // will occur immediately, if no other checks have been made during this run). |
86 // If |force| is true, and the tracker has already performed any requested | 82 // If |force| is true, and the tracker has already performed any requested |
87 // check, it will check again. | 83 // check, it will check again. |
88 // | 84 void RequestServerCheck(bool force); |
89 // When |profile| is NULL or a testing profile, this function does nothing. | |
90 static void RequestServerCheck(Profile* profile, bool force); | |
91 | 85 |
92 // Notifies the tracker that the user has started a Google search. | 86 // Notifies the tracker that the user has started a Google search. |
93 // If prompting is necessary, we then listen for the subsequent pending | 87 // If prompting is necessary, we then listen for the subsequent pending |
94 // navigation to get the appropriate NavigationController. When the load | 88 // navigation to get the appropriate NavigationHelper. When the load |
95 // commits, we'll show the infobar. | 89 // commits, we'll show the infobar. |
96 // | 90 void GoogleURLSearchCommitted(); |
Peter Kasting
2014/05/30 20:50:39
Nit: Now that there isn't a private SearchCommitte
blundell
2014/06/02 15:42:26
Done.
| |
97 // When |profile| is NULL or a testing profile, this function does nothing. | |
98 static void GoogleURLSearchCommitted(Profile* profile); | |
99 | 91 |
100 // No one but GoogleURLTrackerInfoBarDelegate or test code should call these. | 92 // No one but GoogleURLTrackerInfoBarDelegate or test code should call these. |
Peter Kasting
2014/05/30 20:50:39
This comment is now incorrect for google_url() (si
blundell
2014/06/02 15:42:26
Done.
| |
101 void AcceptGoogleURL(bool redo_searches); | 93 void AcceptGoogleURL(bool redo_searches); |
102 void CancelGoogleURL(); | 94 void CancelGoogleURL(); |
103 const GURL& google_url() const { return google_url_; } | 95 const GURL& google_url() const { return google_url_; } |
104 const GURL& fetched_google_url() const { return fetched_google_url_; } | 96 const GURL& fetched_google_url() const { return fetched_google_url_; } |
105 | 97 |
106 // No one but GoogleURLTrackerMapEntry should call this. | 98 // No one but GoogleURLTrackerMapEntry should call this. |
107 void DeleteMapEntryForService(const InfoBarService* infobar_service); | 99 void DeleteMapEntryForService(const InfoBarService* infobar_service); |
108 | 100 |
109 // Called by the client after SearchCommitted() registers listeners, to | 101 // Called by the client after GoogleURLSearchCommitted() registers listeners, |
110 // indicate that we've received the "load now pending" notification. | 102 // to indicate that we've received the "load now pending" notification. |
111 // |nav_helper| is the GoogleURLTrackerNavigationHelper associated with this | 103 // |nav_helper| is the GoogleURLTrackerNavigationHelper associated with this |
112 // navigation; |infobar_service| is the InfoBarService of the associated tab; | 104 // navigation; |infobar_service| is the InfoBarService of the associated tab; |
113 // and |pending_id| is the unique ID of the newly pending NavigationEntry. | 105 // and |pending_id| is the unique ID of the newly pending NavigationEntry. |
114 // If there is already a visible GoogleURLTracker infobar for this tab, this | 106 // If there is already a visible GoogleURLTracker infobar for this tab, this |
115 // function resets its associated pending entry ID to the new ID. Otherwise | 107 // function resets its associated pending entry ID to the new ID. Otherwise |
116 // this function creates a map entry for the associated tab. | 108 // this function creates a map entry for the associated tab. |
117 virtual void OnNavigationPending( | 109 virtual void OnNavigationPending( |
118 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, | 110 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, |
119 InfoBarService* infobar_service, | 111 InfoBarService* infobar_service, |
120 int pending_id); | 112 int pending_id); |
(...skipping 30 matching lines...) Expand all Loading... | |
151 void SetNeedToFetch(); | 143 void SetNeedToFetch(); |
152 | 144 |
153 // Called when the five second startup sleep has finished. Runs any pending | 145 // Called when the five second startup sleep has finished. Runs any pending |
154 // fetch. | 146 // fetch. |
155 void FinishSleep(); | 147 void FinishSleep(); |
156 | 148 |
157 // Starts the fetch of the up-to-date Google URL if we actually want to fetch | 149 // Starts the fetch of the up-to-date Google URL if we actually want to fetch |
158 // it and can currently do so. | 150 // it and can currently do so. |
159 void StartFetchIfDesirable(); | 151 void StartFetchIfDesirable(); |
160 | 152 |
161 // 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 | |
163 // the notifications sent when the actual load is triggered. | |
164 void SearchCommitted(); | |
165 | |
166 // Closes all map entries. If |redo_searches| is true, this also triggers | 153 // 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 | 154 // each tab with an infobar to re-perform the user's search, but on the new |
168 // Google TLD. | 155 // Google TLD. |
169 void CloseAllEntries(bool redo_searches); | 156 void CloseAllEntries(bool redo_searches); |
170 | 157 |
171 // Unregisters any listeners for the navigation helper in |map_entry|. | 158 // Unregisters any listeners for the navigation helper in |map_entry|. |
172 // This sanity-DCHECKs that these are registered (or not) in the specific | 159 // 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 | 160 // cases we expect. (|must_be_listening_for_commit| is used purely for this |
174 // sanity-checking.) This also unregisters the global navigation pending | 161 // sanity-checking.) This also unregisters the global navigation pending |
175 // listener if there are no remaining listeners for navigation commits, as we | 162 // listener if there are no remaining listeners for navigation commits, as we |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 // nor the last prompted Google URL. | 198 // nor the last prompted Google URL. |
212 bool search_committed_; // True when we're expecting a notification of a new | 199 bool search_committed_; // True when we're expecting a notification of a new |
213 // pending search navigation. | 200 // pending search navigation. |
214 EntryMap entry_map_; | 201 EntryMap entry_map_; |
215 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; | 202 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; |
216 | 203 |
217 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); | 204 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); |
218 }; | 205 }; |
219 | 206 |
220 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ | 207 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ |
OLD | NEW |