OLD | NEW |
---|---|
(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 | |
49 CrOSComponentInstallerTraits::CrOSComponentInstallerTraits( | |
50 const ComponentConfig& config) | |
51 : dir_name(config.dir), name(config.name) { | |
52 if (config.sha2hashstr.length() != 64) | |
53 return; | |
54 auto strstream = config.sha2hashstr; | |
55 for (auto& cell : kSha2Hash_) { | |
56 cell = stoul(strstream.substr(0, 2), nullptr, 16); | |
57 strstream.erase(0, 2); | |
58 } | |
59 } | |
60 | |
61 bool CrOSComponentInstallerTraits::SupportsGroupPolicyEnabledComponentUpdates() | |
62 const { | |
63 return true; | |
64 } | |
65 | |
66 bool CrOSComponentInstallerTraits::RequiresNetworkEncryption() const { | |
67 return true; | |
68 } | |
69 | |
70 update_client::CrxInstaller::Result | |
71 CrOSComponentInstallerTraits::OnCustomInstall( | |
72 const base::DictionaryValue& manifest, | |
73 const base::FilePath& install_dir) { | |
74 DVLOG(1) << "[CrOSComponentInstallerTraits::OnCustomInstall]"; | |
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 } | |
84 | |
85 void CrOSComponentInstallerTraits::ComponentReady( | |
86 const base::Version& version, | |
87 const base::FilePath& path, | |
88 std::unique_ptr<base::DictionaryValue> manifest) {} | |
89 | |
90 bool CrOSComponentInstallerTraits::VerifyInstallation( | |
91 const base::DictionaryValue& manifest, | |
92 const base::FilePath& install_dir) const { | |
93 return true; | |
94 } | |
95 | |
96 base::FilePath CrOSComponentInstallerTraits::GetRelativeInstallDir() const { | |
97 return base::FilePath(dir_name); | |
98 } | |
99 | |
100 void CrOSComponentInstallerTraits::GetHash(std::vector<uint8_t>* hash) const { | |
101 hash->assign(kSha2Hash_, kSha2Hash_ + arraysize(kSha2Hash_)); | |
102 } | |
103 | |
104 std::string CrOSComponentInstallerTraits::GetName() const { | |
105 return name; | |
106 } | |
107 | |
108 update_client::InstallerAttributes | |
109 CrOSComponentInstallerTraits::GetInstallerAttributes() const { | |
110 return update_client::InstallerAttributes(); | |
111 } | |
112 | |
113 std::vector<std::string> CrOSComponentInstallerTraits::GetMimeTypes() const { | |
114 std::vector<std::string> mime_types; | |
115 return mime_types; | |
116 } | |
117 | |
118 void RegisterCrOSComponentInternal(ComponentUpdateService* cus, | |
119 const ComponentConfig& config) { | |
120 std::unique_ptr<ComponentInstallerTraits> traits( | |
121 new CrOSComponentInstallerTraits(config)); | |
122 // |cus| will take ownership of |installer| during | |
123 // installer->Register(cus). | |
124 DefaultComponentInstaller* installer = | |
125 new DefaultComponentInstaller(std::move(traits)); | |
126 installer->Register(cus, base::Closure()); | |
127 } | |
128 | |
129 bool RegisterCrOSComponentInternal(ComponentUpdateService* cus, | |
130 const std::string& name) { | |
131 if (name.empty()) { | |
132 DVLOG(1) << "[RegisterCrOSComponents] name is empty."; | |
133 return false; | |
134 } | |
135 const std::map<std::string, std::map<std::string, std::string>> components = { | |
136 {"escpr", | |
137 {{"dir", "epson-inkjet-printer-escpr"}, | |
138 {"sha2hashstr", | |
139 "1913a5e0a6cad30b6f03e176177e0d7ed62c5d6700a9c66da556d7c3f5d6a47e"}}}}; | |
140 const auto it = components.find(name); | |
141 if (it == components.end()) { | |
142 DVLOG(1) << "[RegisterCrOSComponents] component " << name | |
143 << " is not in configuration."; | |
144 return false; | |
145 } | |
146 ComponentConfig config(it->first, it->second.find("dir")->second, | |
147 it->second.find("sha2hashstr")->second); | |
148 RegisterCrOSComponentInternal(cus, config); | |
149 return true; | |
150 } | |
151 | |
152 #endif // defined(OS_CHROMEOS) | |
153 | |
154 bool RegisterCrOSComponent(ComponentUpdateService* cus, | |
155 const std::string& name) { | |
156 #if defined(OS_CHROMEOS) | |
157 return RegisterCrOSComponentInternal(cus, name); | |
158 #else | |
159 return false; | |
160 #endif // defined(OS_CHROMEOS) | |
161 } | |
Sorin Jianu
2017/03/03 02:19:03
ampty line
xiaochu
2017/03/03 17:16:25
Done.
| |
162 } // namespace component_updater | |
OLD | NEW |