OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ | |
5 #define CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ | |
6 | |
7 #include "base/base_paths.h" | |
8 #include "base/bind.h" | |
9 #include "base/command_line.h" | |
10 #include "base/files/file_enumerator.h" | |
11 #include "base/files/file_path.h" | |
12 #include "base/files/file_util.h" | |
13 #include "base/json/json_reader.h" | |
14 #include "base/logging.h" | |
15 #include "base/memory/ptr_util.h" | |
16 #include "base/path_service.h" | |
17 #include "base/stl_util.h" | |
18 #include "base/strings/string_util.h" | |
19 #include "base/strings/stringprintf.h" | |
20 #include "base/strings/utf_string_conversions.h" | |
21 #include "base/version.h" | |
22 #include "build/build_config.h" | |
23 #include "chrome/browser/browser_process.h" | |
24 #include "chrome/browser/component_updater/component_installer_errors.h" | |
25 #include "chrome/browser/component_updater/cros_component_installer.h" | |
26 #include "chrome/browser/plugins/plugin_prefs.h" | |
27 #include "chrome/common/chrome_constants.h" | |
28 #include "chrome/common/chrome_content_client.h" | |
29 #include "chrome/common/chrome_paths.h" | |
30 #include "chrome/common/chrome_switches.h" | |
31 #include "components/component_updater/component_updater_service.h" | |
32 #include "components/component_updater/default_component_installer.h" | |
33 #include "components/update_client/update_client.h" | |
34 #include "components/update_client/update_client_errors.h" | |
35 #include "content/public/browser/browser_thread.h" | |
36 #include "content/public/browser/plugin_service.h" | |
37 #include "content/public/common/content_constants.h" | |
38 #include "crypto/sha2.h" | |
39 #include "third_party/libxml/chromium/libxml_utils.h" | |
40 | |
41 #if defined(OS_CHROMEOS) | |
42 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
43 #include "chrome/browser/ui/ash/system_tray_client.h" | |
44 #include "chrome/common/chrome_features.h" | |
45 #include "chromeos/dbus/dbus_method_call_status.h" | |
46 #include "chromeos/dbus/dbus_thread_manager.h" | |
47 #include "chromeos/dbus/image_loader_client.h" | |
48 #include "content/public/browser/browser_thread.h" | |
49 #elif defined(OS_LINUX) | |
50 #include "chrome/common/component_flash_hint_file_linux.h" | |
51 #endif // defined(OS_CHROMEOS) | |
52 | |
53 namespace component_updater { | |
54 | |
55 class ComponentUpdateService; | |
56 class ConfigParser { | |
57 public: | |
58 struct Result { | |
59 std::string name; | |
60 std::string dir_name; | |
61 std::string sha2hashstr; | |
62 }; | |
63 // an example config_xml: | |
64 // <components> | |
65 // <component name='cups' dir_name='cups'></component> | |
66 // <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.
| |
67 // </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
| |
68 bool Parse(std::string config_xml, std::vector<Result>& results); | |
69 std::string getErrors() { return errors_; } | |
70 | |
71 private: | |
72 // Utility class for cleaning up the xml document when leaving a scope. | |
73 class ScopedXmlDocument { | |
74 public: | |
75 explicit ScopedXmlDocument(xmlDocPtr document) : document_(document) {} | |
76 ~ScopedXmlDocument() { | |
77 if (document_) | |
78 xmlFreeDoc(document_); | |
79 } | |
80 xmlDocPtr get() { return document_; } | |
81 | |
82 private: | |
83 xmlDocPtr document_; | |
84 }; | |
85 // This is used for the xml parser to report errors. This assumes the context | |
86 // is a pointer to a std::string where the error message should be appended. | |
87 static void XmlErrorFunc(void* context, const char* message, ...); | |
88 static bool TagNameEquals(const xmlNode* node, const char* expected_name); | |
89 | |
90 bool IsValidSha256(const std::string& sha2HashStr); | |
91 // Returns the value of a named attribute, or nullptr . | |
92 static std::unique_ptr<std::string> GetAttributePtr( | |
93 xmlNode* node, | |
94 const char* attribute_name); | |
95 | |
96 void ParseError(const char* details, ...); | |
97 | |
98 bool ParseComponentTag(xmlNode* component, | |
99 Result* result, | |
100 std::string* error); | |
101 | |
102 // Returns child nodes of |root| with name |name|. | |
103 static std::vector<xmlNode*> GetChildren(xmlNode* root, const char* name); | |
104 | |
105 std::string errors_; | |
106 }; // class ConfigParser | |
107 | |
108 class CrOSComponentInstallerTraits : public ComponentInstallerTraits { | |
109 public: | |
110 CrOSComponentInstallerTraits(std::string dir_name, | |
111 std::string name, | |
112 std::string sha2HashStr); | |
113 ~CrOSComponentInstallerTraits() override {} | |
114 | |
115 private: | |
116 // The following methods override ComponentInstallerTraits. | |
117 bool SupportsGroupPolicyEnabledComponentUpdates() const override; | |
118 bool RequiresNetworkEncryption() const override; | |
119 update_client::CrxInstaller::Result OnCustomInstall( | |
120 const base::DictionaryValue& manifest, | |
121 const base::FilePath& install_dir) override; | |
122 bool VerifyInstallation(const base::DictionaryValue& manifest, | |
123 const base::FilePath& install_dir) const override; | |
124 void ComponentReady(const base::Version& version, | |
125 const base::FilePath& path, | |
126 std::unique_ptr<base::DictionaryValue> manifest) override; | |
127 base::FilePath GetRelativeInstallDir() const override; | |
128 void GetHash(std::vector<uint8_t>* hash) const override; | |
129 std::string GetName() const override; | |
130 update_client::InstallerAttributes GetInstallerAttributes() const override; | |
131 std::vector<std::string> GetMimeTypes() const override; | |
132 std::string dir_name; | |
133 std::string name; | |
134 uint8_t kSha2Hash_[crypto::kSHA256Length] = {}; | |
135 | |
136 DISALLOW_COPY_AND_ASSIGN(CrOSComponentInstallerTraits); | |
137 }; | |
138 | |
139 void RegisterCrOSComponent(ComponentUpdateService* cus, | |
140 ConfigParser::Result& result); | |
141 bool RegisterCrOSComponent(ComponentUpdateService* cus, std::string name); | |
142 | |
143 bool InstallCrOSComponent(std::string name); | |
144 | |
145 bool IsReadyCrOSComponent(std::string name); | |
146 | |
147 } // namespace component_updater | |
148 | |
149 #endif // CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ | |
OLD | NEW |