Chromium Code Reviews| Index: extensions/browser/updater/update_data_provider.cc |
| diff --git a/extensions/browser/updater/update_data_provider.cc b/extensions/browser/updater/update_data_provider.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5969b96f77b34b069ccdbe982dfd0ac45c8107d8 |
| --- /dev/null |
| +++ b/extensions/browser/updater/update_data_provider.cc |
| @@ -0,0 +1,72 @@ |
| +// 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_data_provider.h" |
| + |
| +#include "base/base64.h" |
| +#include "base/bind.h" |
| +#include "base/files/file_path.h" |
| +#include "base/files/file_util.h" |
| +#include "base/stl_util.h" |
| +#include "base/strings/string_util.h" |
| +#include "components/update_client/update_client.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "crypto/sha2.h" |
| +#include "extensions/browser/content_verifier.h" |
| +#include "extensions/browser/extension_registry.h" |
| +#include "extensions/browser/extension_system.h" |
| +#include "extensions/browser/updater/update_install_shim.h" |
| +#include "extensions/common/extension.h" |
| + |
| +namespace extensions { |
| + |
| +UpdateDataProvider::UpdateDataProvider(content::BrowserContext* context, |
| + const InstallCallback& callback) |
| + : context_(context), callback_(callback) {} |
| + |
| +UpdateDataProvider::~UpdateDataProvider() {} |
| + |
| +void UpdateDataProvider::Shutdown() { |
| + context_ = nullptr; |
| +} |
| + |
| +void UpdateDataProvider::GetData( |
| + const std::vector<std::string>& ids, |
| + std::vector<update_client::CrxComponent>* data) { |
| + if (!context_) |
| + return; |
| + ExtensionRegistry* registry = ExtensionRegistry::Get(context_); |
|
Sorin Jianu
2015/10/02 00:05:10
can this be const?
asargent_no_longer_on_chrome
2015/10/06 21:31:17
Done.
|
| + for (const auto& id : ids) { |
| + const Extension* extension = registry->GetInstalledExtension(id); |
| + if (!extension) |
| + continue; |
| + data->push_back(update_client::CrxComponent()); |
| + update_client::CrxComponent* info = &data->back(); |
|
Sorin Jianu
2015/10/02 00:05:10
is 44-45 an optimization to avoid a copy?
asargent_no_longer_on_chrome
2015/10/06 21:31:17
Yes.
|
| + std::string pubkey_bytes; |
| + base::Base64Decode(extension->public_key(), &pubkey_bytes); |
| + info->pk_hash.resize(crypto::kSHA256Length, 0); |
| + crypto::SHA256HashString(pubkey_bytes, vector_as_array(&info->pk_hash), |
| + info->pk_hash.size()); |
| + info->version = *extension->version(); |
| + info->allow_background_download = false; |
| + |
| + info->installer = new UpdateInstallShim( |
| + id, extension->path(), |
| + base::Bind(&UpdateDataProvider::RunInstallCallback, this)); |
| + } |
| +} |
| + |
| +void UpdateDataProvider::RunInstallCallback(const std::string& extension_id, |
| + const base::FilePath& temp_dir) { |
| + if (!context_) { |
| + content::BrowserThread::PostBlockingPoolTask( |
| + FROM_HERE, |
| + base::Bind(base::IgnoreResult(&base::DeleteFile), temp_dir, false)); |
| + return; |
| + } else { |
| + callback_.Run(context_, extension_id, temp_dir); |
| + } |
| +} |
| + |
| +} // namespace extensions |