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> |
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 GoogleURLTrackerNavigationHelper; | 23 class GoogleURLTrackerNavigationHelper; |
24 class InfoBar; | |
25 class PrefService; | 24 class PrefService; |
26 class Profile; | 25 class Profile; |
27 | 26 |
28 namespace content { | 27 namespace content { |
29 class NavigationController; | 28 class NavigationController; |
30 } | 29 } |
31 | 30 |
| 31 namespace infobars { |
| 32 class InfoBar; |
| 33 } |
| 34 |
32 // This object is responsible for checking the Google URL once per network | 35 // This object is responsible for checking the Google URL once per network |
33 // change, and if necessary prompting the user to see if they want to change to | 36 // change, and if necessary prompting the user to see if they want to change to |
34 // using it. The current and last prompted values are saved to prefs. | 37 // using it. The current and last prompted values are saved to prefs. |
35 // | 38 // |
36 // Most consumers should only call GoogleURL(), which is guaranteed to | 39 // Most consumers should only call GoogleURL(), which is guaranteed to |
37 // synchronously return a value at all times (even during startup or in unittest | 40 // synchronously return a value at all times (even during startup or in unittest |
38 // mode). Consumers who need to be notified when things change should listen to | 41 // mode). Consumers who need to be notified when things change should listen to |
39 // the notification service for NOTIFICATION_GOOGLE_URL_UPDATED, which provides | 42 // the notification service for NOTIFICATION_GOOGLE_URL_UPDATED, which provides |
40 // the original and updated values. | 43 // the original and updated values. |
41 // | 44 // |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 const GoogleURLTrackerMapEntry& map_entry, | 175 const GoogleURLTrackerMapEntry& map_entry, |
173 bool must_be_listening_for_commit); | 176 bool must_be_listening_for_commit); |
174 | 177 |
175 Profile* profile_; | 178 Profile* profile_; |
176 | 179 |
177 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper_; | 180 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper_; |
178 | 181 |
179 // Creates an infobar and adds it to the provided InfoBarService. Returns the | 182 // Creates an infobar and adds it to the provided InfoBarService. Returns the |
180 // infobar on success or NULL on failure. The caller does not own the | 183 // infobar on success or NULL on failure. The caller does not own the |
181 // returned object, the InfoBarService does. | 184 // returned object, the InfoBarService does. |
182 base::Callback<InfoBar*(InfoBarService*, GoogleURLTracker*, const GURL&)> | 185 base::Callback< |
| 186 infobars::InfoBar*(InfoBarService*, GoogleURLTracker*, const GURL&)> |
183 infobar_creator_; | 187 infobar_creator_; |
184 | 188 |
185 GURL google_url_; | 189 GURL google_url_; |
186 GURL fetched_google_url_; | 190 GURL fetched_google_url_; |
187 scoped_ptr<net::URLFetcher> fetcher_; | 191 scoped_ptr<net::URLFetcher> fetcher_; |
188 int fetcher_id_; | 192 int fetcher_id_; |
189 bool in_startup_sleep_; // True if we're in the five-second "no fetching" | 193 bool in_startup_sleep_; // True if we're in the five-second "no fetching" |
190 // period that begins at browser start. | 194 // period that begins at browser start. |
191 bool already_fetched_; // True if we've already fetched a URL once this run; | 195 bool already_fetched_; // True if we've already fetched a URL once this run; |
192 // we won't fetch again until after a restart. | 196 // we won't fetch again until after a restart. |
193 bool need_to_fetch_; // True if a consumer actually wants us to fetch an | 197 bool need_to_fetch_; // True if a consumer actually wants us to fetch an |
194 // updated URL. If this is never set, we won't | 198 // updated URL. If this is never set, we won't |
195 // bother to fetch anything. | 199 // bother to fetch anything. |
196 // Consumers should observe | 200 // Consumers should observe |
197 // chrome::NOTIFICATION_GOOGLE_URL_UPDATED. | 201 // chrome::NOTIFICATION_GOOGLE_URL_UPDATED. |
198 bool need_to_prompt_; // True if the last fetched Google URL is not | 202 bool need_to_prompt_; // True if the last fetched Google URL is not |
199 // matched with current user's default Google URL | 203 // matched with current user's default Google URL |
200 // nor the last prompted Google URL. | 204 // nor the last prompted Google URL. |
201 bool search_committed_; // True when we're expecting a notification of a new | 205 bool search_committed_; // True when we're expecting a notification of a new |
202 // pending search navigation. | 206 // pending search navigation. |
203 EntryMap entry_map_; | 207 EntryMap entry_map_; |
204 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; | 208 base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; |
205 | 209 |
206 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); | 210 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); |
207 }; | 211 }; |
208 | 212 |
209 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ | 213 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ |
OLD | NEW |