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 listen to | 42 // mode). Consumers who need to be notified when things change should register |
43 // the notification service for NOTIFICATION_GOOGLE_URL_UPDATED, which provides | 43 // a callback that provides the original and updated values via |
44 // the original and updated values. | 44 // RegisterCallback(). |
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 | |
62 // The constructor does different things depending on which of these values | 59 // The constructor does different things depending on which of these values |
63 // you pass it. Hopefully these are self-explanatory. | 60 // you pass it. Hopefully these are self-explanatory. |
64 enum Mode { | 61 enum Mode { |
65 NORMAL_MODE, | 62 NORMAL_MODE, |
66 UNIT_TEST_MODE, | 63 UNIT_TEST_MODE, |
67 }; | 64 }; |
68 | 65 |
69 static const char kDefaultGoogleHomepage[]; | 66 static const char kDefaultGoogleHomepage[]; |
70 static const char kSearchDomainCheckURL[]; | 67 static const char kSearchDomainCheckURL[]; |
71 | 68 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 GURL fetched_google_url_; | 201 GURL fetched_google_url_; |
205 scoped_ptr<net::URLFetcher> fetcher_; | 202 scoped_ptr<net::URLFetcher> fetcher_; |
206 int fetcher_id_; | 203 int fetcher_id_; |
207 bool in_startup_sleep_; // True if we're in the five-second "no fetching" | 204 bool in_startup_sleep_; // True if we're in the five-second "no fetching" |
208 // period that begins at browser start. | 205 // period that begins at browser start. |
209 bool already_fetched_; // True if we've already fetched a URL once this run; | 206 bool already_fetched_; // True if we've already fetched a URL once this run; |
210 // we won't fetch again until after a restart. | 207 // we won't fetch again until after a restart. |
211 bool need_to_fetch_; // True if a consumer actually wants us to fetch an | 208 bool need_to_fetch_; // True if a consumer actually wants us to fetch an |
212 // updated URL. If this is never set, we won't | 209 // updated URL. If this is never set, we won't |
213 // bother to fetch anything. | 210 // bother to fetch anything. |
214 // Consumers should observe | 211 // Consumers should register a callback via |
215 // chrome::NOTIFICATION_GOOGLE_URL_UPDATED. | 212 // RegisterCallback(). |
216 bool need_to_prompt_; // True if the last fetched Google URL is not | 213 bool need_to_prompt_; // True if the last fetched Google URL is not |
217 // matched with current user's default Google URL | 214 // matched with current user's default Google URL |
218 // nor the last prompted Google URL. | 215 // nor the last prompted Google URL. |
219 bool search_committed_; // True when we're expecting a notification of a new | 216 bool search_committed_; // True when we're expecting a notification of a new |
220 // pending search navigation. | 217 // pending search navigation. |
221 EntryMap entry_map_; | 218 EntryMap entry_map_; |
222 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; | 219 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; |
223 | 220 |
224 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); | 221 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); |
225 }; | 222 }; |
226 | 223 |
227 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ | 224 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ |
OLD | NEW |