Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chrome/browser/component_updater/cros_component_installer.cc

Issue 2911483002: Check env-version upon component load (Closed)
Patch Set: fix comment Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "chrome/browser/component_updater/cros_component_installer.h" 5 #include "chrome/browser/component_updater/cros_component_installer.h"
6 #include "base/task_scheduler/post_task.h" 6 #include "base/task_scheduler/post_task.h"
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/component_updater/component_installer_errors.h" 8 #include "chrome/browser/component_updater/component_installer_errors.h"
9 #include "components/component_updater/component_updater_paths.h" 9 #include "components/component_updater/component_updater_paths.h"
10 #include "components/crx_file/id_util.h" 10 #include "components/crx_file/id_util.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 12
13 #if defined(OS_CHROMEOS) 13 #if defined(OS_CHROMEOS)
14 #include "chromeos/dbus/dbus_method_call_status.h"
15 #include "chromeos/dbus/dbus_thread_manager.h" 14 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "chromeos/dbus/image_loader_client.h" 15 #include "chromeos/dbus/image_loader_client.h"
17 #endif // defined(OS_CHROMEOS) 16 #endif // defined(OS_CHROMEOS)
18 17
18 #define CONFIG_MAP_CONTENT \
19 {{"epson-inkjet-printer-escpr", \
20 {{"env_version", "2.1"}, \
21 {"sha2hashstr", \
22 "1913a5e0a6cad30b6f03e176177e0d7ed62c5d6700a9c66da556d7c3f5d6a47e"}}}};
23
19 using content::BrowserThread; 24 using content::BrowserThread;
20 25
21 namespace component_updater { 26 namespace component_updater {
22 27
23 #if defined(OS_CHROMEOS) 28 #if defined(OS_CHROMEOS)
24 void LogRegistrationResult(const std::string& name, 29 void LogRegistrationResult(const std::string& name,
25 chromeos::DBusMethodCallStatus call_status, 30 chromeos::DBusMethodCallStatus call_status,
26 bool result) { 31 bool result) {
27 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
28 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { 33 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 79 }
75 80
76 bool CrOSComponentInstallerTraits::RequiresNetworkEncryption() const { 81 bool CrOSComponentInstallerTraits::RequiresNetworkEncryption() const {
77 return true; 82 return true;
78 } 83 }
79 84
80 update_client::CrxInstaller::Result 85 update_client::CrxInstaller::Result
81 CrOSComponentInstallerTraits::OnCustomInstall( 86 CrOSComponentInstallerTraits::OnCustomInstall(
82 const base::DictionaryValue& manifest, 87 const base::DictionaryValue& manifest,
83 const base::FilePath& install_dir) { 88 const base::FilePath& install_dir) {
84 DVLOG(1) << "[CrOSComponentInstallerTraits::OnCustomInstall]";
85 std::string version; 89 std::string version;
86 if (!manifest.GetString("version", &version)) { 90 if (!manifest.GetString("version", &version)) {
87 return ToInstallerResult(update_client::InstallError::GENERIC_ERROR); 91 return ToInstallerResult(update_client::InstallError::GENERIC_ERROR);
88 } 92 }
89 BrowserThread::PostTask( 93 BrowserThread::PostTask(
90 BrowserThread::UI, FROM_HERE, 94 BrowserThread::UI, FROM_HERE,
91 base::Bind(&ImageLoaderRegistration, version, install_dir, name)); 95 base::Bind(&ImageLoaderRegistration, version, install_dir, name));
92 return update_client::CrxInstaller::Result(update_client::InstallError::NONE); 96 return update_client::CrxInstaller::Result(update_client::InstallError::NONE);
93 } 97 }
94 98
95 void CrOSComponentInstallerTraits::ComponentReady( 99 void CrOSComponentInstallerTraits::ComponentReady(
96 const base::Version& version, 100 const base::Version& version,
97 const base::FilePath& path, 101 const base::FilePath& path,
98 std::unique_ptr<base::DictionaryValue> manifest) { 102 std::unique_ptr<base::DictionaryValue> manifest) {
99 g_browser_process->platform_part()->AddCompatibleCrOSComponent(GetName()); 103 std::string min_env_version;
104 if (manifest && manifest->GetString("min_env_version", &min_env_version)) {
105 if (IsCompatible(env_version, min_env_version)) {
106 g_browser_process->platform_part()->AddCompatibleCrOSComponent(GetName());
107 }
108 }
100 } 109 }
101 110
102 bool CrOSComponentInstallerTraits::VerifyInstallation( 111 bool CrOSComponentInstallerTraits::VerifyInstallation(
103 const base::DictionaryValue& manifest, 112 const base::DictionaryValue& manifest,
104 const base::FilePath& install_dir) const { 113 const base::FilePath& install_dir) const {
105 return true; 114 return true;
106 } 115 }
107 116
108 base::FilePath CrOSComponentInstallerTraits::GetRelativeInstallDir() const { 117 base::FilePath CrOSComponentInstallerTraits::GetRelativeInstallDir() const {
109 return base::FilePath(name); 118 return base::FilePath(name);
(...skipping 12 matching lines...) Expand all
122 update_client::InstallerAttributes attrs; 131 update_client::InstallerAttributes attrs;
123 attrs["_env_version"] = env_version; 132 attrs["_env_version"] = env_version;
124 return attrs; 133 return attrs;
125 } 134 }
126 135
127 std::vector<std::string> CrOSComponentInstallerTraits::GetMimeTypes() const { 136 std::vector<std::string> CrOSComponentInstallerTraits::GetMimeTypes() const {
128 std::vector<std::string> mime_types; 137 std::vector<std::string> mime_types;
129 return mime_types; 138 return mime_types;
130 } 139 }
131 140
132 void CrOSComponent::RegisterCrOSComponentInternal( 141 bool CrOSComponentInstallerTraits::IsCompatible(
142 const std::string& env_version_str,
143 const std::string& min_env_version_str) {
144 base::Version env_version(env_version_str);
145 base::Version min_env_version(min_env_version_str);
146 return env_version.IsValid() && min_env_version.IsValid() &&
147 env_version >= min_env_version;
148 }
149
150 void CrOSComponent::LoadComponent(
151 const std::string& name,
152 const base::Callback<void(const std::string&)>& load_callback) {
153 if (!g_browser_process->platform_part()->IsCompatibleCrOSComponent(name)) {
154 // A compatible component is not installed, start installation process.
155 InstallComponent(name, load_callback);
waffles 2017/06/01 00:08:14 Seems simpler to just call the three-argument vers
xiaochu 2017/06/01 02:58:09 Done.
156 } else {
157 // A compatible component is intalled, load it directly.
158 LoadComponentInternal(name, load_callback);
159 }
160 }
161
162 void CrOSComponent::InstallComponent(
163 const std::string& name,
164 const base::Callback<void(const std::string&)>& load_callback) {
165 auto* const cus = g_browser_process->component_updater();
166 InstallComponent(cus, name, load_callback);
167 }
168
169 void CrOSComponent::InstallComponent(
133 ComponentUpdateService* cus, 170 ComponentUpdateService* cus,
134 const ComponentConfig& config, 171 const std::string& name,
135 const base::Closure& installcallback) { 172 const base::Callback<void(const std::string&)>& load_callback) {
173 const ConfigMap components = CONFIG_MAP_CONTENT;
174 const auto it = components.find(name);
175 if (name.empty() || it == components.end()) {
176 base::PostTask(FROM_HERE, base::Bind(load_callback, ""));
177 return;
178 }
179 ComponentConfig config(it->first, it->second.find("env_version")->second,
180 it->second.find("sha2hashstr")->second);
181 RegisterComponent(cus, config,
182 base::Bind(RegisterResult, cus,
183 crx_file::id_util::GenerateIdFromHex(
184 it->second.find("sha2hashstr")->second)
185 .substr(0, 32),
186 base::Bind(InstallResult, name, load_callback)));
187 }
188
189 void CrOSComponent::RegisterComponent(ComponentUpdateService* cus,
190 const ComponentConfig& config,
191 const base::Closure& register_callback) {
136 std::unique_ptr<ComponentInstallerTraits> traits( 192 std::unique_ptr<ComponentInstallerTraits> traits(
137 new CrOSComponentInstallerTraits(config)); 193 new CrOSComponentInstallerTraits(config));
138 // |cus| will take ownership of |installer| during 194 // |cus| will take ownership of |installer| during
139 // installer->Register(cus). 195 // installer->Register(cus).
140 DefaultComponentInstaller* installer = 196 DefaultComponentInstaller* installer =
141 new DefaultComponentInstaller(std::move(traits)); 197 new DefaultComponentInstaller(std::move(traits));
142 installer->Register(cus, installcallback); 198 installer->Register(cus, register_callback);
143 } 199 }
144 200
145 void CrOSComponent::InstallChromeOSComponent( 201 void CrOSComponent::RegisterResult(
146 ComponentUpdateService* cus, 202 ComponentUpdateService* cus,
147 const std::string& id, 203 const std::string& id,
148 const update_client::Callback& install_callback) { 204 const update_client::Callback& install_callback) {
149 cus->GetOnDemandUpdater().OnDemandUpdate(id, install_callback); 205 cus->GetOnDemandUpdater().OnDemandUpdate(id, install_callback);
150 } 206 }
151 207
152 bool CrOSComponent::InstallCrOSComponent( 208 void CrOSComponent::InstallResult(
153 const std::string& name, 209 const std::string& name,
154 const update_client::Callback& install_callback) { 210 const base::Callback<void(const std::string&)>& load_callback,
155 auto* const cus = g_browser_process->component_updater(); 211 update_client::Error error) {
156 const ConfigMap components = { 212 LoadComponentInternal(name, load_callback);
157 {"epson-inkjet-printer-escpr",
158 {{"env_version", "0.0"},
159 {"sha2hashstr",
160 "1913a5e0a6cad30b6f03e176177e0d7ed62c5d6700a9c66da556d7c3f5d6a47e"}}}};
161 if (name.empty()) {
162 base::PostTask(
163 FROM_HERE,
164 base::Bind(install_callback, update_client::Error::INVALID_ARGUMENT));
165 return false;
166 }
167 const auto it = components.find(name);
168 if (it == components.end()) {
169 DVLOG(1) << "[RegisterCrOSComponents] component " << name
170 << " is not in configuration.";
171 base::PostTask(
172 FROM_HERE,
173 base::Bind(install_callback, update_client::Error::INVALID_ARGUMENT));
174 return false;
175 }
176 ComponentConfig config(it->first, it->second.find("env_version")->second,
177 it->second.find("sha2hashstr")->second);
178 RegisterCrOSComponentInternal(
179 cus, config,
180 base::Bind(InstallChromeOSComponent, cus,
181 crx_file::id_util::GenerateIdFromHex(
182 it->second.find("sha2hashstr")->second)
183 .substr(0, 32),
184 install_callback));
185 return true;
186 } 213 }
187 214
188 void MountResult(const base::Callback<void(const std::string&)>& mount_callback, 215 void CrOSComponent::LoadComponentInternal(
189 chromeos::DBusMethodCallStatus call_status, 216 const std::string& name,
190 const std::string& result) { 217 const base::Callback<void(const std::string&)>& load_callback) {
191 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { 218 if (g_browser_process->platform_part()->IsCompatibleCrOSComponent(name)) {
waffles 2017/06/01 00:08:14 This check seems redundant with the check the call
xiaochu 2017/06/01 02:58:09 I am checking this since otherwise it might load a
xiaochu 2017/06/01 16:26:50 Done. Sorry about last message. I get it now.
192 DVLOG(1) << "Call to imageloader service failed."; 219 chromeos::ImageLoaderClient* loader =
193 base::PostTask(FROM_HERE, base::Bind(mount_callback, "")); 220 chromeos::DBusThreadManager::Get()->GetImageLoaderClient();
194 return; 221 if (loader) {
222 loader->LoadComponent(name, base::Bind(&LoadResult, load_callback));
223 return;
224 }
195 } 225 }
196 if (result.empty()) { 226 base::PostTask(FROM_HERE, base::Bind(load_callback, ""));
197 DVLOG(1) << "Component load failed";
198 base::PostTask(FROM_HERE, base::Bind(mount_callback, ""));
199 return;
200 }
201 base::PostTask(FROM_HERE, base::Bind(mount_callback, result));
202 } 227 }
203 228
204 void CrOSComponent::LoadCrOSComponent( 229 void CrOSComponent::LoadResult(
205 const std::string& name, 230 const base::Callback<void(const std::string&)>& load_callback,
206 const base::Callback<void(const std::string&)>& mount_callback) { 231 chromeos::DBusMethodCallStatus call_status,
207 chromeos::ImageLoaderClient* loader = 232 const std::string& result) {
208 chromeos::DBusThreadManager::Get()->GetImageLoaderClient(); 233 PostTask(
209 if (loader) { 234 FROM_HERE,
210 loader->LoadComponent(name, base::Bind(&MountResult, mount_callback)); 235 base::Bind(
211 } else { 236 load_callback,
212 DVLOG(1) << "Failed to get ImageLoaderClient object."; 237 call_status != chromeos::DBUS_METHOD_CALL_SUCCESS ? "" : result));
213 }
214 } 238 }
239
215 #endif // defined(OS_CHROMEOS 240 #endif // defined(OS_CHROMEOS
216 241
217 } // namespace component_updater 242 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698