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

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

Issue 2707063002: Universial component install for chrome os. (Closed)
Patch Set: fix a bug Created 3 years, 9 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
(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 "base/json/json_file_value_serializer.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 VLOG(0) << "[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 RegisterCrOSComponent(ComponentUpdateService* cus,
122 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 // [
waffles 2017/02/23 17:13:20 If you always are using the name as a key, do you
xiaochu 2017/02/23 20:54:56 Done.
137 // {
138 // "name":"escpr",
139 // "dir":"epson-inkjet-printer-escpr",
140 // "sha2hashstr":"1913a5e0a6cad30b6f03e176177e0d7ed62c5d6700a9c66da556d7c3f5d6a4 7e"
141 // }
142 // ]
143 // }
waffles 2017/02/23 17:13:20 Adding indentation could make this clearer.
xiaochu 2017/02/23 20:54:56 Done.
144 bool RegisterCrOSComponent(ComponentUpdateService* cus, std::string name) {
145 base::FilePath configFilePath(filepathstr);
waffles 2017/02/23 17:13:20 Can we remember the contents of this file instead
xiaochu 2017/02/23 20:54:56 Done.
146 JSONFileValueDeserializer deserializer(configFilePath);
waffles 2017/02/23 17:13:20 What thread do you intend this function to be run
xiaochu 2017/02/23 20:54:56 I added some more options for developers: 1) UI t
xiaochu 2017/02/25 23:39:22 I just documented my idea in .h file in details. B
147 std::string error;
148 std::unique_ptr<base::Value> root = deserializer.Deserialize(NULL, &error);
149 if (!root.get()) {
150 VLOG(0) << "[RegisterCrOSComponents] configuration not exist or in wrong "
waffles 2017/02/23 17:13:20 Can we use DVLOG(1)? Also elsewhere in this file,
xiaochu 2017/02/23 20:54:56 Done.
151 "format.";
152 return false;
153 }
154 if (!root->IsType(base::Value::Type::DICTIONARY)) {
155 VLOG(0)
156 << "[RegisterCrOSComponents] top level has to be a dictionary type.";
157 return false;
158 }
159 auto components = std::unique_ptr<base::DictionaryValue>(
160 static_cast<base::DictionaryValue*>(root.release()));
161 base::ListValue* component_list = nullptr;
162 if (!components->GetList("components", &component_list)) {
163 VLOG(0) << "[RegisterCrOSComponents] component list not exist.";
164 return false;
165 }
166 for (size_t i = 0; i < component_list->GetSize(); i++) {
167 base::DictionaryValue* component = nullptr;
168 if (component_list->GetDictionary(i, &component)) {
169 std::string name_, dir, sha2hashstr;
170 if (component->GetString("name", &name_) &&
171 component->GetString("dir", &dir) &&
172 component->GetString("sha2hashstr", &sha2hashstr) &&
173 name.compare(name_) == 0 && name.length() > 0 && dir.length() > 0 &&
174 sha2hashstr.length() == 64) {
175 ComponentConfig config;
176 config.name = name_;
177 config.dir = dir;
178 config.sha2hashstr = sha2hashstr;
179 VLOG(1) << "[RegisterCrOSComponents] register component:" << name_;
180 RegisterCrOSComponent(cus, config);
181 return true;
182 }
183 }
184 }
185 VLOG(0) << "[RegisterCrOSComponents] "
186 "component name is not in configuration file.";
187 return false;
188 }
189
190 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698