OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ | 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ |
6 #define CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ | 6 #define CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "components/component_updater/component_updater_service.h" | 11 #include "components/component_updater/component_updater_service.h" |
12 #include "components/component_updater/default_component_installer.h" | 12 #include "components/component_updater/default_component_installer.h" |
13 #include "components/update_client/update_client.h" | 13 #include "components/update_client/update_client.h" |
14 #include "crypto/sha2.h" | 14 #include "crypto/sha2.h" |
15 | 15 |
16 #define CONFIG_MAP_CONTENT \ | |
17 {{"epson-inkjet-printer-escpr", \ | |
18 {{"env_version", "2.0"}, \ | |
19 {"sha2hashstr", \ | |
20 "1913a5e0a6cad30b6f03e176177e0d7ed62c5d6700a9c66da556d7c3f5d6a47e"}}}}; | |
waffles
2017/05/26 17:28:26
Define this in the .cc, since that's the only plac
xiaochu
2017/05/26 19:44:02
Done.
| |
21 | |
16 namespace component_updater { | 22 namespace component_updater { |
17 | 23 |
18 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
19 struct ComponentConfig { | 25 struct ComponentConfig { |
20 std::string name; | 26 std::string name; |
21 std::string env_version; | 27 std::string env_version; |
22 std::string sha2hashstr; | 28 std::string sha2hashstr; |
23 ComponentConfig(const std::string& name, | 29 ComponentConfig(const std::string& name, |
24 const std::string& env_version, | 30 const std::string& env_version, |
25 const std::string& sha2hashstr); | 31 const std::string& sha2hashstr); |
26 ~ComponentConfig(); | 32 ~ComponentConfig(); |
27 }; | 33 }; |
28 | 34 |
29 using ConfigMap = std::map<std::string, std::map<std::string, std::string>>; | 35 using ConfigMap = std::map<std::string, std::map<std::string, std::string>>; |
30 | 36 |
31 class CrOSComponentInstallerTraits : public ComponentInstallerTraits { | 37 class CrOSComponentInstallerTraits : public ComponentInstallerTraits { |
32 public: | 38 public: |
33 explicit CrOSComponentInstallerTraits(const ComponentConfig& config); | 39 explicit CrOSComponentInstallerTraits(const ComponentConfig& config); |
34 ~CrOSComponentInstallerTraits() override {} | 40 ~CrOSComponentInstallerTraits() override {} |
35 | 41 |
36 private: | 42 private: |
43 FRIEND_TEST_ALL_PREFIXES(CrOSComponentInstallerTest, IsCompatibleOrNot); | |
44 FRIEND_TEST_ALL_PREFIXES(CrOSComponentInstallerTest, | |
45 ComponentReadyIsCompatible); | |
37 // The following methods override ComponentInstallerTraits. | 46 // The following methods override ComponentInstallerTraits. |
38 bool SupportsGroupPolicyEnabledComponentUpdates() const override; | 47 bool SupportsGroupPolicyEnabledComponentUpdates() const override; |
39 bool RequiresNetworkEncryption() const override; | 48 bool RequiresNetworkEncryption() const override; |
40 update_client::CrxInstaller::Result OnCustomInstall( | 49 update_client::CrxInstaller::Result OnCustomInstall( |
41 const base::DictionaryValue& manifest, | 50 const base::DictionaryValue& manifest, |
42 const base::FilePath& install_dir) override; | 51 const base::FilePath& install_dir) override; |
43 bool VerifyInstallation(const base::DictionaryValue& manifest, | 52 bool VerifyInstallation(const base::DictionaryValue& manifest, |
44 const base::FilePath& install_dir) const override; | 53 const base::FilePath& install_dir) const override; |
45 void ComponentReady(const base::Version& version, | 54 void ComponentReady(const base::Version& version, |
46 const base::FilePath& path, | 55 const base::FilePath& path, |
47 std::unique_ptr<base::DictionaryValue> manifest) override; | 56 std::unique_ptr<base::DictionaryValue> manifest) override; |
48 base::FilePath GetRelativeInstallDir() const override; | 57 base::FilePath GetRelativeInstallDir() const override; |
49 void GetHash(std::vector<uint8_t>* hash) const override; | 58 void GetHash(std::vector<uint8_t>* hash) const override; |
50 std::string GetName() const override; | 59 std::string GetName() const override; |
51 update_client::InstallerAttributes GetInstallerAttributes() const override; | 60 update_client::InstallerAttributes GetInstallerAttributes() const override; |
52 std::vector<std::string> GetMimeTypes() const override; | 61 std::vector<std::string> GetMimeTypes() const override; |
62 | |
63 static bool IsCompatible(const std::string& env_version, | |
64 const std::string& min_env_version); | |
53 std::string name; | 65 std::string name; |
54 std::string env_version; | 66 std::string env_version; |
55 uint8_t kSha2Hash_[crypto::kSHA256Length] = {}; | 67 uint8_t kSha2Hash_[crypto::kSHA256Length] = {}; |
56 | 68 |
57 DISALLOW_COPY_AND_ASSIGN(CrOSComponentInstallerTraits); | 69 DISALLOW_COPY_AND_ASSIGN(CrOSComponentInstallerTraits); |
58 }; | 70 }; |
59 | 71 |
60 // This class contains functions used to register and install a component. | 72 // This class contains functions used to register and install a component. |
61 class CrOSComponent { | 73 class CrOSComponent { |
62 public: | 74 public: |
63 // Register and start installing a CrOS component. | 75 // Register and start installing a CrOS component. |
64 // |install_callback| is triggered after install finishes and returns error | 76 // |install_callback| is triggered after install finishes and returns error |
65 // code. | 77 // code. |
66 // | 78 // |
67 // example: | 79 // example: |
68 // ... | 80 // ... |
69 // void load_callback(const std::string& result){ | 81 // void load_callback(const std::string& result){ |
70 // if (result.empty) { | 82 // if (result.empty) { |
71 // // component is not mounted. | 83 // // component is not mounted. |
72 // return; | 84 // return; |
73 // } | 85 // } |
74 // // [component mount point: result] | 86 // // [component mount point: result] |
75 // } | 87 // } |
76 // void install_callback(update_client::Error error){ | 88 // void install_callback(update_client::Error error){ |
77 // // switch(error){ | 89 // // error code: 1) update_client::Error::NONE, success 2) otherwise, |
78 // // case update_client::Error::NONE: | 90 // // fail. |
79 // // // component is installed | |
80 // // break; | |
81 // // case update_client::Error::INVALID_ARGUMENT: | |
82 // // // your install failed due to your wrong parameters. | |
83 // // break; | |
84 // // default: | |
85 // // // your install failed due to system failure. | |
86 // // break; | |
87 // // } | |
88 // // Even when error code other than NONE returned (your install failed), | 91 // // Even when error code other than NONE returned (your install failed), |
89 // // component might has already being installed previously. | 92 // // component might has already being installed previously. |
90 // // Plus, if you want to know current version of component. | 93 // // Plus, if you want to know current version of component. |
91 // component_updater:CrOSComponent::LoadCrOSComponent(name, load_callback); | 94 // component_updater:CrOSComponent::LoadCrOSComponent(name, load_callback); |
waffles
2017/05/26 17:28:26
This API is confusing to me; if you always want to
xiaochu
2017/05/26 19:44:02
It was originally designed the way you are speakin
| |
92 // } | 95 // } |
93 // ... | 96 // ... |
94 // component_updater::CrOSComponent::InstallCrOSComponent( | 97 // component_updater::CrOSComponent::InstallCrOSComponent( |
95 // name, | 98 // name, |
96 // base::Bind(&install_callback)); | 99 // base::Bind(&install_callback)); |
97 // | 100 // |
waffles
2017/05/26 17:28:26
For some reason I didn't notice this comment befor
xiaochu
2017/05/26 19:44:02
Done.
| |
98 static bool InstallCrOSComponent( | 101 static void InstallCrOSComponent( |
99 const std::string& name, | 102 const std::string& name, |
100 const update_client::Callback& install_callback); | 103 const update_client::Callback& install_callback); |
101 | 104 |
102 static void LoadCrOSComponent( | 105 static void LoadCrOSComponent( |
103 const std::string& name, | 106 const std::string& name, |
104 const base::Callback<void(const std::string&)>& mount_callback); | 107 const base::Callback<void(const std::string&)>& load_callback); |
105 | 108 |
106 private: | 109 private: |
110 FRIEND_TEST_ALL_PREFIXES(CrOSComponentInstallerTest, | |
111 RegisterComponentSuccess); | |
112 FRIEND_TEST_ALL_PREFIXES(CrOSComponentInstallerTest, RegisterComponentFail); | |
107 CrOSComponent() {} | 113 CrOSComponent() {} |
108 // Register a component. | 114 // Register a component (called by InstallCrOSComponent). |
109 static void RegisterCrOSComponentInternal(ComponentUpdateService* cus, | 115 static void RegisterCrOSComponentInternal(ComponentUpdateService* cus, |
110 const ComponentConfig& config, | 116 const ComponentConfig& config, |
111 const base::Closure& callback); | 117 const base::Closure& callback); |
118 // Install a component (called by InstallCrOSComponent). | |
119 static void InstallCrOSComponent( | |
120 ComponentUpdateService* cus, | |
121 const std::string& name, | |
122 const update_client::Callback& install_callback); | |
112 // A helper function to pass into RegisterCrOSComonentInternal as a callback. | 123 // A helper function to pass into RegisterCrOSComonentInternal as a callback. |
113 // It calls OnDemandUpdate to install the component right after being | 124 // It calls OnDemandUpdate to install the component right after being |
114 // registered. | 125 // registered. |
115 static void InstallChromeOSComponent( | 126 static void InstallChromeOSComponent( |
116 ComponentUpdateService* cus, | 127 ComponentUpdateService* cus, |
117 const std::string& id, | 128 const std::string& id, |
118 const update_client::Callback& install_callback); | 129 const update_client::Callback& install_callback); |
119 }; | 130 }; |
120 #endif // defined(OS_CHROMEOS) | 131 #endif // defined(OS_CHROMEOS) |
121 | 132 |
122 } // namespace component_updater | 133 } // namespace component_updater |
123 | 134 |
124 #endif // CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ | 135 #endif // CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ |
OLD | NEW |