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

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

Issue 2707063002: Universial component install for chrome os. (Closed)
Patch Set: build unit_test only on chromeos 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 2017 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 "chrome/browser/component_updater/component_installer_errors.h"
8 #include "components/component_updater/component_updater_paths.h"
9 #include "content/public/browser/browser_thread.h"
10
11 #if defined(OS_CHROMEOS)
12 #include "chromeos/dbus/dbus_method_call_status.h"
13 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "chromeos/dbus/image_loader_client.h"
15 #endif // defined(OS_CHROMEOS)
16
17 using content::BrowserThread;
18
19 namespace component_updater {
20
21 #if defined(OS_CHROMEOS)
22 void LogRegistrationResult(chromeos::DBusMethodCallStatus call_status,
23 bool result) {
24 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
25 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) {
26 DVLOG(1) << "Call to imageloader service failed.";
27 return;
28 }
29 if (!result) {
30 DVLOG(1) << "Component registration failed";
31 return;
32 }
33 }
34 void ImageLoaderRegistration(const std::string& version,
35 const base::FilePath& install_dir,
36 const std::string& name) {
37 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
38 chromeos::ImageLoaderClient* loader =
39 chromeos::DBusThreadManager::Get()->GetImageLoaderClient();
40
41 if (loader) {
42 loader->RegisterComponent(name, version, install_dir.value(),
43 base::Bind(&LogRegistrationResult));
44 } else {
45 DVLOG(1) << "Failed to get ImageLoaderClient object.";
46 }
47 }
48 ComponentConfig::ComponentConfig(const std::string& name,
49 const std::string& dir,
50 const std::string& sha2hashstr)
51 : name(name), dir(dir), sha2hashstr(sha2hashstr) {}
52 ComponentConfig::~ComponentConfig() {}
53
54 CrOSComponentInstallerTraits::CrOSComponentInstallerTraits(
55 const ComponentConfig& config)
56 : dir_name(config.dir), name(config.name) {
57 if (config.sha2hashstr.length() != 64)
58 return;
59 auto strstream = config.sha2hashstr;
60 for (auto& cell : kSha2Hash_) {
61 cell = stoul(strstream.substr(0, 2), nullptr, 16);
62 strstream.erase(0, 2);
63 }
64 }
65
66 bool CrOSComponentInstallerTraits::SupportsGroupPolicyEnabledComponentUpdates()
67 const {
68 return true;
69 }
70
71 bool CrOSComponentInstallerTraits::RequiresNetworkEncryption() const {
72 return true;
73 }
74
75 update_client::CrxInstaller::Result
76 CrOSComponentInstallerTraits::OnCustomInstall(
77 const base::DictionaryValue& manifest,
78 const base::FilePath& install_dir) {
79 DVLOG(1) << "[CrOSComponentInstallerTraits::OnCustomInstall]";
80 std::string version;
81 if (!manifest.GetString("version", &version)) {
82 return ToInstallerResult(update_client::InstallError::GENERIC_ERROR);
83 }
84 BrowserThread::PostTask(
85 BrowserThread::UI, FROM_HERE,
86 base::Bind(&ImageLoaderRegistration, version, install_dir, name));
87 return update_client::CrxInstaller::Result(update_client::InstallError::NONE);
88 }
89
90 void CrOSComponentInstallerTraits::ComponentReady(
91 const base::Version& version,
92 const base::FilePath& path,
93 std::unique_ptr<base::DictionaryValue> manifest) {}
94
95 bool CrOSComponentInstallerTraits::VerifyInstallation(
96 const base::DictionaryValue& manifest,
97 const base::FilePath& install_dir) const {
98 return true;
99 }
100
101 base::FilePath CrOSComponentInstallerTraits::GetRelativeInstallDir() const {
102 return base::FilePath(dir_name);
103 }
104
105 void CrOSComponentInstallerTraits::GetHash(std::vector<uint8_t>* hash) const {
106 hash->assign(kSha2Hash_, kSha2Hash_ + arraysize(kSha2Hash_));
107 }
108
109 std::string CrOSComponentInstallerTraits::GetName() const {
110 return name;
111 }
112
113 update_client::InstallerAttributes
114 CrOSComponentInstallerTraits::GetInstallerAttributes() const {
115 return update_client::InstallerAttributes();
116 }
117
118 std::vector<std::string> CrOSComponentInstallerTraits::GetMimeTypes() const {
119 std::vector<std::string> mime_types;
120 return mime_types;
121 }
122
123 void RegisterCrOSComponentInternal(ComponentUpdateService* cus,
124 const ComponentConfig& config) {
125 std::unique_ptr<ComponentInstallerTraits> traits(
126 new CrOSComponentInstallerTraits(config));
127 // |cus| will take ownership of |installer| during
128 // installer->Register(cus).
129 DefaultComponentInstaller* installer =
130 new DefaultComponentInstaller(std::move(traits));
131 installer->Register(cus, base::Closure());
132 }
133
134 bool RegisterCrOSComponentInternal(ComponentUpdateService* cus,
135 const std::string& name) {
136 if (name.empty()) {
137 DVLOG(1) << "[RegisterCrOSComponents] name is empty.";
138 return false;
139 }
140 const std::map<std::string, std::map<std::string, std::string>> components = {
141 {"escpr",
142 {{"dir", "epson-inkjet-printer-escpr"},
143 {"sha2hashstr",
144 "1913a5e0a6cad30b6f03e176177e0d7ed62c5d6700a9c66da556d7c3f5d6a47e"}}}};
145 const auto it = components.find(name);
146 if (it == components.end()) {
147 DVLOG(1) << "[RegisterCrOSComponents] component " << name
148 << " is not in configuration.";
149 return false;
150 }
151 ComponentConfig config(it->first, it->second.find("dir")->second,
152 it->second.find("sha2hashstr")->second);
153 RegisterCrOSComponentInternal(cus, config);
154 return true;
155 }
156
157 #endif // defined(OS_CHROMEOS)
158
159 bool RegisterCrOSComponent(ComponentUpdateService* cus,
160 const std::string& name) {
161 #if defined(OS_CHROMEOS)
162 return RegisterCrOSComponentInternal(cus, name);
163 #else
164 return false;
165 #endif // defined(OS_CHROMEOS)
166 }
167
168 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698