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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/component_updater/cros_component_installer.cc
diff --git a/chrome/browser/component_updater/cros_component_installer.cc b/chrome/browser/component_updater/cros_component_installer.cc
index f2ed8cf6ca8871d65a050bcc410508145f14cb9b..06710c3e86316886e1573b67bb17b2436ed671a6 100644
--- a/chrome/browser/component_updater/cros_component_installer.cc
+++ b/chrome/browser/component_updater/cros_component_installer.cc
@@ -11,11 +11,16 @@
#include "content/public/browser/browser_thread.h"
#if defined(OS_CHROMEOS)
-#include "chromeos/dbus/dbus_method_call_status.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/image_loader_client.h"
#endif // defined(OS_CHROMEOS)
+#define CONFIG_MAP_CONTENT \
+ {{"epson-inkjet-printer-escpr", \
+ {{"env_version", "2.1"}, \
+ {"sha2hashstr", \
+ "1913a5e0a6cad30b6f03e176177e0d7ed62c5d6700a9c66da556d7c3f5d6a47e"}}}};
+
using content::BrowserThread;
namespace component_updater {
@@ -81,7 +86,6 @@ update_client::CrxInstaller::Result
CrOSComponentInstallerTraits::OnCustomInstall(
const base::DictionaryValue& manifest,
const base::FilePath& install_dir) {
- DVLOG(1) << "[CrOSComponentInstallerTraits::OnCustomInstall]";
std::string version;
if (!manifest.GetString("version", &version)) {
return ToInstallerResult(update_client::InstallError::GENERIC_ERROR);
@@ -96,7 +100,12 @@ void CrOSComponentInstallerTraits::ComponentReady(
const base::Version& version,
const base::FilePath& path,
std::unique_ptr<base::DictionaryValue> manifest) {
- g_browser_process->platform_part()->AddCompatibleCrOSComponent(GetName());
+ std::string min_env_version;
+ if (manifest && manifest->GetString("min_env_version", &min_env_version)) {
+ if (IsCompatible(env_version, min_env_version)) {
+ g_browser_process->platform_part()->AddCompatibleCrOSComponent(GetName());
+ }
+ }
}
bool CrOSComponentInstallerTraits::VerifyInstallation(
@@ -129,89 +138,108 @@ std::vector<std::string> CrOSComponentInstallerTraits::GetMimeTypes() const {
return mime_types;
}
-void CrOSComponent::RegisterCrOSComponentInternal(
+bool CrOSComponentInstallerTraits::IsCompatible(
+ const std::string& env_version_str,
+ const std::string& min_env_version_str) {
+ base::Version env_version(env_version_str);
+ base::Version min_env_version(min_env_version_str);
+ return env_version.IsValid() && min_env_version.IsValid() &&
+ env_version.components()[0] == min_env_version.components()[0] &&
+ env_version >= min_env_version;
+}
+
+// It returns load result passing the following as parameters in
+// load_callback: call_status - dbus call status, result - component mount
+// point.
+static void LoadResult(
+ const base::Callback<void(const std::string&)>& load_callback,
+ chromeos::DBusMethodCallStatus call_status,
+ const std::string& result) {
+ PostTask(
+ FROM_HERE,
+ base::Bind(
+ load_callback,
+ call_status != chromeos::DBUS_METHOD_CALL_SUCCESS ? "" : result));
+}
+
+// Internal function to load a component.
+static void LoadComponentInternal(
+ const std::string& name,
+ const base::Callback<void(const std::string&)>& load_callback) {
+ DCHECK(g_browser_process->platform_part()->IsCompatibleCrOSComponent(name));
+ chromeos::ImageLoaderClient* loader =
+ chromeos::DBusThreadManager::Get()->GetImageLoaderClient();
+ if (loader) {
+ loader->LoadComponent(name, base::Bind(&LoadResult, load_callback));
+ } else {
+ base::PostTask(FROM_HERE, base::Bind(load_callback, ""));
+ }
+}
+
+// It calls LoadComponentInternal to load the installed component.
+static void InstallResult(
+ const std::string& name,
+ const base::Callback<void(const std::string&)>& load_callback,
+ update_client::Error error) {
+ LoadComponentInternal(name, load_callback);
+}
+
+// It calls OnDemandUpdate to install the component right after being
+// registered.
+void CrOSComponent::RegisterResult(
ComponentUpdateService* cus,
- const ComponentConfig& config,
- const base::Closure& installcallback) {
+ const std::string& id,
+ const update_client::Callback& install_callback) {
+ cus->GetOnDemandUpdater().OnDemandUpdate(id, install_callback);
+}
+
+// Register a component with a dedicated ComponentUpdateService instance.
+static void RegisterComponent(ComponentUpdateService* cus,
+ const ComponentConfig& config,
+ const base::Closure& register_callback) {
std::unique_ptr<ComponentInstallerTraits> traits(
new CrOSComponentInstallerTraits(config));
// |cus| will take ownership of |installer| during
// installer->Register(cus).
DefaultComponentInstaller* installer =
new DefaultComponentInstaller(std::move(traits));
- installer->Register(cus, installcallback);
+ installer->Register(cus, register_callback);
}
-void CrOSComponent::InstallChromeOSComponent(
+// Install a component with a dedicated ComponentUpdateService instance.
+void CrOSComponent::InstallComponent(
ComponentUpdateService* cus,
- const std::string& id,
- const update_client::Callback& install_callback) {
- cus->GetOnDemandUpdater().OnDemandUpdate(id, install_callback);
-}
-
-bool CrOSComponent::InstallCrOSComponent(
const std::string& name,
- const update_client::Callback& install_callback) {
- auto* const cus = g_browser_process->component_updater();
- const ConfigMap components = {
- {"epson-inkjet-printer-escpr",
- {{"env_version", "0.0"},
- {"sha2hashstr",
- "1913a5e0a6cad30b6f03e176177e0d7ed62c5d6700a9c66da556d7c3f5d6a47e"}}}};
- if (name.empty()) {
- base::PostTask(
- FROM_HERE,
- base::Bind(install_callback, update_client::Error::INVALID_ARGUMENT));
- return false;
- }
+ const base::Callback<void(const std::string&)>& load_callback) {
+ const ConfigMap components = CONFIG_MAP_CONTENT;
const auto it = components.find(name);
- if (it == components.end()) {
- DVLOG(1) << "[RegisterCrOSComponents] component " << name
- << " is not in configuration.";
- base::PostTask(
- FROM_HERE,
- base::Bind(install_callback, update_client::Error::INVALID_ARGUMENT));
- return false;
+ if (name.empty() || it == components.end()) {
+ base::PostTask(FROM_HERE, base::Bind(load_callback, ""));
+ return;
}
ComponentConfig config(it->first, it->second.find("env_version")->second,
it->second.find("sha2hashstr")->second);
- RegisterCrOSComponentInternal(
- cus, config,
- base::Bind(InstallChromeOSComponent, cus,
- crx_file::id_util::GenerateIdFromHex(
- it->second.find("sha2hashstr")->second)
- .substr(0, 32),
- install_callback));
- return true;
-}
-
-void MountResult(const base::Callback<void(const std::string&)>& mount_callback,
- chromeos::DBusMethodCallStatus call_status,
- const std::string& result) {
- if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) {
- DVLOG(1) << "Call to imageloader service failed.";
- base::PostTask(FROM_HERE, base::Bind(mount_callback, ""));
- return;
- }
- if (result.empty()) {
- DVLOG(1) << "Component load failed";
- base::PostTask(FROM_HERE, base::Bind(mount_callback, ""));
- return;
- }
- base::PostTask(FROM_HERE, base::Bind(mount_callback, result));
+ RegisterComponent(cus, config,
+ base::Bind(RegisterResult, cus,
+ crx_file::id_util::GenerateIdFromHex(
+ it->second.find("sha2hashstr")->second)
+ .substr(0, 32),
+ base::Bind(InstallResult, name, load_callback)));
}
-void CrOSComponent::LoadCrOSComponent(
+void CrOSComponent::LoadComponent(
const std::string& name,
- const base::Callback<void(const std::string&)>& mount_callback) {
- chromeos::ImageLoaderClient* loader =
- chromeos::DBusThreadManager::Get()->GetImageLoaderClient();
- if (loader) {
- loader->LoadComponent(name, base::Bind(&MountResult, mount_callback));
+ const base::Callback<void(const std::string&)>& load_callback) {
+ if (!g_browser_process->platform_part()->IsCompatibleCrOSComponent(name)) {
+ // A compatible component is not installed, start installation process.
+ auto* const cus = g_browser_process->component_updater();
+ InstallComponent(cus, name, load_callback);
} else {
- DVLOG(1) << "Failed to get ImageLoaderClient object.";
+ // A compatible component is intalled, load it directly.
+ LoadComponentInternal(name, load_callback);
}
}
+
#endif // defined(OS_CHROMEOS
} // namespace component_updater

Powered by Google App Engine
This is Rietveld 408576698