Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/component_updater/cros_component_installer.h" | |
| 6 #include "chrome/browser/browser_process.h" | |
| 7 #include "components/component_updater/component_updater_paths.h" | |
| 8 | |
| 9 using content::BrowserThread; | |
| 10 using content::PluginService; | |
| 11 | |
| 12 namespace component_updater { | |
| 13 | |
| 14 #if defined(OS_CHROMEOS) | |
| 15 void LogRegistrationResult(chromeos::DBusMethodCallStatus call_status, | |
| 16 bool result) { | |
| 17 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 18 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { | |
| 19 LOG(ERROR) << "Call to imageloader service failed."; | |
| 20 return; | |
| 21 } | |
| 22 if (!result) { | |
| 23 LOG(ERROR) << "Component registration failed"; | |
| 24 return; | |
| 25 } | |
| 26 } | |
| 27 void ImageLoaderRegistration(const std::string& version, | |
| 28 const base::FilePath& install_dir, | |
| 29 const std::string& name) { | |
| 30 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 31 chromeos::ImageLoaderClient* loader = | |
| 32 chromeos::DBusThreadManager::Get()->GetImageLoaderClient(); | |
| 33 | |
| 34 if (loader) { | |
| 35 loader->RegisterComponent(name, version, install_dir.value(), | |
| 36 base::Bind(&LogRegistrationResult)); | |
| 37 } else { | |
| 38 LOG(ERROR) << "Failed to get ImageLoaderClient object."; | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 // Determine whether or not to skip registering this cros component updates. | |
| 43 bool SkipCupsRegistration(ComponentUpdateService* cus) { | |
| 44 return false; | |
| 45 } | |
| 46 #endif // defined(OS_CHROMEOS) | |
| 47 | |
| 48 CrOSComponentInstallerTraits::CrOSComponentInstallerTraits( | |
| 49 std::string dir_name, | |
| 50 std::string name, | |
| 51 std::string sha2HashStr) | |
| 52 : dir_name(dir_name), name(name) { | |
| 53 if (sha2HashStr.length() != 64) | |
| 54 return; | |
| 55 for (unsigned int i = 0; i < sizeof(kSha2Hash_); i++) { | |
| 56 kSha2Hash_[i] = stoul(sha2HashStr.substr(i * 2, 2), nullptr, 16); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 bool CrOSComponentInstallerTraits::SupportsGroupPolicyEnabledComponentUpdates() | |
| 61 const { | |
| 62 return true; | |
| 63 } | |
| 64 | |
| 65 bool CrOSComponentInstallerTraits::RequiresNetworkEncryption() const { | |
| 66 return false; | |
| 67 } | |
| 68 | |
| 69 update_client::CrxInstaller::Result | |
| 70 CrOSComponentInstallerTraits::OnCustomInstall( | |
| 71 const base::DictionaryValue& manifest, | |
| 72 const base::FilePath& install_dir) { | |
| 73 DVLOG(1) << "[CrOSComponentInstallerTraits::OnCustomInstall]"; | |
| 74 #if defined(OS_CHROMEOS) | |
| 75 std::string version; | |
| 76 if (!manifest.GetString("version", &version)) { | |
| 77 return ToInstallerResult(update_client::InstallError::GENERIC_ERROR); | |
| 78 } | |
| 79 BrowserThread::PostTask( | |
| 80 BrowserThread::UI, FROM_HERE, | |
| 81 base::Bind(&ImageLoaderRegistration, version, install_dir, name)); | |
| 82 return update_client::CrxInstaller::Result(update_client::InstallError::NONE); | |
| 83 #else | |
| 84 return ToInstallerResult(update_client::InstallError::GENERIC_ERROR); | |
| 85 #endif // defined(OS_CHROMEOS) | |
| 86 } | |
| 87 | |
| 88 void CrOSComponentInstallerTraits::ComponentReady( | |
| 89 const base::Version& version, | |
| 90 const base::FilePath& path, | |
| 91 std::unique_ptr<base::DictionaryValue> manifest) {} | |
| 92 | |
| 93 bool CrOSComponentInstallerTraits::VerifyInstallation( | |
| 94 const base::DictionaryValue& manifest, | |
| 95 const base::FilePath& install_dir) const { | |
| 96 return true; | |
| 97 } | |
| 98 | |
| 99 base::FilePath CrOSComponentInstallerTraits::GetRelativeInstallDir() const { | |
| 100 return base::FilePath(FILE_PATH_LITERAL(dir_name)); | |
| 101 } | |
| 102 | |
| 103 void CrOSComponentInstallerTraits::GetHash(std::vector<uint8_t>* hash) const { | |
| 104 hash->assign(kSha2Hash_, kSha2Hash_ + arraysize(kSha2Hash_)); | |
| 105 } | |
| 106 | |
| 107 std::string CrOSComponentInstallerTraits::GetName() const { | |
| 108 return name; | |
| 109 } | |
| 110 | |
| 111 update_client::InstallerAttributes | |
| 112 CrOSComponentInstallerTraits::GetInstallerAttributes() const { | |
| 113 return update_client::InstallerAttributes(); | |
| 114 } | |
| 115 | |
| 116 std::vector<std::string> CrOSComponentInstallerTraits::GetMimeTypes() const { | |
| 117 std::vector<std::string> mime_types; | |
| 118 return mime_types; | |
| 119 } | |
| 120 | |
| 121 void RegisterCrOSComponentInternal(ComponentUpdateService* cus, | |
| 122 const ComponentConfig& config) { | |
| 123 std::unique_ptr<ComponentInstallerTraits> traits( | |
| 124 new CrOSComponentInstallerTraits(config.dir, config.name, | |
| 125 config.sha2hashstr)); | |
| 126 // |cus| will take ownership of |installer| during | |
| 127 // installer->Register(cus). | |
| 128 DefaultComponentInstaller* installer = | |
| 129 new DefaultComponentInstaller(std::move(traits)); | |
| 130 installer->Register(cus, base::Closure()); | |
| 131 } | |
| 132 | |
| 133 // an example config file content: | |
| 134 //{ | |
| 135 // "components":{ | |
| 136 // "escpr": { | |
| 137 // "dir":"epson-inkjet-printer-escpr", | |
| 138 // "sha2hashstr":"1913a5e0a6cad30b6f03e176177e0d7ed62c5d6700a9c66da556d7c3f 5d6a47e" | |
| 139 // } | |
| 140 // } | |
| 141 //} | |
| 142 bool RegisterCrOSComponentInternal(ComponentUpdateService* cus, | |
| 143 const std::string& name) { | |
| 144 if (name.length() == 0) { | |
| 145 DVLOG(1) << "[RegisterCrOSComponents] name is empty."; | |
| 146 return false; | |
| 147 } | |
| 148 if (!componentConfigReaderRoot.get()) { | |
| 149 DVLOG(1) << "[RegisterCrOSComponents] configuration is not loaded."; | |
| 150 return false; | |
| 151 } | |
| 152 auto root_dic = std::unique_ptr<base::DictionaryValue>( | |
| 153 static_cast<base::DictionaryValue*>(componentConfigReaderRoot.get())); | |
| 154 base::DictionaryValue* components = nullptr; | |
| 155 if (root_dic->GetDictionary("components", &components)) { | |
| 156 base::DictionaryValue* component = nullptr; | |
| 157 if (components->GetDictionary(name, &component)) { | |
| 158 std::string dir, sha2hashstr; | |
| 159 if (component->GetString("dir", &dir) && | |
| 160 component->GetString("sha2hashstr", &sha2hashstr) && | |
| 161 dir.length() > 0 && sha2hashstr.length() == 64) { | |
| 162 ComponentConfig config; | |
| 163 config.name = name; | |
| 164 config.dir = dir; | |
| 165 config.sha2hashstr = sha2hashstr; | |
| 166 DVLOG(1) << "[RegisterCrOSComponents] register component:" << name; | |
| 167 RegisterCrOSComponentInternal(cus, config); | |
| 168 return true; | |
| 169 } | |
| 170 } | |
| 171 } | |
| 172 DVLOG(1) << "[RegisterCrOSComponents] " | |
| 173 "component " | |
|
waffles
2017/03/01 18:49:20
Why not combine with the above line?
xiaochu
2017/03/02 01:50:05
Done.
| |
| 174 << name << " is not in configuration file."; | |
| 175 return false; | |
| 176 } | |
| 177 | |
| 178 void LoadCrOSConfigInternal() { | |
| 179 if (!componentConfigReaderRoot.get()) { | |
| 180 base::FilePath configFilePath(componentConfigReaderFilepathstr); | |
| 181 JSONFileValueDeserializer deserializer(configFilePath); | |
| 182 std::string error; | |
| 183 componentConfigReaderRoot = deserializer.Deserialize(NULL, &error); | |
|
waffles
2017/03/01 18:49:20
Consider DCHECKing that error.empty().
If you don'
xiaochu
2017/03/02 01:50:05
Done.
| |
| 184 } | |
| 185 } | |
| 186 void LoadCrOSConfig(ComponentUpdateService* cus) { | |
| 187 cus->GetSequencedTaskRunner()->PostTask(FROM_HERE, | |
| 188 base::Bind(&LoadCrOSConfigInternal)); | |
|
waffles
2017/03/01 18:49:20
I recommend instead doing:
base::PostTaskWithTrai
xiaochu
2017/03/02 01:50:05
Done.
| |
| 189 } | |
| 190 | |
| 191 bool RegisterCrOSComponent(ComponentUpdateService* cus, | |
| 192 const std::string& name) { | |
| 193 return RegisterCrOSComponentInternal(cus, name); | |
| 194 } | |
| 195 } // namespace component_updater | |
| OLD | NEW |