| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> |
| 11 | 12 |
| 12 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 15 #include "chrome/browser/profiles/profile_keyed_service.h" | 16 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 16 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 17 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 17 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/common/url_fetcher.h" | 20 #include "content/public/common/url_fetcher.h" |
| 20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 21 #include "net/base/network_change_notifier.h" | 22 #include "net/base/network_change_notifier.h" |
| 22 #include "net/url_request/url_fetcher_delegate.h" | 23 #include "net/url_request/url_fetcher_delegate.h" |
| 23 | 24 |
| 24 class GoogleURLTrackerInfoBarDelegate; | 25 class GoogleURLTrackerInfoBarDelegate; |
| 25 class PrefService; | 26 class PrefService; |
| 26 class Profile; | 27 class Profile; |
| 27 | 28 |
| 28 namespace content { | 29 namespace content { |
| 29 class NavigationController; | 30 class NavigationController; |
| 30 class WebContents; | 31 class WebContents; |
| 31 } | 32 } |
| 32 | 33 |
| 33 // This object is responsible for checking the Google URL once per network | 34 // 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 | 35 // 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. | 36 // using it. The current and last prompted values are saved to prefs. |
| 36 // | 37 // |
| 37 // Most consumers should only call GoogleURL(), which is guaranteed to | 38 // Most consumers should only call GoogleURL(), which is guaranteed to |
| 38 // synchronously return a value at all times (even during startup or in unittest | 39 // synchronously return a value at all times (even during startup or in unittest |
| 39 // mode). Consumers who need to be notified when things change should listen to | 40 // mode). Consumers who need to be notified when things change should listen to |
| 40 // the notification service for NOTIFY_GOOGLE_URL_UPDATED, and call GoogleURL() | 41 // the notification service for NOTIFICATION_GOOGLE_URL_UPDATED, which provides |
| 41 // again after receiving it, in order to get the updated value. | 42 // the original and updated values. |
| 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 content::NotificationObserver, | 48 public content::NotificationObserver, |
| 48 public net::NetworkChangeNotifier::IPAddressObserver, | 49 public net::NetworkChangeNotifier::IPAddressObserver, |
| 49 public ProfileKeyedService { | 50 public ProfileKeyedService { |
| 50 public: | 51 public: |
| 52 // The contents of the Details for a NOTIFICATION_GOOGLE_URL_UPDATED. |
| 53 typedef std::pair<GURL, GURL> UpdatedDetails; |
| 54 |
| 51 // The constructor does different things depending on which of these values | 55 // The constructor does different things depending on which of these values |
| 52 // you pass it. Hopefully these are self-explanatory. | 56 // you pass it. Hopefully these are self-explanatory. |
| 53 enum Mode { | 57 enum Mode { |
| 54 NORMAL_MODE, | 58 NORMAL_MODE, |
| 55 UNIT_TEST_MODE, | 59 UNIT_TEST_MODE, |
| 56 }; | 60 }; |
| 57 | 61 |
| 58 // Only the GoogleURLTrackerFactory and tests should call this. No code other | 62 // Only the GoogleURLTrackerFactory and tests should call this. No code other |
| 59 // than the GoogleURLTracker itself should actually use | 63 // than the GoogleURLTracker itself should actually use |
| 60 // GoogleURLTrackerFactory::GetForProfile(). | 64 // GoogleURLTrackerFactory::GetForProfile(). |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 InfoBarTabHelper* infobar_helper, | 102 InfoBarTabHelper* infobar_helper, |
| 99 const GURL& search_url, | 103 const GURL& search_url, |
| 100 GoogleURLTracker* google_url_tracker, | 104 GoogleURLTracker* google_url_tracker, |
| 101 const GURL& new_google_url); | 105 const GURL& new_google_url); |
| 102 | 106 |
| 103 void AcceptGoogleURL(const GURL& google_url, bool redo_searches); | 107 void AcceptGoogleURL(const GURL& google_url, bool redo_searches); |
| 104 void CancelGoogleURL(const GURL& google_url); | 108 void CancelGoogleURL(const GURL& google_url); |
| 105 void InfoBarClosed(const InfoBarTabHelper* infobar_helper); | 109 void InfoBarClosed(const InfoBarTabHelper* infobar_helper); |
| 106 | 110 |
| 107 // Registers consumer interest in getting an updated URL from the server. | 111 // Registers consumer interest in getting an updated URL from the server. |
| 108 // It will be notified as chrome::GOOGLE_URL_UPDATED, so the | 112 // Observe chrome::NOTIFICATION_GOOGLE_URL_UPDATED to be notified when the URL |
| 109 // consumer should observe this notification before calling this. | 113 // changes. |
| 110 void SetNeedToFetch(); | 114 void SetNeedToFetch(); |
| 111 | 115 |
| 112 // Called when the five second startup sleep has finished. Runs any pending | 116 // Called when the five second startup sleep has finished. Runs any pending |
| 113 // fetch. | 117 // fetch. |
| 114 void FinishSleep(); | 118 void FinishSleep(); |
| 115 | 119 |
| 116 // Starts the fetch of the up-to-date Google URL if we actually want to fetch | 120 // Starts the fetch of the up-to-date Google URL if we actually want to fetch |
| 117 // it and can currently do so. | 121 // it and can currently do so. |
| 118 void StartFetchIfDesirable(); | 122 void StartFetchIfDesirable(); |
| 119 | 123 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 scoped_ptr<net::URLFetcher> fetcher_; | 183 scoped_ptr<net::URLFetcher> fetcher_; |
| 180 int fetcher_id_; | 184 int fetcher_id_; |
| 181 bool in_startup_sleep_; // True if we're in the five-second "no fetching" | 185 bool in_startup_sleep_; // True if we're in the five-second "no fetching" |
| 182 // period that begins at browser start. | 186 // period that begins at browser start. |
| 183 bool already_fetched_; // True if we've already fetched a URL once this run; | 187 bool already_fetched_; // True if we've already fetched a URL once this run; |
| 184 // we won't fetch again until after a restart. | 188 // we won't fetch again until after a restart. |
| 185 bool need_to_fetch_; // True if a consumer actually wants us to fetch an | 189 bool need_to_fetch_; // True if a consumer actually wants us to fetch an |
| 186 // updated URL. If this is never set, we won't | 190 // updated URL. If this is never set, we won't |
| 187 // bother to fetch anything. | 191 // bother to fetch anything. |
| 188 // Consumers should observe | 192 // Consumers should observe |
| 189 // chrome::GOOGLE_URL_UPDATED. | 193 // chrome::NOTIFICATION_GOOGLE_URL_UPDATED. |
| 190 bool need_to_prompt_; // True if the last fetched Google URL is not | 194 bool need_to_prompt_; // True if the last fetched Google URL is not |
| 191 // matched with current user's default Google URL | 195 // matched with current user's default Google URL |
| 192 // nor the last prompted Google URL. | 196 // nor the last prompted Google URL. |
| 193 InfoBarMap infobar_map_; | 197 InfoBarMap infobar_map_; |
| 194 | 198 |
| 195 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); | 199 DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); |
| 196 }; | 200 }; |
| 197 | 201 |
| 198 | 202 |
| 199 // This infobar delegate is declared here (rather than in the .cc file) so test | 203 // This infobar delegate is declared here (rather than in the .cc file) so test |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 236 |
| 233 private: | 237 private: |
| 234 // ConfirmInfoBarDelegate: | 238 // ConfirmInfoBarDelegate: |
| 235 virtual string16 GetMessageText() const OVERRIDE; | 239 virtual string16 GetMessageText() const OVERRIDE; |
| 236 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 240 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 237 | 241 |
| 238 DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerInfoBarDelegate); | 242 DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerInfoBarDelegate); |
| 239 }; | 243 }; |
| 240 | 244 |
| 241 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ | 245 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ |
| OLD | NEW |