Chromium Code Reviews| 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/bind.h" | |
| 9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 14 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 16 #include "base/task.h" | 17 #include "base/task.h" |
| 17 #include "base/time.h" | 18 #include "base/time.h" |
| 18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 return interval_ms * 1000; // Command line value is in seconds. | 61 return interval_ms * 1000; // Command line value is in seconds. |
| 61 | 62 |
| 62 return kCheckForUpgradeMs; | 63 return kCheckForUpgradeMs; |
| 63 } | 64 } |
| 64 | 65 |
| 65 // This task checks the currently running version of Chrome against the | 66 // This task checks the currently running version of Chrome against the |
| 66 // installed version. If the installed version is newer, it runs the passed | 67 // installed version. If the installed version is newer, it runs the passed |
| 67 // callback task. Otherwise it just deletes the task. | 68 // callback task. Otherwise it just deletes the task. |
| 68 class DetectUpgradeTask : public Task { | 69 class DetectUpgradeTask : public Task { |
| 69 public: | 70 public: |
| 70 DetectUpgradeTask(Task* upgrade_detected_task, | 71 DetectUpgradeTask(base::Closure upgrade_detected_task, |
|
James Hawkins
2011/11/16 22:31:36
const base::Closure&
csilv
2011/11/16 22:43:23
Done.
| |
| 71 bool* is_unstable_channel, | 72 bool* is_unstable_channel, |
| 72 bool* is_critical_upgrade) | 73 bool* is_critical_upgrade) |
| 73 : upgrade_detected_task_(upgrade_detected_task), | 74 : upgrade_detected_task_(upgrade_detected_task), |
| 74 is_unstable_channel_(is_unstable_channel), | 75 is_unstable_channel_(is_unstable_channel), |
| 75 is_critical_upgrade_(is_critical_upgrade) { | 76 is_critical_upgrade_(is_critical_upgrade) { |
| 76 } | 77 } |
| 77 | 78 |
| 78 virtual ~DetectUpgradeTask() { | 79 virtual ~DetectUpgradeTask() { |
| 79 if (upgrade_detected_task_) { | 80 if (!upgrade_detected_task_.is_null()) { |
| 80 // This has to get deleted on the same thread it was created. | 81 // This has to get deleted on the same thread it was created. |
| 81 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 82 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 82 new DeleteTask<Task>(upgrade_detected_task_)); | 83 upgrade_detected_task_); |
| 83 } | 84 } |
| 84 } | 85 } |
| 85 | 86 |
| 86 virtual void Run() { | 87 virtual void Run() { |
| 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 88 | 89 |
| 89 scoped_ptr<Version> installed_version; | 90 scoped_ptr<Version> installed_version; |
| 90 scoped_ptr<Version> critical_update; | 91 scoped_ptr<Version> critical_update; |
| 91 | 92 |
| 92 #if defined(OS_WIN) | 93 #if defined(OS_WIN) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 (installed_version->CompareTo(*running_version) > 0)) { | 154 (installed_version->CompareTo(*running_version) > 0)) { |
| 154 // If a more recent version is available, it might be that we are lacking | 155 // If a more recent version is available, it might be that we are lacking |
| 155 // a critical update, such as a zero-day fix. | 156 // a critical update, such as a zero-day fix. |
| 156 *is_critical_upgrade_ = | 157 *is_critical_upgrade_ = |
| 157 critical_update.get() && | 158 critical_update.get() && |
| 158 (critical_update->CompareTo(*running_version) > 0); | 159 (critical_update->CompareTo(*running_version) > 0); |
| 159 | 160 |
| 160 // Fire off the upgrade detected task. | 161 // Fire off the upgrade detected task. |
| 161 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 162 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 162 upgrade_detected_task_); | 163 upgrade_detected_task_); |
| 163 upgrade_detected_task_ = NULL; | 164 upgrade_detected_task_.Reset(); |
| 164 } | 165 } |
| 165 } | 166 } |
| 166 | 167 |
| 167 private: | 168 private: |
| 168 Task* upgrade_detected_task_; | 169 base::Closure upgrade_detected_task_; |
| 169 bool* is_unstable_channel_; | 170 bool* is_unstable_channel_; |
| 170 bool* is_critical_upgrade_; | 171 bool* is_critical_upgrade_; |
| 171 }; | 172 }; |
| 172 | 173 |
| 173 } // namespace | 174 } // namespace |
| 174 | 175 |
| 175 UpgradeDetectorImpl::UpgradeDetectorImpl() | 176 UpgradeDetectorImpl::UpgradeDetectorImpl() |
| 176 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 177 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 177 is_unstable_channel_(false) { | 178 is_unstable_channel_(false) { |
| 178 CommandLine command_line(*CommandLine::ForCurrentProcess()); | 179 CommandLine command_line(*CommandLine::ForCurrentProcess()); |
| 179 if (command_line.HasSwitch(switches::kDisableBackgroundNetworking)) | 180 if (command_line.HasSwitch(switches::kDisableBackgroundNetworking)) |
| 180 return; | 181 return; |
| 181 // Windows: only enable upgrade notifications for official builds. | 182 // Windows: only enable upgrade notifications for official builds. |
| 182 // Mac: only enable them if the updater (Keystone) is present. | 183 // Mac: only enable them if the updater (Keystone) is present. |
| 183 // Linux (and other POSIX): always enable regardless of branding. | 184 // Linux (and other POSIX): always enable regardless of branding. |
| 184 #if (defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)) || defined(OS_POSIX) | 185 #if (defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)) || defined(OS_POSIX) |
| 185 #if defined(OS_MACOSX) | 186 #if defined(OS_MACOSX) |
| 186 if (keystone_glue::KeystoneEnabled()) | 187 if (keystone_glue::KeystoneEnabled()) |
| 187 #endif | 188 #endif |
| 188 { | 189 { |
| 189 detect_upgrade_timer_.Start(FROM_HERE, | 190 detect_upgrade_timer_.Start(FROM_HERE, |
| 190 base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()), | 191 base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()), |
| 191 this, &UpgradeDetectorImpl::CheckForUpgrade); | 192 this, &UpgradeDetectorImpl::CheckForUpgrade); |
| 192 } | 193 } |
| 193 #endif | 194 #endif |
| 194 } | 195 } |
| 195 | 196 |
| 196 UpgradeDetectorImpl::~UpgradeDetectorImpl() { | 197 UpgradeDetectorImpl::~UpgradeDetectorImpl() { |
| 197 } | 198 } |
| 198 | 199 |
| 199 void UpgradeDetectorImpl::CheckForUpgrade() { | 200 void UpgradeDetectorImpl::CheckForUpgrade() { |
| 200 method_factory_.RevokeAll(); | 201 weak_factory_.InvalidateWeakPtrs(); |
| 201 Task* callback_task = | 202 base::Closure callback_task = |
| 202 method_factory_.NewRunnableMethod(&UpgradeDetectorImpl::UpgradeDetected); | 203 base::Bind(&UpgradeDetectorImpl::UpgradeDetected, |
| 204 weak_factory_.GetWeakPtr()); | |
| 203 // We use FILE as the thread to run the upgrade detection code on all | 205 // We use FILE as the thread to run the upgrade detection code on all |
| 204 // platforms. For Linux, this is because we don't want to block the UI thread | 206 // platforms. For Linux, this is because we don't want to block the UI thread |
| 205 // while launching a background process and reading its output; on the Mac and | 207 // while launching a background process and reading its output; on the Mac and |
| 206 // on Windows checking for an upgrade requires reading a file. | 208 // on Windows checking for an upgrade requires reading a file. |
| 207 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 209 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 208 new DetectUpgradeTask(callback_task, | 210 new DetectUpgradeTask(callback_task, |
| 209 &is_unstable_channel_, | 211 &is_unstable_channel_, |
| 210 &is_critical_upgrade_)); | 212 &is_critical_upgrade_)); |
| 211 } | 213 } |
| 212 | 214 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 | 288 |
| 287 // static | 289 // static |
| 288 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { | 290 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { |
| 289 return Singleton<UpgradeDetectorImpl>::get(); | 291 return Singleton<UpgradeDetectorImpl>::get(); |
| 290 } | 292 } |
| 291 | 293 |
| 292 // static | 294 // static |
| 293 UpgradeDetector* UpgradeDetector::GetInstance() { | 295 UpgradeDetector* UpgradeDetector::GetInstance() { |
| 294 return UpgradeDetectorImpl::GetInstance(); | 296 return UpgradeDetectorImpl::GetInstance(); |
| 295 } | 297 } |
| OLD | NEW |