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

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

Issue 1443033004: Supervised User whitelists: update to json format v2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove l10n Created 5 years, 1 month 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h " 5 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h "
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/files/file_enumerator.h" 9 #include "base/files/file_enumerator.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 22 matching lines...) Expand all
33 #include "components/crx_file/id_util.h" 33 #include "components/crx_file/id_util.h"
34 #include "components/safe_json/json_sanitizer.h" 34 #include "components/safe_json/json_sanitizer.h"
35 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
36 36
37 namespace component_updater { 37 namespace component_updater {
38 38
39 namespace { 39 namespace {
40 40
41 const char kSanitizedWhitelistExtension[] = ".json"; 41 const char kSanitizedWhitelistExtension[] = ".json";
42 42
43 const char kWhitelist[] = "whitelist"; 43 const char kWhitelistedContent[] = "whitelisted_content";
44 const char kFile[] = "file"; 44 const char kSites[] = "sites";
45 45
46 const char kClients[] = "clients"; 46 const char kClients[] = "clients";
47 const char kName[] = "name"; 47 const char kName[] = "name";
48 48
49 // These are copies of extensions::manifest_keys::kName and kShortName. They
50 // are duplicated here because we mustn't depend on code from extensions/
51 // (since it's not built on Android).
52 const char kExtensionName[] = "name";
53 const char kExtensionShortName[] = "short_name";
54
55 base::string16 GetWhitelistTitle(const base::DictionaryValue& manifest) {
56 base::string16 title;
57 if (!manifest.GetString(kExtensionShortName, &title))
58 manifest.GetString(kExtensionName, &title);
59 return title;
60 }
61
49 base::FilePath GetRawWhitelistPath(const base::DictionaryValue& manifest, 62 base::FilePath GetRawWhitelistPath(const base::DictionaryValue& manifest,
50 const base::FilePath& install_dir) { 63 const base::FilePath& install_dir) {
51 const base::DictionaryValue* whitelist_dict = nullptr; 64 const base::DictionaryValue* whitelist_dict = nullptr;
52 if (!manifest.GetDictionary(kWhitelist, &whitelist_dict)) 65 if (!manifest.GetDictionary(kWhitelistedContent, &whitelist_dict))
53 return base::FilePath(); 66 return base::FilePath();
54 67
55 base::FilePath::StringType whitelist_file; 68 base::FilePath::StringType whitelist_file;
56 if (!whitelist_dict->GetString(kFile, &whitelist_file)) 69 if (!whitelist_dict->GetString(kSites, &whitelist_file))
57 return base::FilePath(); 70 return base::FilePath();
58 71
59 return install_dir.Append(whitelist_file); 72 return install_dir.Append(whitelist_file);
60 } 73 }
61 74
62 base::FilePath GetSanitizedWhitelistPath(const std::string& crx_id) { 75 base::FilePath GetSanitizedWhitelistPath(const std::string& crx_id) {
63 base::FilePath base_dir; 76 base::FilePath base_dir;
64 PathService::Get(chrome::DIR_SUPERVISED_USER_INSTALLED_WHITELISTS, &base_dir); 77 PathService::Get(chrome::DIR_SUPERVISED_USER_INSTALLED_WHITELISTS, &base_dir);
65 return base_dir.empty() 78 return base_dir.empty()
66 ? base::FilePath() 79 ? base::FilePath()
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 193
181 if (!base::DeleteFile(path, true)) 194 if (!base::DeleteFile(path, true))
182 DPLOG(ERROR) << "Couldn't delete " << path.value(); 195 DPLOG(ERROR) << "Couldn't delete " << path.value();
183 } 196 }
184 } 197 }
185 } 198 }
186 199
187 class SupervisedUserWhitelistComponentInstallerTraits 200 class SupervisedUserWhitelistComponentInstallerTraits
188 : public ComponentInstallerTraits { 201 : public ComponentInstallerTraits {
189 public: 202 public:
203 using RawWhitelistReadyCallback =
204 base::Callback<void(const base::string16&, const base::FilePath&)>;
205
190 SupervisedUserWhitelistComponentInstallerTraits( 206 SupervisedUserWhitelistComponentInstallerTraits(
191 const std::string& crx_id, 207 const std::string& crx_id,
192 const std::string& name, 208 const std::string& name,
193 const base::Callback<void(const base::FilePath&)>& callback) 209 const RawWhitelistReadyCallback& callback)
194 : crx_id_(crx_id), name_(name), callback_(callback) {} 210 : crx_id_(crx_id), name_(name), callback_(callback) {}
195 ~SupervisedUserWhitelistComponentInstallerTraits() override {} 211 ~SupervisedUserWhitelistComponentInstallerTraits() override {}
196 212
197 private: 213 private:
198 // ComponentInstallerTraits overrides: 214 // ComponentInstallerTraits overrides:
199 bool VerifyInstallation(const base::DictionaryValue& manifest, 215 bool VerifyInstallation(const base::DictionaryValue& manifest,
200 const base::FilePath& install_dir) const override; 216 const base::FilePath& install_dir) const override;
201 bool CanAutoUpdate() const override; 217 bool CanAutoUpdate() const override;
202 bool OnCustomInstall(const base::DictionaryValue& manifest, 218 bool OnCustomInstall(const base::DictionaryValue& manifest,
203 const base::FilePath& install_dir) override; 219 const base::FilePath& install_dir) override;
204 void ComponentReady(const base::Version& version, 220 void ComponentReady(const base::Version& version,
205 const base::FilePath& install_dir, 221 const base::FilePath& install_dir,
206 scoped_ptr<base::DictionaryValue> manifest) override; 222 scoped_ptr<base::DictionaryValue> manifest) override;
207 base::FilePath GetBaseDirectory() const override; 223 base::FilePath GetBaseDirectory() const override;
208 void GetHash(std::vector<uint8_t>* hash) const override; 224 void GetHash(std::vector<uint8_t>* hash) const override;
209 std::string GetName() const override; 225 std::string GetName() const override;
210 226
211 std::string crx_id_; 227 std::string crx_id_;
212 std::string name_; 228 std::string name_;
213 base::Callback<void(const base::FilePath&)> callback_; 229 RawWhitelistReadyCallback callback_;
214 230
215 DISALLOW_COPY_AND_ASSIGN(SupervisedUserWhitelistComponentInstallerTraits); 231 DISALLOW_COPY_AND_ASSIGN(SupervisedUserWhitelistComponentInstallerTraits);
216 }; 232 };
217 233
218 bool SupervisedUserWhitelistComponentInstallerTraits::VerifyInstallation( 234 bool SupervisedUserWhitelistComponentInstallerTraits::VerifyInstallation(
219 const base::DictionaryValue& manifest, 235 const base::DictionaryValue& manifest,
220 const base::FilePath& install_dir) const { 236 const base::FilePath& install_dir) const {
221 // Check whether the whitelist exists at the path specified by the manifest. 237 // Check whether the whitelist exists at the path specified by the manifest.
222 // This does not check whether the whitelist is wellformed. 238 // This does not check whether the whitelist is wellformed.
223 return base::PathExists(GetRawWhitelistPath(manifest, install_dir)); 239 return base::PathExists(GetRawWhitelistPath(manifest, install_dir));
224 } 240 }
225 241
226 bool SupervisedUserWhitelistComponentInstallerTraits::CanAutoUpdate() const { 242 bool SupervisedUserWhitelistComponentInstallerTraits::CanAutoUpdate() const {
227 return true; 243 return true;
228 } 244 }
229 245
230 bool SupervisedUserWhitelistComponentInstallerTraits::OnCustomInstall( 246 bool SupervisedUserWhitelistComponentInstallerTraits::OnCustomInstall(
231 const base::DictionaryValue& manifest, 247 const base::DictionaryValue& manifest,
232 const base::FilePath& install_dir) { 248 const base::FilePath& install_dir) {
233 // Delete the existing sanitized whitelist. 249 // Delete the existing sanitized whitelist.
234 return base::DeleteFile(GetSanitizedWhitelistPath(crx_id_), false); 250 return base::DeleteFile(GetSanitizedWhitelistPath(crx_id_), false);
235 } 251 }
236 252
237 void SupervisedUserWhitelistComponentInstallerTraits::ComponentReady( 253 void SupervisedUserWhitelistComponentInstallerTraits::ComponentReady(
238 const base::Version& version, 254 const base::Version& version,
239 const base::FilePath& install_dir, 255 const base::FilePath& install_dir,
240 scoped_ptr<base::DictionaryValue> manifest) { 256 scoped_ptr<base::DictionaryValue> manifest) {
241 callback_.Run(GetRawWhitelistPath(*manifest, install_dir)); 257 // TODO(treib): Before getting the title, we should localize the manifest
258 // using extension_l10n_util::LocalizeExtension, but that doesn't exist on
259 // Android. crbug.com/558387
260 callback_.Run(GetWhitelistTitle(*manifest),
261 GetRawWhitelistPath(*manifest, install_dir));
242 } 262 }
243 263
244 base::FilePath 264 base::FilePath
245 SupervisedUserWhitelistComponentInstallerTraits::GetBaseDirectory() const { 265 SupervisedUserWhitelistComponentInstallerTraits::GetBaseDirectory() const {
246 base::FilePath whitelist_directory; 266 base::FilePath whitelist_directory;
247 PathService::Get(DIR_SUPERVISED_USER_WHITELISTS, &whitelist_directory); 267 PathService::Get(DIR_SUPERVISED_USER_WHITELISTS, &whitelist_directory);
248 return whitelist_directory.AppendASCII(crx_id_); 268 return whitelist_directory.AppendASCII(crx_id_);
249 } 269 }
250 270
251 void SupervisedUserWhitelistComponentInstallerTraits::GetHash( 271 void SupervisedUserWhitelistComponentInstallerTraits::GetHash(
(...skipping 17 matching lines...) Expand all
269 private: 289 private:
270 void RegisterComponent(const std::string& crx_id, 290 void RegisterComponent(const std::string& crx_id,
271 const std::string& name, 291 const std::string& name,
272 const base::Closure& callback); 292 const base::Closure& callback);
273 void RegisterNewComponent(const std::string& crx_id, const std::string& name); 293 void RegisterNewComponent(const std::string& crx_id, const std::string& name);
274 bool UnregisterWhitelistInternal(base::DictionaryValue* pref_dict, 294 bool UnregisterWhitelistInternal(base::DictionaryValue* pref_dict,
275 const std::string& client_id, 295 const std::string& client_id,
276 const std::string& crx_id); 296 const std::string& crx_id);
277 297
278 void OnRawWhitelistReady(const std::string& crx_id, 298 void OnRawWhitelistReady(const std::string& crx_id,
299 const base::string16& title,
279 const base::FilePath& whitelist_path); 300 const base::FilePath& whitelist_path);
280 void OnSanitizedWhitelistReady(const std::string& crx_id); 301 void OnSanitizedWhitelistReady(const std::string& crx_id,
302 const base::string16& title);
281 303
282 // SupervisedUserWhitelistInstaller overrides: 304 // SupervisedUserWhitelistInstaller overrides:
283 void RegisterComponents() override; 305 void RegisterComponents() override;
284 void Subscribe(const WhitelistReadyCallback& callback) override; 306 void Subscribe(const WhitelistReadyCallback& callback) override;
285 void RegisterWhitelist(const std::string& client_id, 307 void RegisterWhitelist(const std::string& client_id,
286 const std::string& crx_id, 308 const std::string& crx_id,
287 const std::string& name) override; 309 const std::string& name) override;
288 void UnregisterWhitelist(const std::string& client_id, 310 void UnregisterWhitelist(const std::string& client_id,
289 const std::string& crx_id) override; 311 const std::string& crx_id) override;
290 312
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 DCHECK(result); 384 DCHECK(result);
363 385
364 result = base::DeleteFile(GetSanitizedWhitelistPath(crx_id), false); 386 result = base::DeleteFile(GetSanitizedWhitelistPath(crx_id), false);
365 DCHECK(result); 387 DCHECK(result);
366 388
367 return removed; 389 return removed;
368 } 390 }
369 391
370 void SupervisedUserWhitelistInstallerImpl::OnRawWhitelistReady( 392 void SupervisedUserWhitelistInstallerImpl::OnRawWhitelistReady(
371 const std::string& crx_id, 393 const std::string& crx_id,
394 const base::string16& title,
372 const base::FilePath& whitelist_path) { 395 const base::FilePath& whitelist_path) {
373 cus_->GetSequencedTaskRunner()->PostTask( 396 cus_->GetSequencedTaskRunner()->PostTask(
374 FROM_HERE, 397 FROM_HERE,
375 base::Bind( 398 base::Bind(
376 &CheckForSanitizedWhitelistOnTaskRunner, crx_id, whitelist_path, 399 &CheckForSanitizedWhitelistOnTaskRunner, crx_id, whitelist_path,
377 base::ThreadTaskRunnerHandle::Get(), 400 base::ThreadTaskRunnerHandle::Get(),
378 base::Bind( 401 base::Bind(
379 &SupervisedUserWhitelistInstallerImpl::OnSanitizedWhitelistReady, 402 &SupervisedUserWhitelistInstallerImpl::OnSanitizedWhitelistReady,
380 weak_ptr_factory_.GetWeakPtr(), crx_id))); 403 weak_ptr_factory_.GetWeakPtr(), crx_id, title)));
381 } 404 }
382 405
383 void SupervisedUserWhitelistInstallerImpl::OnSanitizedWhitelistReady( 406 void SupervisedUserWhitelistInstallerImpl::OnSanitizedWhitelistReady(
384 const std::string& crx_id) { 407 const std::string& crx_id,
408 const base::string16& title) {
385 for (const WhitelistReadyCallback& callback : callbacks_) 409 for (const WhitelistReadyCallback& callback : callbacks_)
386 callback.Run(crx_id, GetSanitizedWhitelistPath(crx_id)); 410 callback.Run(crx_id, title, GetSanitizedWhitelistPath(crx_id));
387 } 411 }
388 412
389 void SupervisedUserWhitelistInstallerImpl::RegisterComponents() { 413 void SupervisedUserWhitelistInstallerImpl::RegisterComponents() {
390 const std::map<std::string, std::string> command_line_whitelists = 414 const std::map<std::string, std::string> command_line_whitelists =
391 SupervisedUserWhitelistService::GetWhitelistsFromCommandLine(); 415 SupervisedUserWhitelistService::GetWhitelistsFromCommandLine();
392 416
393 std::set<std::string> registered_whitelists; 417 std::set<std::string> registered_whitelists;
394 std::set<std::string> stale_whitelists; 418 std::set<std::string> stale_whitelists;
395 DictionaryPrefUpdate update(local_state_, 419 DictionaryPrefUpdate update(local_state_,
396 prefs::kRegisteredSupervisedUserWhitelists); 420 prefs::kRegisteredSupervisedUserWhitelists);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 569
546 // static 570 // static
547 void SupervisedUserWhitelistInstaller::TriggerComponentUpdate( 571 void SupervisedUserWhitelistInstaller::TriggerComponentUpdate(
548 OnDemandUpdater* updater, 572 OnDemandUpdater* updater,
549 const std::string& crx_id) { 573 const std::string& crx_id) {
550 const bool result = updater->OnDemandUpdate(crx_id); 574 const bool result = updater->OnDemandUpdate(crx_id);
551 DCHECK(result); 575 DCHECK(result);
552 } 576 }
553 577
554 } // namespace component_updater 578 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698