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 21 matching lines...) Expand all Loading... |
32 namespace infobars { | 32 namespace infobars { |
33 class InfoBar; | 33 class InfoBar; |
34 } | 34 } |
35 | 35 |
36 // This object is responsible for checking the Google URL once per network | 36 // 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 | 37 // 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. | 38 // using it. The current and last prompted values are saved to prefs. |
39 // | 39 // |
40 // Most consumers should only call GoogleURL(), which is guaranteed to | 40 // Most consumers should only call GoogleURL(), which is guaranteed to |
41 // synchronously return a value at all times (even during startup or in unittest | 41 // synchronously return a value at all times (even during startup or in unittest |
42 // mode). Consumers who need to be notified when things change should register | 42 // mode). Consumers who need to be notified when things change should listen to |
43 // a callback that provides the original and updated values via | 43 // the notification service for NOTIFICATION_GOOGLE_URL_UPDATED, which provides |
44 // RegisterCallback(). | 44 // the original and updated values. |
45 // | 45 // |
46 // To protect users' privacy and reduce server load, no updates will be | 46 // To protect users' privacy and reduce server load, no updates will be |
47 // performed (ever) unless at least one consumer registers interest by calling | 47 // performed (ever) unless at least one consumer registers interest by calling |
48 // RequestServerCheck(). | 48 // RequestServerCheck(). |
49 class GoogleURLTracker : public net::URLFetcherDelegate, | 49 class GoogleURLTracker : public net::URLFetcherDelegate, |
50 public net::NetworkChangeNotifier::IPAddressObserver, | 50 public net::NetworkChangeNotifier::IPAddressObserver, |
51 public KeyedService { | 51 public KeyedService { |
52 public: | 52 public: |
53 // Callback that is called when the Google URL is updated. The arguments are | 53 // Callback that is called when the Google URL is updated. The arguments are |
54 // the old and new URLs. | 54 // the old and new URLs. |
55 typedef base::Callback<void(GURL, GURL)> OnGoogleURLUpdatedCallback; | 55 typedef base::Callback<void(GURL, GURL)> OnGoogleURLUpdatedCallback; |
56 typedef base::CallbackList<void(GURL, GURL)> CallbackList; | 56 typedef base::CallbackList<void(GURL, GURL)> CallbackList; |
57 typedef CallbackList::Subscription Subscription; | 57 typedef CallbackList::Subscription Subscription; |
58 | 58 |
| 59 // The contents of the Details for a NOTIFICATION_GOOGLE_URL_UPDATED. |
| 60 typedef std::pair<GURL, GURL> UpdatedDetails; |
| 61 |
59 // The constructor does different things depending on which of these values | 62 // The constructor does different things depending on which of these values |
60 // you pass it. Hopefully these are self-explanatory. | 63 // you pass it. Hopefully these are self-explanatory. |
61 enum Mode { | 64 enum Mode { |
62 NORMAL_MODE, | 65 NORMAL_MODE, |
63 UNIT_TEST_MODE, | 66 UNIT_TEST_MODE, |
64 }; | 67 }; |
65 | 68 |
66 static const char kDefaultGoogleHomepage[]; | 69 static const char kDefaultGoogleHomepage[]; |
67 static const char kSearchDomainCheckURL[]; | 70 static const char kSearchDomainCheckURL[]; |
68 | 71 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 GURL fetched_google_url_; | 204 GURL fetched_google_url_; |
202 scoped_ptr<net::URLFetcher> fetcher_; | 205 scoped_ptr<net::URLFetcher> fetcher_; |
203 int fetcher_id_; | 206 int fetcher_id_; |
204 bool in_startup_sleep_; // True if we're in the five-second "no fetching" | 207 bool in_startup_sleep_; // True if we're in the five-second "no fetching" |
205 // period that begins at browser start. | 208 // period that begins at browser start. |
206 bool already_fetched_; // True if we've already fetched a URL once this run; | 209 bool already_fetched_; // True if we've already fetched a URL once this run; |
207 // we won't fetch again until after a restart. | 210 // we won't fetch again until after a restart. |
208 bool need_to_fetch_; // True if a consumer actually wants us to fetch an | 211 bool need_to_fetch_; // True if a consumer actually wants us to fetch an |
209 // updated URL. If this is never set, we won't | 212 // updated URL. If this is never set, we won't |
210 // bother to fetch anything. | 213 // bother to fetch anything. |
211 // Consumers should register a callback via | 214 // Consumers should observe |
212 // RegisterCallback(). | 215 // chrome::NOTIFICATION_GOOGLE_URL_UPDATED. |
213 bool need_to_prompt_; // True if the last fetched Google URL is not | 216 bool need_to_prompt_; // True if the last fetched Google URL is not |
214 // matched with current user's default Google URL | 217 // matched with current user's default Google URL |
215 // nor the last prompted Google URL. | 218 // nor the last prompted Google URL. |
216 bool search_committed_; // True when we're expecting a notification of a new | 219 bool search_committed_; // True when we're expecting a notification of a new |
217 // pending search navigation. | 220 // pending search navigation. |
218 EntryMap entry_map_; | 221 EntryMap entry_map_; |
219 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; | 222 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; |
220 | 223 |
221 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); | 224 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); |
222 }; | 225 }; |
223 | 226 |
224 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ | 227 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ |
OLD | NEW |