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 "base/task_scheduler/post_task.h" | |
7 #include "base/task_scheduler/task_traits.h" | |
waffles
2017/03/02 20:50:16
Do you need the two above headers?
xiaochu
2017/03/02 21:08:34
Done.
| |
8 #include "chrome/browser/browser_process.h" | |
9 #include "chrome/browser/component_updater/component_installer_errors.h" | |
10 #include "components/component_updater/component_updater_paths.h" | |
11 #include "content/public/browser/browser_thread.h" | |
12 #include "content/public/browser/plugin_service.h" | |
waffles
2017/03/02 20:50:16
Can we remove the dependency on plugin_service.h?
xiaochu
2017/03/02 21:08:34
Done.
| |
13 | |
14 #if defined(OS_CHROMEOS) | |
15 #include "chromeos/dbus/dbus_method_call_status.h" | |
16 #include "chromeos/dbus/dbus_thread_manager.h" | |
17 #include "chromeos/dbus/image_loader_client.h" | |
18 #endif // defined(OS_CHROMEOS) | |
19 | |
20 using content::BrowserThread; | |
21 using content::PluginService; | |
waffles
2017/03/02 20:50:16
remove this line
xiaochu
2017/03/02 21:08:34
Done.
| |
22 | |
23 namespace component_updater { | |
24 | |
25 #if defined(OS_CHROMEOS) | |
26 void LogRegistrationResult(chromeos::DBusMethodCallStatus call_status, | |
27 bool result) { | |
28 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
29 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { | |
30 LOG(ERROR) << "Call to imageloader service failed."; | |
31 return; | |
32 } | |
33 if (!result) { | |
34 LOG(ERROR) << "Component registration failed"; | |
waffles
2017/03/02 20:50:16
Can this be DVLOG(1)?
Also on lines 30 and 49.
xiaochu
2017/03/02 21:08:34
Done.
| |
35 return; | |
36 } | |
37 } | |
38 void ImageLoaderRegistration(const std::string& version, | |
39 const base::FilePath& install_dir, | |
40 const std::string& name) { | |
41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
42 chromeos::ImageLoaderClient* loader = | |
43 chromeos::DBusThreadManager::Get()->GetImageLoaderClient(); | |
44 | |
45 if (loader) { | |
46 loader->RegisterComponent(name, version, install_dir.value(), | |
47 base::Bind(&LogRegistrationResult)); | |
48 } else { | |
49 LOG(ERROR) << "Failed to get ImageLoaderClient object."; | |
50 } | |
51 } | |
52 | |
53 // Determine whether or not to skip registering this cros component updates. | |
54 bool SkipCupsRegistration(ComponentUpdateService* cus) { | |
waffles
2017/03/02 20:50:15
I'm not sure what the purpose of this function is.
xiaochu
2017/03/02 21:08:34
Done.
| |
55 return false; | |
56 } | |
57 | |
58 CrOSComponentInstallerTraits::CrOSComponentInstallerTraits( | |
59 std::string dir_name, | |
60 std::string name, | |
61 std::string sha2HashStr) | |
62 : dir_name(dir_name), name(name) { | |
63 if (sha2HashStr.length() != 64) | |
64 return; | |
65 for (unsigned int i = 0; i < sizeof(kSha2Hash_); i++) { | |
66 kSha2Hash_[i] = stoul(sha2HashStr.substr(i * 2, 2), nullptr, 16); | |
67 } | |
68 } | |
69 | |
70 bool CrOSComponentInstallerTraits::SupportsGroupPolicyEnabledComponentUpdates() | |
71 const { | |
72 return true; | |
73 } | |
74 | |
75 bool CrOSComponentInstallerTraits::RequiresNetworkEncryption() const { | |
76 return false; | |
waffles
2017/03/02 20:50:15
We should think about this carefully. Since the in
xiaochu
2017/03/02 21:08:34
Done.
| |
77 } | |
78 | |
79 update_client::CrxInstaller::Result | |
80 CrOSComponentInstallerTraits::OnCustomInstall( | |
81 const base::DictionaryValue& manifest, | |
82 const base::FilePath& install_dir) { | |
83 DVLOG(1) << "[CrOSComponentInstallerTraits::OnCustomInstall]"; | |
84 std::string version; | |
85 if (!manifest.GetString("version", &version)) { | |
86 return ToInstallerResult(update_client::InstallError::GENERIC_ERROR); | |
87 } | |
88 BrowserThread::PostTask( | |
89 BrowserThread::UI, FROM_HERE, | |
90 base::Bind(&ImageLoaderRegistration, version, install_dir, name)); | |
91 return update_client::CrxInstaller::Result(update_client::InstallError::NONE); | |
92 } | |
93 | |
94 void CrOSComponentInstallerTraits::ComponentReady( | |
95 const base::Version& version, | |
96 const base::FilePath& path, | |
97 std::unique_ptr<base::DictionaryValue> manifest) {} | |
98 | |
99 bool CrOSComponentInstallerTraits::VerifyInstallation( | |
100 const base::DictionaryValue& manifest, | |
101 const base::FilePath& install_dir) const { | |
102 return true; | |
103 } | |
104 | |
105 base::FilePath CrOSComponentInstallerTraits::GetRelativeInstallDir() const { | |
106 return base::FilePath(FILE_PATH_LITERAL(dir_name)); | |
waffles
2017/03/02 20:50:15
dir_name is not literal, so don't use FILE_PATH_LI
xiaochu
2017/03/02 21:08:34
Done.
| |
107 } | |
108 | |
109 void CrOSComponentInstallerTraits::GetHash(std::vector<uint8_t>* hash) const { | |
110 hash->assign(kSha2Hash_, kSha2Hash_ + arraysize(kSha2Hash_)); | |
111 } | |
112 | |
113 std::string CrOSComponentInstallerTraits::GetName() const { | |
114 return name; | |
115 } | |
116 | |
117 update_client::InstallerAttributes | |
118 CrOSComponentInstallerTraits::GetInstallerAttributes() const { | |
119 return update_client::InstallerAttributes(); | |
120 } | |
121 | |
122 std::vector<std::string> CrOSComponentInstallerTraits::GetMimeTypes() const { | |
123 std::vector<std::string> mime_types; | |
124 return mime_types; | |
125 } | |
126 | |
127 void RegisterCrOSComponentInternal(ComponentUpdateService* cus, | |
128 const ComponentConfig& config) { | |
129 std::unique_ptr<ComponentInstallerTraits> traits( | |
130 new CrOSComponentInstallerTraits(config.dir, config.name, | |
131 config.sha2hashstr)); | |
132 // |cus| will take ownership of |installer| during | |
133 // installer->Register(cus). | |
134 DefaultComponentInstaller* installer = | |
135 new DefaultComponentInstaller(std::move(traits)); | |
136 installer->Register(cus, base::Closure()); | |
137 } | |
138 | |
139 bool RegisterCrOSComponentInternal(ComponentUpdateService* cus, | |
140 const std::string& name) { | |
141 if (name.length() == 0) { | |
142 DVLOG(1) << "[RegisterCrOSComponents] name is empty."; | |
143 return false; | |
144 } | |
145 const std::map<std::string, std::map<std::string, std::string>> components = { | |
146 {"escpr", | |
147 {{"dir", "epson-inkjet-printer-escpr"}, | |
148 {"sha2hashstr", | |
149 "1913a5e0a6cad30b6f03e176177e0d7ed62c5d6700a9c66da556d7c3f5d6a47e"}}}}; | |
150 auto component = components.find(name); | |
151 if (component != components.end()) { | |
152 ComponentConfig config; | |
153 config.name = component->first; | |
154 config.dir = component->second.find("dir")->second; | |
155 config.sha2hashstr = component->second.find("sha2hashstr")->second; | |
156 RegisterCrOSComponentInternal(cus, config); | |
157 return true; | |
158 } | |
159 DVLOG(1) << "[RegisterCrOSComponents] component " << name | |
160 << " is not in configuration."; | |
161 return false; | |
162 } | |
163 | |
164 #endif // defined(OS_CHROMEOS) | |
165 | |
166 bool RegisterCrOSComponent(ComponentUpdateService* cus, | |
167 const std::string& name) { | |
168 #if defined(OS_CHROMEOS) | |
169 return RegisterCrOSComponentInternal(cus, name); | |
170 #else | |
171 return false; | |
172 #endif // defined(OS_CHROMEOS) | |
173 } | |
174 } // namespace component_updater | |
OLD | NEW |