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..859504ab92791c9d67a816c7cfffafda347ac974 |
--- /dev/null |
+++ b/chrome/browser/component_updater/cros_component_installer.h |
@@ -0,0 +1,149 @@ |
+// 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_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 { |
+ |
+class ComponentUpdateService; |
+class ConfigParser { |
+ public: |
+ struct Result { |
+ std::string name; |
+ std::string dir_name; |
+ std::string sha2hashstr; |
+ }; |
+ // an example config_xml: |
+ // <components> |
+ // <component name='cups' dir_name='cups'></component> |
+ // <component name='samba' dir_name='samba'></component> |
waffles
2017/02/21 21:16:04
The sha256 hash of the public key must also appear
xiaochu
2017/02/21 21:39:40
Done.
|
+ // </components> |
waffles
2017/02/21 21:16:04
Can we use JSON or protocol buffers instead? XML i
waffles
2017/02/21 21:39:25
...so is that a "no"?
xiaochu
2017/02/21 21:39:40
I agree.
I created another issue here (https://bug
waffles
2017/02/21 21:52:13
I suggest switching now, since there's no reason t
|
+ bool Parse(std::string config_xml, std::vector<Result>& results); |
+ std::string getErrors() { return errors_; } |
+ |
+ private: |
+ // Utility class for cleaning up the xml document when leaving a scope. |
+ class ScopedXmlDocument { |
+ public: |
+ explicit ScopedXmlDocument(xmlDocPtr document) : document_(document) {} |
+ ~ScopedXmlDocument() { |
+ if (document_) |
+ xmlFreeDoc(document_); |
+ } |
+ xmlDocPtr get() { return document_; } |
+ |
+ private: |
+ xmlDocPtr document_; |
+ }; |
+ // This is used for the xml parser to report errors. This assumes the context |
+ // is a pointer to a std::string where the error message should be appended. |
+ static void XmlErrorFunc(void* context, const char* message, ...); |
+ static bool TagNameEquals(const xmlNode* node, const char* expected_name); |
+ |
+ bool IsValidSha256(const std::string& sha2HashStr); |
+ // Returns the value of a named attribute, or nullptr . |
+ static std::unique_ptr<std::string> GetAttributePtr( |
+ xmlNode* node, |
+ const char* attribute_name); |
+ |
+ void ParseError(const char* details, ...); |
+ |
+ bool ParseComponentTag(xmlNode* component, |
+ Result* result, |
+ std::string* error); |
+ |
+ // Returns child nodes of |root| with name |name|. |
+ static std::vector<xmlNode*> GetChildren(xmlNode* root, const char* name); |
+ |
+ std::string errors_; |
+}; // class ConfigParser |
+ |
+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 RegisterCrOSComponent(ComponentUpdateService* cus, |
+ ConfigParser::Result& result); |
+bool RegisterCrOSComponent(ComponentUpdateService* cus, std::string name); |
+ |
+bool InstallCrOSComponent(std::string name); |
+ |
+bool IsReadyCrOSComponent(std::string name); |
+ |
+} // namespace component_updater |
+ |
+#endif // CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ |