| 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 | 11 |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "chrome/browser/profiles/profile_keyed_service.h" | 15 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 16 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 16 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/common/url_fetcher.h" | 19 #include "content/public/common/url_fetcher.h" |
| 20 #include "content/public/common/url_fetcher_delegate.h" | |
| 21 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| 22 #include "net/base/network_change_notifier.h" | 21 #include "net/base/network_change_notifier.h" |
| 22 #include "net/url_request/url_fetcher_delegate.h" |
| 23 | 23 |
| 24 class GoogleURLTrackerInfoBarDelegate; | 24 class GoogleURLTrackerInfoBarDelegate; |
| 25 class PrefService; | 25 class PrefService; |
| 26 class Profile; | 26 class Profile; |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 class NavigationController; | 29 class NavigationController; |
| 30 class WebContents; | 30 class WebContents; |
| 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 GoogleURL(), which is guaranteed to |
| 38 // synchronously return a value at all times (even during startup or in unittest | 38 // 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 | 39 // 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() | 40 // the notification service for NOTIFY_GOOGLE_URL_UPDATED, and call GoogleURL() |
| 41 // again after receiving it, in order to get the updated value. | 41 // again after receiving it, in order to get the updated value. |
| 42 // | 42 // |
| 43 // To protect users' privacy and reduce server load, no updates will be | 43 // To protect users' privacy and reduce server load, no updates will be |
| 44 // performed (ever) unless at least one consumer registers interest by calling | 44 // performed (ever) unless at least one consumer registers interest by calling |
| 45 // RequestServerCheck(). | 45 // RequestServerCheck(). |
| 46 class GoogleURLTracker : public content::URLFetcherDelegate, | 46 class GoogleURLTracker : public net::URLFetcherDelegate, |
| 47 public content::NotificationObserver, | 47 public content::NotificationObserver, |
| 48 public net::NetworkChangeNotifier::IPAddressObserver, | 48 public net::NetworkChangeNotifier::IPAddressObserver, |
| 49 public ProfileKeyedService { | 49 public ProfileKeyedService { |
| 50 public: | 50 public: |
| 51 // The constructor does different things depending on which of these values | 51 // The constructor does different things depending on which of these values |
| 52 // you pass it. Hopefully these are self-explanatory. | 52 // you pass it. Hopefully these are self-explanatory. |
| 53 enum Mode { | 53 enum Mode { |
| 54 NORMAL_MODE, | 54 NORMAL_MODE, |
| 55 UNIT_TEST_MODE, | 55 UNIT_TEST_MODE, |
| 56 }; | 56 }; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 void SetNeedToFetch(); | 110 void SetNeedToFetch(); |
| 111 | 111 |
| 112 // Called when the five second startup sleep has finished. Runs any pending | 112 // Called when the five second startup sleep has finished. Runs any pending |
| 113 // fetch. | 113 // fetch. |
| 114 void FinishSleep(); | 114 void FinishSleep(); |
| 115 | 115 |
| 116 // Starts the fetch of the up-to-date Google URL if we actually want to fetch | 116 // Starts the fetch of the up-to-date Google URL if we actually want to fetch |
| 117 // it and can currently do so. | 117 // it and can currently do so. |
| 118 void StartFetchIfDesirable(); | 118 void StartFetchIfDesirable(); |
| 119 | 119 |
| 120 // content::URLFetcherDelegate: | 120 // net::URLFetcherDelegate: |
| 121 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 121 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 122 | 122 |
| 123 // content::NotificationObserver: | 123 // content::NotificationObserver: |
| 124 virtual void Observe(int type, | 124 virtual void Observe(int type, |
| 125 const content::NotificationSource& source, | 125 const content::NotificationSource& source, |
| 126 const content::NotificationDetails& details) OVERRIDE; | 126 const content::NotificationDetails& details) OVERRIDE; |
| 127 | 127 |
| 128 // NetworkChangeNotifier::IPAddressObserver: | 128 // NetworkChangeNotifier::IPAddressObserver: |
| 129 virtual void OnIPAddressChanged() OVERRIDE; | 129 virtual void OnIPAddressChanged() OVERRIDE; |
| 130 | 130 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 232 |
| 233 private: | 233 private: |
| 234 // ConfirmInfoBarDelegate: | 234 // ConfirmInfoBarDelegate: |
| 235 virtual string16 GetMessageText() const OVERRIDE; | 235 virtual string16 GetMessageText() const OVERRIDE; |
| 236 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 236 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 237 | 237 |
| 238 DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerInfoBarDelegate); | 238 DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerInfoBarDelegate); |
| 239 }; | 239 }; |
| 240 | 240 |
| 241 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ | 241 #endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ |
| OLD | NEW |