| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_UPGRADE_DETECTOR_IMPL_H_ | 5 #ifndef CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_ |
| 6 #define CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_ | 6 #define CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/time.h" |
| 9 #include "base/timer.h" | 10 #include "base/timer.h" |
| 10 #include "chrome/browser/upgrade_detector.h" | 11 #include "chrome/browser/upgrade_detector.h" |
| 12 #include "net/url_request/url_fetcher_delegate.h" |
| 11 | 13 |
| 12 template <typename T> struct DefaultSingletonTraits; | 14 template <typename T> struct DefaultSingletonTraits; |
| 13 | 15 |
| 14 class UpgradeDetectorImpl : public UpgradeDetector { | 16 class UpgradeDetectorImpl : public UpgradeDetector, |
| 17 public net::URLFetcherDelegate { |
| 15 public: | 18 public: |
| 16 virtual ~UpgradeDetectorImpl(); | 19 virtual ~UpgradeDetectorImpl(); |
| 17 | 20 |
| 18 // Returns the singleton instance. | 21 // Returns the singleton instance. |
| 19 static UpgradeDetectorImpl* GetInstance(); | 22 static UpgradeDetectorImpl* GetInstance(); |
| 20 | 23 |
| 21 private: | 24 private: |
| 22 friend struct DefaultSingletonTraits<UpgradeDetectorImpl>; | 25 friend struct DefaultSingletonTraits<UpgradeDetectorImpl>; |
| 23 | 26 |
| 24 UpgradeDetectorImpl(); | 27 UpgradeDetectorImpl(); |
| 25 | 28 |
| 26 // Launches a task on the file thread to check if we have the latest version. | 29 // Launches a task on the file thread to check if we have the latest version. |
| 27 void CheckForUpgrade(); | 30 void CheckForUpgrade(); |
| 28 | 31 |
| 29 // Sends out a notification and starts a one shot timer to wait until | 32 // Sends out a notification and starts a one shot timer to wait until |
| 30 // notifying the user. | 33 // notifying the user. |
| 31 void UpgradeDetected(); | 34 void UpgradeDetected(); |
| 32 | 35 |
| 36 // Sends a URL request to get a sane time to be compared to the build time. |
| 37 void CompareBuildTimeToSaneTime(); |
| 38 |
| 33 // The function that sends out a notification (after a certain time has | 39 // The function that sends out a notification (after a certain time has |
| 34 // elapsed) that lets the rest of the UI know we should start notifying the | 40 // elapsed) that lets the rest of the UI know we should start notifying the |
| 35 // user that a new version is available. | 41 // user that a new version is available. |
| 36 void NotifyOnUpgrade(); | 42 void NotifyOnUpgrade(); |
| 37 | 43 |
| 44 // net::URLFetcherDelegate implementation: |
| 45 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 46 |
| 47 // Contains the current time request. Will only have a value while a request |
| 48 // is pending, and will be reset by |OnURLFetchComplete|. |
| 49 scoped_ptr<net::URLFetcher> pending_time_request_; |
| 50 |
| 38 // We periodically check to see if Chrome has been upgraded. | 51 // We periodically check to see if Chrome has been upgraded. |
| 39 base::RepeatingTimer<UpgradeDetectorImpl> detect_upgrade_timer_; | 52 base::RepeatingTimer<UpgradeDetectorImpl> detect_upgrade_timer_; |
| 40 | 53 |
| 41 // After we detect an upgrade we start a recurring timer to see if enough time | 54 // After we detect an upgrade we start a recurring timer to see if enough time |
| 42 // has passed and we should start notifying the user. | 55 // has passed and we should start notifying the user. |
| 43 base::RepeatingTimer<UpgradeDetectorImpl> upgrade_notification_timer_; | 56 base::RepeatingTimer<UpgradeDetectorImpl> upgrade_notification_timer_; |
| 44 | 57 |
| 45 // We use this factory to create callback tasks for UpgradeDetected. We pass | 58 // We use this factory to create callback tasks for UpgradeDetected. We pass |
| 46 // the task to the actual upgrade detection code, which is in | 59 // the task to the actual upgrade detection code, which is in |
| 47 // DetectUpgradeTask. | 60 // DetectUpgradeTask. |
| 48 base::WeakPtrFactory<UpgradeDetectorImpl> weak_factory_; | 61 base::WeakPtrFactory<UpgradeDetectorImpl> weak_factory_; |
| 49 | 62 |
| 50 // True if this build is a dev or canary channel build. | 63 // True if this build is a dev or canary channel build. |
| 51 bool is_unstable_channel_; | 64 bool is_unstable_channel_; |
| 52 | 65 |
| 66 // The date the binaries were built. |
| 67 base::Time build_date_; |
| 68 |
| 53 DISALLOW_COPY_AND_ASSIGN(UpgradeDetectorImpl); | 69 DISALLOW_COPY_AND_ASSIGN(UpgradeDetectorImpl); |
| 54 }; | 70 }; |
| 55 | 71 |
| 56 | 72 |
| 57 #endif // CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_ | 73 #endif // CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_ |
| OLD | NEW |