Chromium Code Reviews| Index: chrome/browser/component_updater/cros_component_installer.h |
| diff --git a/chrome/browser/component_updater/cros_component_installer.h b/chrome/browser/component_updater/cros_component_installer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a9230864ae5da003803053267eb9ea65114912e4 |
| --- /dev/null |
| +++ b/chrome/browser/component_updater/cros_component_installer.h |
| @@ -0,0 +1,127 @@ |
| +// Copyright (c) 2012 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. |
| +#ifndef CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ |
| +#define CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ |
| + |
| +#include "base/base_paths.h" |
| +#include "base/bind.h" |
| +#include "base/command_line.h" |
| +#include "base/files/file_enumerator.h" |
| +#include "base/files/file_path.h" |
| +#include "base/files/file_util.h" |
| +#include "base/json/json_file_value_serializer.h" |
| +#include "base/json/json_reader.h" |
| +#include "base/logging.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "base/path_service.h" |
| +#include "base/stl_util.h" |
| +#include "base/strings/string_util.h" |
| +#include "base/strings/stringprintf.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "base/version.h" |
| +#include "build/build_config.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/component_updater/component_installer_errors.h" |
| +#include "chrome/browser/component_updater/cros_component_installer.h" |
| +#include "chrome/browser/plugins/plugin_prefs.h" |
| +#include "chrome/common/chrome_constants.h" |
| +#include "chrome/common/chrome_content_client.h" |
| +#include "chrome/common/chrome_paths.h" |
| +#include "chrome/common/chrome_switches.h" |
| +#include "components/component_updater/component_updater_service.h" |
| +#include "components/component_updater/default_component_installer.h" |
| +#include "components/update_client/update_client.h" |
| +#include "components/update_client/update_client_errors.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/plugin_service.h" |
| +#include "content/public/common/content_constants.h" |
| +#include "crypto/sha2.h" |
| +#include "third_party/libxml/chromium/libxml_utils.h" |
| + |
| +#if defined(OS_CHROMEOS) |
| +#include "chrome/browser/chromeos/settings/cros_settings.h" |
| +#include "chrome/browser/ui/ash/system_tray_client.h" |
| +#include "chrome/common/chrome_features.h" |
| +#include "chromeos/dbus/dbus_method_call_status.h" |
| +#include "chromeos/dbus/dbus_thread_manager.h" |
| +#include "chromeos/dbus/image_loader_client.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#elif defined(OS_LINUX) |
| +#include "chrome/common/component_flash_hint_file_linux.h" |
| +#endif // defined(OS_CHROMEOS) |
| + |
| +namespace component_updater { |
| + |
| +static const char componentConfigReaderFilepathstr[] = |
| + "/etc/cros_component.config"; |
| +static std::unique_ptr<base::Value> componentConfigReaderRoot = nullptr; |
| + |
| +class ComponentUpdateService; |
| + |
| +struct ComponentConfig { |
| + std::string name; |
| + std::string dir; |
| + std::string sha2hashstr; |
| +}; |
| +class CrOSComponentInstallerTraits : public ComponentInstallerTraits { |
| + public: |
| + CrOSComponentInstallerTraits(std::string dir_name, |
| + std::string name, |
| + std::string sha2HashStr); |
| + ~CrOSComponentInstallerTraits() override {} |
| + |
| + private: |
| + // The following methods override ComponentInstallerTraits. |
| + bool SupportsGroupPolicyEnabledComponentUpdates() const override; |
| + bool RequiresNetworkEncryption() const override; |
| + update_client::CrxInstaller::Result OnCustomInstall( |
| + const base::DictionaryValue& manifest, |
| + const base::FilePath& install_dir) override; |
| + bool VerifyInstallation(const base::DictionaryValue& manifest, |
| + const base::FilePath& install_dir) const override; |
| + void ComponentReady(const base::Version& version, |
| + const base::FilePath& path, |
| + std::unique_ptr<base::DictionaryValue> manifest) override; |
| + base::FilePath GetRelativeInstallDir() const override; |
| + void GetHash(std::vector<uint8_t>* hash) const override; |
| + std::string GetName() const override; |
| + update_client::InstallerAttributes GetInstallerAttributes() const override; |
| + std::vector<std::string> GetMimeTypes() const override; |
| + std::string dir_name; |
| + std::string name; |
| + uint8_t kSha2Hash_[crypto::kSHA256Length] = {}; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CrOSComponentInstallerTraits); |
| +}; |
| + |
| +void RegisterCrOSComponentInternal(ComponentUpdateService* cus, |
| + ComponentConfig& config); |
|
waffles
2017/02/28 17:37:21
Is it necessary to declare this in the header? I s
xiaochu
2017/02/28 23:20:33
Done.
|
| + |
| +// We provide two options for developers to register a Chrome OS Component at |
| +// anytime: |
| +// (1) use a TaskRunner to asynchroniously register a component. You can use |
| +// this option in either UI thread or any other threads. |
| +// |
| +// scoped_refptr<base::SequencedTaskRunner> blocking_task_runner; |
| +// blocking_task_runner->PostTaskAndReply( |
| +// FROM_HERE, base::Bind(&LoadCrOSConfig, |
| +// base::Unretained(this)), |
| +// base::Bind(&RegisterCrOSComponent), |
| +// base::Unretained(this), |
| +// "component_name_to_update"); |
|
waffles
2017/02/28 17:37:21
Could this logic be moved into RegisterCrOSCompone
xiaochu
2017/02/28 23:20:33
Done.
|
| +bool RegisterCrOSComponent(ComponentUpdateService* cus, std::string name); |
| + |
| +// load configuration file from disk into memory variable |
| +// comopnentConfigReaderRoot; load only when call the first time, first call |
|
waffles
2017/02/28 17:37:21
when call → when called
xiaochu
2017/02/28 23:20:33
replaced.
|
| +// result is cached for later call use. |
| +void LoadCrOSConfig(); |
| + |
| +// (2) register a Chrome OS component synchronously. Please do not call this in |
| +// UI thread since it potentially loads a file from disk (even only once across |
| +// all calls). |
| +bool RegisterCrOSComponentIO(ComponentUpdateService* cus, std::string name); |
| + |
| +} // namespace component_updater |
| + |
| +#endif // CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ |