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

Side by Side Diff: extensions/browser/updater/update_data_provider.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_data_provider.h"
6
7 #include "base/base64.h"
8 #include "base/bind.h"
9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
11 #include "base/stl_util.h"
12 #include "base/strings/string_util.h"
13 #include "components/update_client/update_client.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "crypto/sha2.h"
16 #include "extensions/browser/content_verifier.h"
17 #include "extensions/browser/extension_registry.h"
18 #include "extensions/browser/extension_system.h"
19 #include "extensions/browser/updater/update_install_shim.h"
20 #include "extensions/common/extension.h"
21
22 namespace extensions {
23
24 UpdateDataProvider::UpdateDataProvider(content::BrowserContext* context,
25 const InstallCallback& callback)
26 : context_(context), callback_(callback) {}
27
28 UpdateDataProvider::~UpdateDataProvider() {}
29
30 void UpdateDataProvider::Shutdown() {
31 context_ = nullptr;
32 }
33
34 void UpdateDataProvider::GetData(
35 const std::vector<std::string>& ids,
36 std::vector<update_client::CrxComponent>* data) {
37 if (!context_)
38 return;
39 const ExtensionRegistry* registry = ExtensionRegistry::Get(context_);
40 for (const auto& id : ids) {
41 const Extension* extension = registry->GetInstalledExtension(id);
42 if (!extension)
43 continue;
44 data->push_back(update_client::CrxComponent());
45 update_client::CrxComponent* info = &data->back();
46 std::string pubkey_bytes;
47 base::Base64Decode(extension->public_key(), &pubkey_bytes);
48 info->pk_hash.resize(crypto::kSHA256Length, 0);
49 crypto::SHA256HashString(pubkey_bytes, vector_as_array(&info->pk_hash),
50 info->pk_hash.size());
51 info->version = *extension->version();
52 info->allow_background_download = false;
53
54 info->installer = new UpdateInstallShim(
55 id, extension->path(),
56 base::Bind(&UpdateDataProvider::RunInstallCallback, this));
57 }
58 }
59
60 void UpdateDataProvider::RunInstallCallback(const std::string& extension_id,
61 const base::FilePath& temp_dir) {
62 if (!context_) {
63 content::BrowserThread::PostBlockingPoolTask(
64 FROM_HERE,
65 base::Bind(base::IgnoreResult(&base::DeleteFile), temp_dir, false));
66 return;
67 } else {
68 callback_.Run(context_, extension_id, temp_dir);
69 }
70 }
71
72 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/updater/update_data_provider.h ('k') | extensions/browser/updater/update_install_shim.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698