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

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

Issue 2911483002: Check env-version upon component load (Closed)
Patch Set: rebase 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" 14 #include "chromeos/dbus/dbus_method_call_status.h"
15 #include "chromeos/dbus/dbus_thread_manager.h" 15 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "chromeos/dbus/image_loader_client.h" 16 #include "chromeos/dbus/image_loader_client.h"
17 #endif // defined(OS_CHROMEOS) 17 #endif // defined(OS_CHROMEOS)
18 18
19 #define CONFIG_MAP_CONTENT \
20 {{"epson-inkjet-printer-escpr", \
21 {{"env_version", "2.1"}, \
22 {"sha2hashstr", \
23 "1913a5e0a6cad30b6f03e176177e0d7ed62c5d6700a9c66da556d7c3f5d6a47e"}}}};
24
19 using content::BrowserThread; 25 using content::BrowserThread;
20 26
21 namespace component_updater { 27 namespace component_updater {
22 28
23 #if defined(OS_CHROMEOS) 29 #if defined(OS_CHROMEOS)
24 void LogRegistrationResult(const std::string& name, 30 void LogRegistrationResult(const std::string& name,
25 chromeos::DBusMethodCallStatus call_status, 31 chromeos::DBusMethodCallStatus call_status,
26 bool result) { 32 bool result) {
27 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 33 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
28 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { 34 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 80 }
75 81
76 bool CrOSComponentInstallerTraits::RequiresNetworkEncryption() const { 82 bool CrOSComponentInstallerTraits::RequiresNetworkEncryption() const {
77 return true; 83 return true;
78 } 84 }
79 85
80 update_client::CrxInstaller::Result 86 update_client::CrxInstaller::Result
81 CrOSComponentInstallerTraits::OnCustomInstall( 87 CrOSComponentInstallerTraits::OnCustomInstall(
82 const base::DictionaryValue& manifest, 88 const base::DictionaryValue& manifest,
83 const base::FilePath& install_dir) { 89 const base::FilePath& install_dir) {
84 DVLOG(1) << "[CrOSComponentInstallerTraits::OnCustomInstall]";
85 std::string version; 90 std::string version;
86 if (!manifest.GetString("version", &version)) { 91 if (!manifest.GetString("version", &version)) {
87 return ToInstallerResult(update_client::InstallError::GENERIC_ERROR); 92 return ToInstallerResult(update_client::InstallError::GENERIC_ERROR);
88 } 93 }
89 BrowserThread::PostTask( 94 BrowserThread::PostTask(
90 BrowserThread::UI, FROM_HERE, 95 BrowserThread::UI, FROM_HERE,
91 base::Bind(&ImageLoaderRegistration, version, install_dir, name)); 96 base::Bind(&ImageLoaderRegistration, version, install_dir, name));
92 return update_client::CrxInstaller::Result(update_client::InstallError::NONE); 97 return update_client::CrxInstaller::Result(update_client::InstallError::NONE);
93 } 98 }
94 99
95 void CrOSComponentInstallerTraits::ComponentReady( 100 void CrOSComponentInstallerTraits::ComponentReady(
96 const base::Version& version, 101 const base::Version& version,
97 const base::FilePath& path, 102 const base::FilePath& path,
98 std::unique_ptr<base::DictionaryValue> manifest) { 103 std::unique_ptr<base::DictionaryValue> manifest) {
99 g_browser_process->platform_part()->AddCompatibleCrOSComponent(GetName()); 104 std::string min_env_version;
105 if (manifest && manifest->GetString("min_env_version", &min_env_version)) {
106 if (IsCompatible(env_version, min_env_version)) {
107 g_browser_process->platform_part()->AddCompatibleCrOSComponent(GetName());
108 }
109 }
100 } 110 }
101 111
102 bool CrOSComponentInstallerTraits::VerifyInstallation( 112 bool CrOSComponentInstallerTraits::VerifyInstallation(
103 const base::DictionaryValue& manifest, 113 const base::DictionaryValue& manifest,
104 const base::FilePath& install_dir) const { 114 const base::FilePath& install_dir) const {
105 return true; 115 return true;
106 } 116 }
107 117
108 base::FilePath CrOSComponentInstallerTraits::GetRelativeInstallDir() const { 118 base::FilePath CrOSComponentInstallerTraits::GetRelativeInstallDir() const {
109 return base::FilePath(name); 119 return base::FilePath(name);
(...skipping 12 matching lines...) Expand all
122 update_client::InstallerAttributes attrs; 132 update_client::InstallerAttributes attrs;
123 attrs["_env_version"] = env_version; 133 attrs["_env_version"] = env_version;
124 return attrs; 134 return attrs;
125 } 135 }
126 136
127 std::vector<std::string> CrOSComponentInstallerTraits::GetMimeTypes() const { 137 std::vector<std::string> CrOSComponentInstallerTraits::GetMimeTypes() const {
128 std::vector<std::string> mime_types; 138 std::vector<std::string> mime_types;
129 return mime_types; 139 return mime_types;
130 } 140 }
131 141
132 void CrOSComponent::RegisterCrOSComponentInternal( 142 bool CrOSComponentInstallerTraits::IsCompatible(
133 ComponentUpdateService* cus, 143 const std::string& env_version_str,
134 const ComponentConfig& config, 144 const std::string& min_env_version_str) {
135 const base::Closure& installcallback) { 145 // env_version format: [0-9]+.[0-9]+
136 std::unique_ptr<ComponentInstallerTraits> traits( 146 base::Version env_version(env_version_str);
137 new CrOSComponentInstallerTraits(config)); 147 base::Version min_env_version(min_env_version_str);
138 // |cus| will take ownership of |installer| during 148 if (env_version.components().size() == 2 &&
139 // installer->Register(cus). 149 min_env_version.components().size() == 2 &&
140 DefaultComponentInstaller* installer = 150 env_version.components()[0] == min_env_version.components()[0] &&
141 new DefaultComponentInstaller(std::move(traits)); 151 env_version.components()[1] >= min_env_version.components()[1]) {
waffles 2017/05/30 22:12:17 You can replace the == 2 check with .IsValid and t
xiaochu 2017/05/31 15:40:11 Done.
142 installer->Register(cus, installcallback); 152 return true;
153 }
154 return false;
waffles 2017/05/30 22:12:17 IMHO it's better to just return the value of the e
xiaochu 2017/05/31 15:40:11 Done.
143 } 155 }
144 156
145 void CrOSComponent::InstallChromeOSComponent( 157 void CrOSComponent::InstallCrOSComponent(
146 ComponentUpdateService* cus,
147 const std::string& id,
148 const update_client::Callback& install_callback) {
149 cus->GetOnDemandUpdater().OnDemandUpdate(id, install_callback);
150 }
151
152 bool CrOSComponent::InstallCrOSComponent(
153 const std::string& name, 158 const std::string& name,
154 const update_client::Callback& install_callback) { 159 const update_client::Callback& install_callback) {
155 auto* const cus = g_browser_process->component_updater(); 160 auto* const cus = g_browser_process->component_updater();
156 const ConfigMap components = { 161 InstallCrOSComponent(cus, name, install_callback);
157 {"epson-inkjet-printer-escpr", 162 }
158 {{"env_version", "0.0"}, 163
159 {"sha2hashstr", 164 void CrOSComponent::InstallCrOSComponent(
160 "1913a5e0a6cad30b6f03e176177e0d7ed62c5d6700a9c66da556d7c3f5d6a47e"}}}}; 165 ComponentUpdateService* cus,
161 if (name.empty()) { 166 const std::string& name,
167 const update_client::Callback& install_callback) {
168 const ConfigMap components = CONFIG_MAP_CONTENT;
169 const auto it = components.find(name);
170 if (name.empty() || it == components.end()) {
162 base::PostTask( 171 base::PostTask(
163 FROM_HERE, 172 FROM_HERE,
164 base::Bind(install_callback, update_client::Error::INVALID_ARGUMENT)); 173 base::Bind(install_callback, update_client::Error::INVALID_ARGUMENT));
165 return false; 174 return;
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 } 175 }
176 ComponentConfig config(it->first, it->second.find("env_version")->second, 176 ComponentConfig config(it->first, it->second.find("env_version")->second,
177 it->second.find("sha2hashstr")->second); 177 it->second.find("sha2hashstr")->second);
178 RegisterCrOSComponentInternal( 178 RegisterCrOSComponentInternal(
179 cus, config, 179 cus, config,
180 base::Bind(InstallChromeOSComponent, cus, 180 base::Bind(InstallChromeOSComponent, cus,
181 crx_file::id_util::GenerateIdFromHex( 181 crx_file::id_util::GenerateIdFromHex(
182 it->second.find("sha2hashstr")->second) 182 it->second.find("sha2hashstr")->second)
183 .substr(0, 32), 183 .substr(0, 32),
184 install_callback)); 184 install_callback));
185 return true;
186 } 185 }
187 186
188 void MountResult(const base::Callback<void(const std::string&)>& mount_callback, 187 void CrOSComponent::RegisterCrOSComponentInternal(
189 chromeos::DBusMethodCallStatus call_status, 188 ComponentUpdateService* cus,
190 const std::string& result) { 189 const ComponentConfig& config,
191 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { 190 const base::Closure& installcallback) {
192 DVLOG(1) << "Call to imageloader service failed."; 191 std::unique_ptr<ComponentInstallerTraits> traits(
193 base::PostTask(FROM_HERE, base::Bind(mount_callback, "")); 192 new CrOSComponentInstallerTraits(config));
194 return; 193 // |cus| will take ownership of |installer| during
195 } 194 // installer->Register(cus).
196 if (result.empty()) { 195 DefaultComponentInstaller* installer =
197 DVLOG(1) << "Component load failed"; 196 new DefaultComponentInstaller(std::move(traits));
198 base::PostTask(FROM_HERE, base::Bind(mount_callback, "")); 197 installer->Register(cus, installcallback);
199 return; 198 }
200 } 199
201 base::PostTask(FROM_HERE, base::Bind(mount_callback, result)); 200 void CrOSComponent::InstallChromeOSComponent(
201 ComponentUpdateService* cus,
202 const std::string& id,
203 const update_client::Callback& install_callback) {
204 cus->GetOnDemandUpdater().OnDemandUpdate(id, install_callback);
205 }
206
207 void LoadResult(const base::Callback<void(const std::string&)>& load_callback,
208 chromeos::DBusMethodCallStatus call_status,
209 const std::string& result) {
210 PostTask(
211 FROM_HERE,
212 base::Bind(
213 load_callback,
214 call_status != chromeos::DBUS_METHOD_CALL_SUCCESS ? "" : result));
202 } 215 }
203 216
204 void CrOSComponent::LoadCrOSComponent( 217 void CrOSComponent::LoadCrOSComponent(
205 const std::string& name, 218 const std::string& name,
206 const base::Callback<void(const std::string&)>& mount_callback) { 219 const base::Callback<void(const std::string&)>& load_callback) {
220 if (!g_browser_process->platform_part()->IsCompatibleCrOSComponent(name))
221 return;
207 chromeos::ImageLoaderClient* loader = 222 chromeos::ImageLoaderClient* loader =
208 chromeos::DBusThreadManager::Get()->GetImageLoaderClient(); 223 chromeos::DBusThreadManager::Get()->GetImageLoaderClient();
209 if (loader) { 224 if (loader) {
210 loader->LoadComponent(name, base::Bind(&MountResult, mount_callback)); 225 loader->LoadComponent(name, base::Bind(&LoadResult, load_callback));
211 } else { 226 return;
212 DVLOG(1) << "Failed to get ImageLoaderClient object.";
213 } 227 }
228 base::PostTask(FROM_HERE, base::Bind(load_callback, ""));
214 } 229 }
230
215 #endif // defined(OS_CHROMEOS 231 #endif // defined(OS_CHROMEOS
216 232
217 } // namespace component_updater 233 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698