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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "extensions/browser/updater/update_install_shim.h"
6
7 #include "base/files/file_enumerator.h"
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/logging.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/values.h"
14 #include "content/public/browser/browser_thread.h"
15
16 namespace extensions {
17
18 UpdateInstallShim::UpdateInstallShim(std::string extension_id,
19 const base::FilePath& extension_root,
20 const UpdateInstallShimCallback& callback)
21 : extension_id_(extension_id),
22 extension_root_(extension_root),
23 callback_(callback) {}
24
25 void UpdateInstallShim::OnUpdateError(int error) {
26 VLOG(1) << "OnUpdateError (" << extension_id_ << ") " << error;
27 }
28
29 bool UpdateInstallShim::Install(const base::DictionaryValue& manifest,
30 const base::FilePath& unpack_path) {
31 base::ScopedTempDir temp_dir;
32 if (!temp_dir.CreateUniqueTempDir())
33 return false;
34
35 // The UpdateClient code will delete unpack_path if it still exists after
36 // this method is done, so we rename it on top of our temp dir.
37 if (!base::DeleteFile(temp_dir.path(), true) ||
38 !base::Move(unpack_path, temp_dir.path())) {
39 LOG(ERROR) << "Trying to install update for " << extension_id_
40 << "and failed to move " << unpack_path.value() << " to "
41 << temp_dir.path().value();
42 return false;
43 }
44 content::BrowserThread::PostTask(
45 content::BrowserThread::UI, FROM_HERE,
46 base::Bind(&UpdateInstallShim::RunCallbackOnUIThread, this,
47 temp_dir.Take()));
48 return true;
49 }
50
51 bool UpdateInstallShim::GetInstalledFile(const std::string& file,
52 base::FilePath* installed_file) {
53 base::FilePath relative_path = base::FilePath::FromUTF8Unsafe(file);
54 if (relative_path.IsAbsolute() || relative_path.ReferencesParent())
55 return false;
56 *installed_file = extension_root_.Append(relative_path);
57 if (!extension_root_.IsParent(*installed_file) ||
58 !base::PathExists(*installed_file)) {
59 VLOG(1) << "GetInstalledFile failed to find " << installed_file->value();
60 installed_file->clear();
61 return false;
62 }
63 return true;
64 }
65
66 bool UpdateInstallShim::Uninstall() {
67 NOTREACHED();
68 return false;
69 }
70
71 UpdateInstallShim::~UpdateInstallShim() {}
72
73 void UpdateInstallShim::RunCallbackOnUIThread(const base::FilePath& temp_dir) {
74 if (callback_.is_null()) {
75 content::BrowserThread::PostBlockingPoolTask(
76 FROM_HERE, base::Bind(base::IgnoreResult(&base::DeleteFile), temp_dir,
77 true /*recursive */));
78 return;
79 }
80 callback_.Run(extension_id_, temp_dir);
81 }
82
83 } // namespace extensions
OLDNEW
« 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