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

Unified Diff: extensions/browser/updater/update_install_shim.cc

Issue 1362043005: Add extensions code to use common updater in components/update_client/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merged latest origin/master Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/updater/update_install_shim.h ('k') | extensions/browser/updater/update_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/updater/update_install_shim.cc
diff --git a/extensions/browser/updater/update_install_shim.cc b/extensions/browser/updater/update_install_shim.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4b6f58294aab5720e81839c0dc90c9363f591e60
--- /dev/null
+++ b/extensions/browser/updater/update_install_shim.cc
@@ -0,0 +1,83 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/browser/updater/update_install_shim.h"
+
+#include "base/files/file_enumerator.h"
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/logging.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/values.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace extensions {
+
+UpdateInstallShim::UpdateInstallShim(std::string extension_id,
+ const base::FilePath& extension_root,
+ const UpdateInstallShimCallback& callback)
+ : extension_id_(extension_id),
+ extension_root_(extension_root),
+ callback_(callback) {}
+
+void UpdateInstallShim::OnUpdateError(int error) {
+ VLOG(1) << "OnUpdateError (" << extension_id_ << ") " << error;
+}
+
+bool UpdateInstallShim::Install(const base::DictionaryValue& manifest,
+ const base::FilePath& unpack_path) {
+ base::ScopedTempDir temp_dir;
+ if (!temp_dir.CreateUniqueTempDir())
+ return false;
+
+ // The UpdateClient code will delete unpack_path if it still exists after
+ // this method is done, so we rename it on top of our temp dir.
+ if (!base::DeleteFile(temp_dir.path(), true) ||
+ !base::Move(unpack_path, temp_dir.path())) {
+ LOG(ERROR) << "Trying to install update for " << extension_id_
+ << "and failed to move " << unpack_path.value() << " to "
+ << temp_dir.path().value();
+ return false;
+ }
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&UpdateInstallShim::RunCallbackOnUIThread, this,
+ temp_dir.Take()));
+ return true;
+}
+
+bool UpdateInstallShim::GetInstalledFile(const std::string& file,
+ base::FilePath* installed_file) {
+ base::FilePath relative_path = base::FilePath::FromUTF8Unsafe(file);
+ if (relative_path.IsAbsolute() || relative_path.ReferencesParent())
+ return false;
+ *installed_file = extension_root_.Append(relative_path);
+ if (!extension_root_.IsParent(*installed_file) ||
+ !base::PathExists(*installed_file)) {
+ VLOG(1) << "GetInstalledFile failed to find " << installed_file->value();
+ installed_file->clear();
+ return false;
+ }
+ return true;
+}
+
+bool UpdateInstallShim::Uninstall() {
+ NOTREACHED();
+ return false;
+}
+
+UpdateInstallShim::~UpdateInstallShim() {}
+
+void UpdateInstallShim::RunCallbackOnUIThread(const base::FilePath& temp_dir) {
+ if (callback_.is_null()) {
+ content::BrowserThread::PostBlockingPoolTask(
+ FROM_HERE, base::Bind(base::IgnoreResult(&base::DeleteFile), temp_dir,
+ true /*recursive */));
+ return;
+ }
+ callback_.Run(extension_id_, temp_dir);
+}
+
+} // namespace extensions
« no previous file with comments | « extensions/browser/updater/update_install_shim.h ('k') | extensions/browser/updater/update_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698