OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 69 } |
70 | 70 |
71 // This task checks the currently running version of Chrome against the | 71 // This task checks the currently running version of Chrome against the |
72 // installed version. If the installed version is newer, it runs the passed | 72 // installed version. If the installed version is newer, it runs the passed |
73 // callback task. Otherwise it just deletes the task. | 73 // callback task. Otherwise it just deletes the task. |
74 void DetectUpgradeTask(const base::Closure& upgrade_detected_task, | 74 void DetectUpgradeTask(const base::Closure& upgrade_detected_task, |
75 bool* is_unstable_channel, | 75 bool* is_unstable_channel, |
76 bool* is_critical_upgrade) { | 76 bool* is_critical_upgrade) { |
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
78 | 78 |
79 scoped_ptr<Version> installed_version; | 79 Version installed_version; |
80 scoped_ptr<Version> critical_update; | 80 Version critical_update; |
81 | 81 |
82 #if defined(OS_WIN) | 82 #if defined(OS_WIN) |
83 // Get the version of the currently *installed* instance of Chrome, | 83 // Get the version of the currently *installed* instance of Chrome, |
84 // which might be newer than the *running* instance if we have been | 84 // which might be newer than the *running* instance if we have been |
85 // upgraded in the background. | 85 // upgraded in the background. |
86 FilePath exe_path; | 86 FilePath exe_path; |
87 if (!PathService::Get(base::DIR_EXE, &exe_path)) { | 87 if (!PathService::Get(base::DIR_EXE, &exe_path)) { |
88 NOTREACHED() << "Failed to find executable path"; | 88 NOTREACHED() << "Failed to find executable path"; |
89 return; | 89 return; |
90 } | 90 } |
91 | 91 |
92 bool system_install = | 92 bool system_install = |
93 !InstallUtil::IsPerUserInstall(exe_path.value().c_str()); | 93 !InstallUtil::IsPerUserInstall(exe_path.value().c_str()); |
94 | 94 |
95 // TODO(tommi): Check if using the default distribution is always the right | 95 // TODO(tommi): Check if using the default distribution is always the right |
96 // thing to do. | 96 // thing to do. |
97 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 97 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
98 installed_version.reset(InstallUtil::GetChromeVersion(dist, | 98 InstallUtil::GetChromeVersion(dist, system_install, &installed_version); |
99 system_install)); | |
100 | 99 |
101 if (installed_version.get()) { | 100 if (installed_version.IsValid()) { |
102 critical_update.reset( | 101 InstallUtil::GetCriticalUpdateVersion(dist, system_install, |
103 InstallUtil::GetCriticalUpdateVersion(dist, system_install)); | 102 &critical_update); |
104 } | 103 } |
105 #elif defined(OS_MACOSX) | 104 #elif defined(OS_MACOSX) |
106 installed_version.reset( | 105 installed_version = |
107 Version::GetVersionFromString(UTF16ToASCII( | 106 Version(UTF16ToASCII(keystone_glue::CurrentlyInstalledVersion())); |
108 keystone_glue::CurrentlyInstalledVersion()))); | |
109 #elif defined(OS_POSIX) | 107 #elif defined(OS_POSIX) |
110 // POSIX but not Mac OS X: Linux, etc. | 108 // POSIX but not Mac OS X: Linux, etc. |
111 CommandLine command_line(*CommandLine::ForCurrentProcess()); | 109 CommandLine command_line(*CommandLine::ForCurrentProcess()); |
112 command_line.AppendSwitch(switches::kProductVersion); | 110 command_line.AppendSwitch(switches::kProductVersion); |
113 std::string reply; | 111 std::string reply; |
114 if (!base::GetAppOutput(command_line, &reply)) { | 112 if (!base::GetAppOutput(command_line, &reply)) { |
115 DLOG(ERROR) << "Failed to get current file version"; | 113 DLOG(ERROR) << "Failed to get current file version"; |
116 return; | 114 return; |
117 } | 115 } |
118 | 116 |
119 installed_version.reset(Version::GetVersionFromString(reply)); | 117 installed_version = Version(reply); |
120 #endif | 118 #endif |
121 | 119 |
122 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 120 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
123 *is_unstable_channel = channel == chrome::VersionInfo::CHANNEL_DEV || | 121 *is_unstable_channel = channel == chrome::VersionInfo::CHANNEL_DEV || |
124 channel == chrome::VersionInfo::CHANNEL_CANARY; | 122 channel == chrome::VersionInfo::CHANNEL_CANARY; |
125 | 123 |
126 // Get the version of the currently *running* instance of Chrome. | 124 // Get the version of the currently *running* instance of Chrome. |
127 chrome::VersionInfo version_info; | 125 chrome::VersionInfo version_info; |
128 if (!version_info.is_valid()) { | 126 if (!version_info.is_valid()) { |
129 NOTREACHED() << "Failed to get current file version"; | 127 NOTREACHED() << "Failed to get current file version"; |
130 return; | 128 return; |
131 } | 129 } |
132 scoped_ptr<Version> running_version( | 130 Version running_version(version_info.Version()); |
133 Version::GetVersionFromString(version_info.Version())); | 131 if (!running_version.IsValid()) { |
134 if (running_version.get() == NULL) { | 132 NOTREACHED(); |
135 NOTREACHED() << "Failed to parse version info"; | |
136 return; | 133 return; |
137 } | 134 } |
138 | 135 |
139 // |installed_version| may be NULL when the user downgrades on Linux (by | 136 // |installed_version| may be NULL when the user downgrades on Linux (by |
140 // switching from dev to beta channel, for example). The user needs a | 137 // switching from dev to beta channel, for example). The user needs a |
141 // restart in this case as well. See http://crbug.com/46547 | 138 // restart in this case as well. See http://crbug.com/46547 |
142 if (!installed_version.get() || | 139 if (!installed_version.IsValid() || |
143 (installed_version->CompareTo(*running_version) > 0)) { | 140 (installed_version.CompareTo(running_version) > 0)) { |
144 // If a more recent version is available, it might be that we are lacking | 141 // If a more recent version is available, it might be that we are lacking |
145 // a critical update, such as a zero-day fix. | 142 // a critical update, such as a zero-day fix. |
146 *is_critical_upgrade = | 143 *is_critical_upgrade = |
147 critical_update.get() && | 144 critical_update.IsValid() && |
148 (critical_update->CompareTo(*running_version) > 0); | 145 (critical_update.CompareTo(running_version) > 0); |
149 | 146 |
150 // Fire off the upgrade detected task. | 147 // Fire off the upgrade detected task. |
151 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 148 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
152 upgrade_detected_task); | 149 upgrade_detected_task); |
153 } | 150 } |
154 } | 151 } |
155 | 152 |
156 } // namespace | 153 } // namespace |
157 | 154 |
158 UpgradeDetectorImpl::UpgradeDetectorImpl() | 155 UpgradeDetectorImpl::UpgradeDetectorImpl() |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 270 |
274 // static | 271 // static |
275 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { | 272 UpgradeDetectorImpl* UpgradeDetectorImpl::GetInstance() { |
276 return Singleton<UpgradeDetectorImpl>::get(); | 273 return Singleton<UpgradeDetectorImpl>::get(); |
277 } | 274 } |
278 | 275 |
279 // static | 276 // static |
280 UpgradeDetector* UpgradeDetector::GetInstance() { | 277 UpgradeDetector* UpgradeDetector::GetInstance() { |
281 return UpgradeDetectorImpl::GetInstance(); | 278 return UpgradeDetectorImpl::GetInstance(); |
282 } | 279 } |
OLD | NEW |