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