Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: chrome/browser/extensions/crx_installer.cc

Issue 174036: Get rid of the extension's "Current Version" file. (Closed)
Patch Set: merge conflicts Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/extensions/crx_installer.h" 5 #include "chrome/browser/extensions/crx_installer.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 DCHECK(MessageLoop::current() == ui_loop_); 164 DCHECK(MessageLoop::current() == ui_loop_);
165 if (frontend_->extension_prefs()->IsExtensionBlacklisted(extension_->id())) { 165 if (frontend_->extension_prefs()->IsExtensionBlacklisted(extension_->id())) {
166 LOG(INFO) << "This extension: " << extension_->id() 166 LOG(INFO) << "This extension: " << extension_->id()
167 << " is blacklisted. Install failed."; 167 << " is blacklisted. Install failed.";
168 if (client_.get()) { 168 if (client_.get()) {
169 client_->OnInstallFailure("This extension is blacklisted."); 169 client_->OnInstallFailure("This extension is blacklisted.");
170 } 170 }
171 return; 171 return;
172 } 172 }
173 173
174 current_version_ =
175 frontend_->extension_prefs()->GetVersionString(extension_->id());
176
174 if (client_.get()) { 177 if (client_.get()) {
175 AddRef(); // balanced in ContinueInstall() and AbortInstall(). 178 AddRef(); // balanced in ContinueInstall() and AbortInstall().
176 client_->ConfirmInstall(this, extension_.get(), install_icon_.get()); 179 client_->ConfirmInstall(this, extension_.get(), install_icon_.get());
177 } else { 180 } else {
178 file_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 181 file_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
179 &CrxInstaller::CompleteInstall)); 182 &CrxInstaller::CompleteInstall));
180 } 183 }
181 return; 184 return;
182 } 185 }
183 186
184 void CrxInstaller::ContinueInstall() { 187 void CrxInstaller::ContinueInstall() {
185 file_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 188 file_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
186 &CrxInstaller::CompleteInstall)); 189 &CrxInstaller::CompleteInstall));
187 190
188 Release(); // balanced in ConfirmInstall(). 191 Release(); // balanced in ConfirmInstall().
189 } 192 }
190 193
191 void CrxInstaller::AbortInstall() { 194 void CrxInstaller::AbortInstall() {
192 Release(); // balanced in ConfirmInstall(). 195 Release(); // balanced in ConfirmInstall().
193 196
194 // We're done. Since we don't post any more tasks to ourself, our ref count 197 // We're done. Since we don't post any more tasks to ourself, our ref count
195 // should go to zero and we die. The destructor will clean up the temp dir. 198 // should go to zero and we die. The destructor will clean up the temp dir.
196 } 199 }
197 200
198 void CrxInstaller::CompleteInstall() { 201 void CrxInstaller::CompleteInstall() {
199 DCHECK(MessageLoop::current() == file_loop_); 202 DCHECK(MessageLoop::current() == file_loop_);
200 203
201 FilePath version_dir; 204 FilePath version_dir;
202 Extension::InstallType install_type = Extension::INSTALL_ERROR; 205 Extension::InstallType install_type =
203 std::string error_msg; 206 extension_file_util::CompareToInstalledVersion(
204 if (!extension_file_util::InstallExtension(unpacked_extension_root_, 207 install_directory_, extension_->id(), current_version_,
205 install_directory_, 208 extension_->VersionString(), &version_dir);
206 extension_->id(),
207 extension_->VersionString(),
208 &version_dir,
209 &install_type, &error_msg)) {
210 ReportFailureFromFileThread(error_msg);
211 return;
212 }
213 209
214 if (install_type == Extension::DOWNGRADE) { 210 if (install_type == Extension::DOWNGRADE) {
215 ReportFailureFromFileThread("Attempted to downgrade extension."); 211 ReportFailureFromFileThread("Attempted to downgrade extension.");
216 return; 212 return;
217 } 213 }
218 214
219 if (install_type == Extension::REINSTALL) { 215 if (install_type == Extension::REINSTALL) {
220 // We use this as a signal to switch themes. 216 // We use this as a signal to switch themes.
221 ReportOverinstallFromFileThread(); 217 ReportOverinstallFromFileThread();
222 return; 218 return;
223 } 219 }
224 220
221 std::string error_msg;
222 if (!extension_file_util::InstallExtension(unpacked_extension_root_,
223 version_dir, &error_msg)) {
224 ReportFailureFromFileThread(error_msg);
225 return;
226 }
227
225 // This is lame, but we must reload the extension because absolute paths 228 // This is lame, but we must reload the extension because absolute paths
226 // inside the content scripts are established inside InitFromValue() and we 229 // inside the content scripts are established inside InitFromValue() and we
227 // just moved the extension. 230 // just moved the extension.
228 // TODO(aa): All paths to resources inside extensions should be created 231 // TODO(aa): All paths to resources inside extensions should be created
229 // lazily and based on the Extension's root path at that moment. 232 // lazily and based on the Extension's root path at that moment.
230 std::string error; 233 std::string error;
231 extension_.reset(extension_file_util::LoadExtension(version_dir, true, 234 extension_.reset(extension_file_util::LoadExtension(version_dir, true,
232 &error)); 235 &error));
233 DCHECK(error.empty()); 236 DCHECK(error.empty());
234 extension_->set_location(install_source_); 237 extension_->set_location(install_source_);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 if (client_.get()) 287 if (client_.get())
285 client_->OnInstallSuccess(extension_.get()); 288 client_->OnInstallSuccess(extension_.get());
286 289
287 // Tell the frontend about the installation and hand off ownership of 290 // Tell the frontend about the installation and hand off ownership of
288 // extension_ to it. 291 // extension_ to it.
289 frontend_->OnExtensionInstalled(extension_.release()); 292 frontend_->OnExtensionInstalled(extension_.release());
290 293
291 // We're done. We don't post any more tasks to ourselves so we are deleted 294 // We're done. We don't post any more tasks to ourselves so we are deleted
292 // soon. 295 // soon.
293 } 296 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer.h ('k') | chrome/browser/extensions/extension_file_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698