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

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

Issue 2911483002: Check env-version upon component load (Closed)
Patch Set: address comments from waffles 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 auto* const cus = g_browser_process->component_updater();
156 InstallComponent(cus, name, load_callback);
157 } else {
158 // A compatible component is intalled, load it directly.
159 LoadComponentInternal(name, load_callback);
160 }
161 }
162
163 void CrOSComponent::InstallComponent(
133 ComponentUpdateService* cus, 164 ComponentUpdateService* cus,
134 const ComponentConfig& config, 165 const std::string& name,
135 const base::Closure& installcallback) { 166 const base::Callback<void(const std::string&)>& load_callback) {
167 const ConfigMap components = CONFIG_MAP_CONTENT;
168 const auto it = components.find(name);
169 if (name.empty() || it == components.end()) {
170 base::PostTask(FROM_HERE, base::Bind(load_callback, ""));
171 return;
172 }
173 ComponentConfig config(it->first, it->second.find("env_version")->second,
174 it->second.find("sha2hashstr")->second);
175 RegisterComponent(cus, config,
176 base::Bind(RegisterResult, cus,
177 crx_file::id_util::GenerateIdFromHex(
178 it->second.find("sha2hashstr")->second)
179 .substr(0, 32),
180 base::Bind(InstallResult, name, load_callback)));
181 }
182
183 void CrOSComponent::RegisterComponent(ComponentUpdateService* cus,
184 const ComponentConfig& config,
185 const base::Closure& register_callback) {
136 std::unique_ptr<ComponentInstallerTraits> traits( 186 std::unique_ptr<ComponentInstallerTraits> traits(
137 new CrOSComponentInstallerTraits(config)); 187 new CrOSComponentInstallerTraits(config));
138 // |cus| will take ownership of |installer| during 188 // |cus| will take ownership of |installer| during
139 // installer->Register(cus). 189 // installer->Register(cus).
140 DefaultComponentInstaller* installer = 190 DefaultComponentInstaller* installer =
141 new DefaultComponentInstaller(std::move(traits)); 191 new DefaultComponentInstaller(std::move(traits));
142 installer->Register(cus, installcallback); 192 installer->Register(cus, register_callback);
143 } 193 }
144 194
145 void CrOSComponent::InstallChromeOSComponent( 195 void CrOSComponent::RegisterResult(
146 ComponentUpdateService* cus, 196 ComponentUpdateService* cus,
147 const std::string& id, 197 const std::string& id,
148 const update_client::Callback& install_callback) { 198 const update_client::Callback& install_callback) {
149 cus->GetOnDemandUpdater().OnDemandUpdate(id, install_callback); 199 cus->GetOnDemandUpdater().OnDemandUpdate(id, install_callback);
150 } 200 }
151 201
152 bool CrOSComponent::InstallCrOSComponent( 202 void CrOSComponent::InstallResult(
153 const std::string& name, 203 const std::string& name,
154 const update_client::Callback& install_callback) { 204 const base::Callback<void(const std::string&)>& load_callback,
155 auto* const cus = g_browser_process->component_updater(); 205 update_client::Error error) {
156 const ConfigMap components = { 206 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 } 207 }
187 208
188 void MountResult(const base::Callback<void(const std::string&)>& mount_callback, 209 void CrOSComponent::LoadComponentInternal(
189 chromeos::DBusMethodCallStatus call_status,
190 const std::string& result) {
191 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) {
192 DVLOG(1) << "Call to imageloader service failed.";
193 base::PostTask(FROM_HERE, base::Bind(mount_callback, ""));
194 return;
195 }
196 if (result.empty()) {
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 }
203
204 void CrOSComponent::LoadCrOSComponent(
205 const std::string& name, 210 const std::string& name,
206 const base::Callback<void(const std::string&)>& mount_callback) { 211 const base::Callback<void(const std::string&)>& load_callback) {
212 DCHECK(g_browser_process->platform_part()->IsCompatibleCrOSComponent(name));
207 chromeos::ImageLoaderClient* loader = 213 chromeos::ImageLoaderClient* loader =
208 chromeos::DBusThreadManager::Get()->GetImageLoaderClient(); 214 chromeos::DBusThreadManager::Get()->GetImageLoaderClient();
209 if (loader) { 215 if (loader) {
210 loader->LoadComponent(name, base::Bind(&MountResult, mount_callback)); 216 loader->LoadComponent(name, base::Bind(&LoadResult, load_callback));
211 } else { 217 } else {
212 DVLOG(1) << "Failed to get ImageLoaderClient object."; 218 base::PostTask(FROM_HERE, base::Bind(load_callback, ""));
213 } 219 }
214 } 220 }
221
222 void CrOSComponent::LoadResult(
223 const base::Callback<void(const std::string&)>& load_callback,
224 chromeos::DBusMethodCallStatus call_status,
225 const std::string& result) {
226 PostTask(
227 FROM_HERE,
228 base::Bind(
229 load_callback,
230 call_status != chromeos::DBUS_METHOD_CALL_SUCCESS ? "" : result));
231 }
232
215 #endif // defined(OS_CHROMEOS 233 #endif // defined(OS_CHROMEOS
216 234
217 } // namespace component_updater 235 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698