| 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 #include "chrome/browser/upgrade_detector_impl.h" | 5 #include "chrome/browser/upgrade_detector_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 return interval_ms * 1000; // Command line value is in seconds. | 56 return interval_ms * 1000; // Command line value is in seconds. |
| 57 | 57 |
| 58 return kCheckForUpgradeMs; | 58 return kCheckForUpgradeMs; |
| 59 } | 59 } |
| 60 | 60 |
| 61 // This task checks the currently running version of Chrome against the | 61 // This task checks the currently running version of Chrome against the |
| 62 // installed version. If the installed version is newer, it runs the passed | 62 // installed version. If the installed version is newer, it runs the passed |
| 63 // callback task. Otherwise it just deletes the task. | 63 // callback task. Otherwise it just deletes the task. |
| 64 class DetectUpgradeTask : public Task { | 64 class DetectUpgradeTask : public Task { |
| 65 public: | 65 public: |
| 66 DetectUpgradeTask(Task* upgrade_detected_task, bool* is_unstable_channel) | 66 DetectUpgradeTask(Task* upgrade_detected_task, |
| 67 bool* is_unstable_channel, |
| 68 bool* is_critical_upgrade) |
| 67 : upgrade_detected_task_(upgrade_detected_task), | 69 : upgrade_detected_task_(upgrade_detected_task), |
| 68 is_unstable_channel_(is_unstable_channel) { | 70 is_unstable_channel_(is_unstable_channel), |
| 71 is_critical_upgrade_(is_critical_upgrade) { |
| 69 } | 72 } |
| 70 | 73 |
| 71 virtual ~DetectUpgradeTask() { | 74 virtual ~DetectUpgradeTask() { |
| 72 if (upgrade_detected_task_) { | 75 if (upgrade_detected_task_) { |
| 73 // This has to get deleted on the same thread it was created. | 76 // This has to get deleted on the same thread it was created. |
| 74 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 77 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 75 new DeleteTask<Task>(upgrade_detected_task_)); | 78 new DeleteTask<Task>(upgrade_detected_task_)); |
| 76 } | 79 } |
| 77 } | 80 } |
| 78 | 81 |
| 79 virtual void Run() { | 82 virtual void Run() { |
| 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 81 | 84 |
| 82 scoped_ptr<Version> installed_version; | 85 scoped_ptr<Version> installed_version; |
| 86 scoped_ptr<Version> critical_update; |
| 83 | 87 |
| 84 #if defined(OS_WIN) | 88 #if defined(OS_WIN) |
| 85 // Get the version of the currently *installed* instance of Chrome, | 89 // Get the version of the currently *installed* instance of Chrome, |
| 86 // which might be newer than the *running* instance if we have been | 90 // which might be newer than the *running* instance if we have been |
| 87 // upgraded in the background. | 91 // upgraded in the background. |
| 88 // TODO(tommi): Check if using the default distribution is always the right | 92 // TODO(tommi): Check if using the default distribution is always the right |
| 89 // thing to do. | 93 // thing to do. |
| 90 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 94 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 91 installed_version.reset(InstallUtil::GetChromeVersion(dist, false)); | 95 installed_version.reset(InstallUtil::GetChromeVersion(dist, false)); |
| 92 if (!installed_version.get()) { | 96 |
| 93 // User level Chrome is not installed, check system level. | 97 if (installed_version.get()) { |
| 98 #if defined(OS_WIN) |
| 99 // Critical version detection is only supported for user-level Chrome |
| 100 // since elevation is needed for system-level Chrome (and this runs in |
| 101 // the background -- don't want to prompt). |
| 102 critical_update.reset(InstallUtil::GetCriticalUpdateVersion(dist)); |
| 103 #endif |
| 104 } else { |
| 105 // User-level Chrome is not installed, check system-level. |
| 94 installed_version.reset(InstallUtil::GetChromeVersion(dist, true)); | 106 installed_version.reset(InstallUtil::GetChromeVersion(dist, true)); |
| 95 } | 107 } |
| 96 #elif defined(OS_MACOSX) | 108 #elif defined(OS_MACOSX) |
| 97 installed_version.reset( | 109 installed_version.reset( |
| 98 Version::GetVersionFromString(UTF16ToASCII( | 110 Version::GetVersionFromString(UTF16ToASCII( |
| 99 keystone_glue::CurrentlyInstalledVersion()))); | 111 keystone_glue::CurrentlyInstalledVersion()))); |
| 100 #elif defined(OS_POSIX) | 112 #elif defined(OS_POSIX) |
| 101 // POSIX but not Mac OS X: Linux, etc. | 113 // POSIX but not Mac OS X: Linux, etc. |
| 102 CommandLine command_line(*CommandLine::ForCurrentProcess()); | 114 CommandLine command_line(*CommandLine::ForCurrentProcess()); |
| 103 command_line.AppendSwitch(switches::kProductVersion); | 115 command_line.AppendSwitch(switches::kProductVersion); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 125 if (running_version.get() == NULL) { | 137 if (running_version.get() == NULL) { |
| 126 NOTREACHED() << "Failed to parse version info"; | 138 NOTREACHED() << "Failed to parse version info"; |
| 127 return; | 139 return; |
| 128 } | 140 } |
| 129 | 141 |
| 130 // |installed_version| may be NULL when the user downgrades on Linux (by | 142 // |installed_version| may be NULL when the user downgrades on Linux (by |
| 131 // switching from dev to beta channel, for example). The user needs a | 143 // switching from dev to beta channel, for example). The user needs a |
| 132 // restart in this case as well. See http://crbug.com/46547 | 144 // restart in this case as well. See http://crbug.com/46547 |
| 133 if (!installed_version.get() || | 145 if (!installed_version.get() || |
| 134 (installed_version->CompareTo(*running_version) > 0)) { | 146 (installed_version->CompareTo(*running_version) > 0)) { |
| 147 // If a more recent version is available, it might be that we are lacking |
| 148 // a critical update, such as a zero-day fix. |
| 149 *is_critical_upgrade_ = |
| 150 critical_update.get() && |
| 151 (critical_update->CompareTo(*running_version) > 0); |
| 152 |
| 153 // Fire off the upgrade detected task. |
| 135 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 154 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 136 upgrade_detected_task_); | 155 upgrade_detected_task_); |
| 137 upgrade_detected_task_ = NULL; | 156 upgrade_detected_task_ = NULL; |
| 138 } | 157 } |
| 139 } | 158 } |
| 140 | 159 |
| 141 private: | 160 private: |
| 142 Task* upgrade_detected_task_; | 161 Task* upgrade_detected_task_; |
| 143 bool* is_unstable_channel_; | 162 bool* is_unstable_channel_; |
| 163 bool* is_critical_upgrade_; |
| 144 }; | 164 }; |
| 145 | 165 |
| 146 } // namespace | 166 } // namespace |
| 147 | 167 |
| 148 UpgradeDetectorImpl::UpgradeDetectorImpl() | 168 UpgradeDetectorImpl::UpgradeDetectorImpl() |
| 149 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 169 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
| 150 is_unstable_channel_(false) { | 170 is_unstable_channel_(false) { |
| 151 CommandLine command_line(*CommandLine::ForCurrentProcess()); | 171 CommandLine command_line(*CommandLine::ForCurrentProcess()); |
| 152 if (command_line.HasSwitch(switches::kDisableBackgroundNetworking)) | 172 if (command_line.HasSwitch(switches::kDisableBackgroundNetworking)) |
| 153 return; | 173 return; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 172 void UpgradeDetectorImpl::CheckForUpgrade() { | 192 void UpgradeDetectorImpl::CheckForUpgrade() { |
| 173 method_factory_.RevokeAll(); | 193 method_factory_.RevokeAll(); |
| 174 Task* callback_task = | 194 Task* callback_task = |
| 175 method_factory_.NewRunnableMethod(&UpgradeDetectorImpl::UpgradeDetected); | 195 method_factory_.NewRunnableMethod(&UpgradeDetectorImpl::UpgradeDetected); |
| 176 // We use FILE as the thread to run the upgrade detection code on all | 196 // We use FILE as the thread to run the upgrade detection code on all |
| 177 // platforms. For Linux, this is because we don't want to block the UI thread | 197 // platforms. For Linux, this is because we don't want to block the UI thread |
| 178 // while launching a background process and reading its output; on the Mac and | 198 // while launching a background process and reading its output; on the Mac and |
| 179 // on Windows checking for an upgrade requires reading a file. | 199 // on Windows checking for an upgrade requires reading a file. |
| 180 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 200 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 181 new DetectUpgradeTask(callback_task, | 201 new DetectUpgradeTask(callback_task, |
| 182 &is_unstable_channel_)); | 202 &is_unstable_channel_, |
| 203 &is_critical_upgrade_)); |
| 183 } | 204 } |
| 184 | 205 |
| 185 void UpgradeDetectorImpl::UpgradeDetected() { | 206 void UpgradeDetectorImpl::UpgradeDetected() { |
| 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 187 | 208 |
| 188 // Stop the recurring timer (that is checking for changes). | 209 // Stop the recurring timer (that is checking for changes). |
| 189 detect_upgrade_timer_.Stop(); | 210 detect_upgrade_timer_.Stop(); |
| 190 | 211 |
| 191 NotifyUpgradeDetected(); | 212 NotifyUpgradeDetected(); |
| 192 | 213 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 209 // severity. This works in conjunction with the similar interval.empty() | 230 // severity. This works in conjunction with the similar interval.empty() |
| 210 // check below. | 231 // check below. |
| 211 int64 time_passed = interval.empty() ? delta.InHours() : delta.InSeconds(); | 232 int64 time_passed = interval.empty() ? delta.InHours() : delta.InSeconds(); |
| 212 | 233 |
| 213 if (is_unstable_channel_) { | 234 if (is_unstable_channel_) { |
| 214 // There's only one threat level for unstable channels like dev and | 235 // There's only one threat level for unstable channels like dev and |
| 215 // canary, and it hits after one hour. During testing, it hits after one | 236 // canary, and it hits after one hour. During testing, it hits after one |
| 216 // minute. | 237 // minute. |
| 217 const int kUnstableThreshold = 1; | 238 const int kUnstableThreshold = 1; |
| 218 | 239 |
| 219 if (time_passed >= kUnstableThreshold) { | 240 if (is_critical_upgrade_) |
| 241 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_CRITICAL); |
| 242 else if (time_passed >= kUnstableThreshold) { |
| 220 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); | 243 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); |
| 221 | 244 |
| 222 // That's as high as it goes. | 245 // That's as high as it goes. |
| 223 upgrade_notification_timer_.Stop(); | 246 upgrade_notification_timer_.Stop(); |
| 224 } else { | 247 } else { |
| 225 return; // Not ready to recommend upgrade. | 248 return; // Not ready to recommend upgrade. |
| 226 } | 249 } |
| 227 } else { | 250 } else { |
| 228 const int kMultiplier = interval.empty() ? 24 : 1; | 251 const int kMultiplier = interval.empty() ? 24 : 1; |
| 229 // 14 days when not testing, otherwise 14 seconds. | 252 // 14 days when not testing, otherwise 14 seconds. |
| 230 const int kSevereThreshold = 14 * kMultiplier; | 253 const int kSevereThreshold = 14 * kMultiplier; |
| 231 const int kHighThreshold = 7 * kMultiplier; | 254 const int kHighThreshold = 7 * kMultiplier; |
| 232 const int kElevatedThreshold = 4 * kMultiplier; | 255 const int kElevatedThreshold = 4 * kMultiplier; |
| 233 const int kLowThreshold = 2 * kMultiplier; | 256 const int kLowThreshold = 2 * kMultiplier; |
| 234 | 257 |
| 235 // These if statements must be sorted (highest interval first). | 258 // These if statements must be sorted (highest interval first). |
| 236 if (time_passed >= kSevereThreshold) { | 259 if (time_passed >= kSevereThreshold || is_critical_upgrade_) { |
| 237 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_SEVERE); | 260 set_upgrade_notification_stage( |
| 261 is_critical_upgrade_ ? UPGRADE_ANNOYANCE_CRITICAL : |
| 262 UPGRADE_ANNOYANCE_SEVERE); |
| 238 | 263 |
| 239 // We can't get any higher, baby. | 264 // We can't get any higher, baby. |
| 240 upgrade_notification_timer_.Stop(); | 265 upgrade_notification_timer_.Stop(); |
| 241 } else if (time_passed >= kHighThreshold) { | 266 } else if (time_passed >= kHighThreshold) { |
| 242 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_HIGH); | 267 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_HIGH); |
| 243 } else if (time_passed >= kElevatedThreshold) { | 268 } else if (time_passed >= kElevatedThreshold) { |
| 244 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_ELEVATED); | 269 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_ELEVATED); |
| 245 } else if (time_passed >= kLowThreshold) { | 270 } else if (time_passed >= kLowThreshold) { |
| 246 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); | 271 set_upgrade_notification_stage(UPGRADE_ANNOYANCE_LOW); |
| 247 } else { | 272 } else { |
| 248 return; // Not ready to recommend upgrade. | 273 return; // Not ready to recommend upgrade. |
| 249 } | 274 } |
| 250 } | 275 } |
| 251 | 276 |
| 252 NotifyUpgradeRecommended(); | 277 NotifyUpgradeRecommended(); |
| 253 } | 278 } |
| 254 | 279 |
| 255 // static | 280 // static |
| 256 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { | 281 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { |
| 257 return Singleton<UpgradeDetectorImpl>::get(); | 282 return Singleton<UpgradeDetectorImpl>::get(); |
| 258 } | 283 } |
| 259 | 284 |
| 260 // static | 285 // static |
| 261 UpgradeDetector* UpgradeDetector::GetInstance() { | 286 UpgradeDetector* UpgradeDetector::GetInstance() { |
| 262 return UpgradeDetectorImpl::GetInstance(); | 287 return UpgradeDetectorImpl::GetInstance(); |
| 263 } | 288 } |
| OLD | NEW |