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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_ 6 #define CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_ 7 8 #include "base/memory/weak_ptr.h" 9 #include "base/timer/timer.h" 10 #include "base/version.h" 11 #include "chrome/browser/upgrade_detector.h" 12 13 template <typename T> struct DefaultSingletonTraits; 14 15 class UpgradeDetectorImpl : public UpgradeDetector { 16 public: 17 virtual ~UpgradeDetectorImpl(); 18 19 // Returns the currently installed Chrome version, which may be newer than the 20 // one currently running. Not supported on Android, iOS or ChromeOS. Must be 21 // run on a thread where I/O operations are allowed (e.g. FILE thread). 22 static base::Version GetCurrentlyInstalledVersion(); 23 24 // Returns the singleton instance. 25 static UpgradeDetectorImpl* GetInstance(); 26 27 private: 28 friend struct DefaultSingletonTraits<UpgradeDetectorImpl>; 29 30 UpgradeDetectorImpl(); 31 32 // Start the timer that will call |CheckForUpgrade()|. 33 void StartTimerForUpgradeCheck(); 34 35 // Launches a task on the file thread to check if we have the latest version. 36 void CheckForUpgrade(); 37 38 // Sends out a notification and starts a one shot timer to wait until 39 // notifying the user. 40 void UpgradeDetected(UpgradeAvailable upgrade_available); 41 42 // Returns true after calling UpgradeDetected if current install is outdated. 43 bool DetectOutdatedInstall(); 44 45 // The function that sends out a notification (after a certain time has 46 // elapsed) that lets the rest of the UI know we should start notifying the 47 // user that a new version is available. 48 void NotifyOnUpgrade(); 49 50 // Called on the FILE thread to detect an upgrade. Calls back UpgradeDetected 51 // on the UI thread if so. Although it looks weird, this needs to be a static 52 // method receiving a WeakPtr<> to this object so that we can interrupt 53 // the UpgradeDetected callback before it runs. Having this method non-static 54 // and using |this| directly wouldn't be thread safe. And keeping it as a 55 // non-class function would prevent it from calling UpgradeDetected. 56 static void DetectUpgradeTask( 57 base::WeakPtr<UpgradeDetectorImpl> upgrade_detector); 58 59 // We periodically check to see if Chrome has been upgraded. 60 base::RepeatingTimer<UpgradeDetectorImpl> detect_upgrade_timer_; 61 62 // After we detect an upgrade we start a recurring timer to see if enough time 63 // has passed and we should start notifying the user. 64 base::RepeatingTimer<UpgradeDetectorImpl> upgrade_notification_timer_; 65 66 // We use this factory to create callback tasks for UpgradeDetected. We pass 67 // the task to the actual upgrade detection code, which is in 68 // DetectUpgradeTask. 69 base::WeakPtrFactory<UpgradeDetectorImpl> weak_factory_; 70 71 // True if this build is a dev or canary channel build. 72 bool is_unstable_channel_; 73 74 // True if auto update is turned on. 75 bool is_auto_update_enabled_; 76 77 // The date the binaries were built. 78 base::Time build_date_; 79 80 DISALLOW_COPY_AND_ASSIGN(UpgradeDetectorImpl); 81 }; 82 83 84 #endif // CHROME_BROWSER_UPGRADE_DETECTOR_IMPL_H_ 85