OLD | NEW |
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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 } | 379 } |
380 | 380 |
381 void SupervisedUserWhitelistInstallerImpl::RegisterComponents() { | 381 void SupervisedUserWhitelistInstallerImpl::RegisterComponents() { |
382 std::set<std::string> registered_whitelists; | 382 std::set<std::string> registered_whitelists; |
383 const base::DictionaryValue* whitelists = | 383 const base::DictionaryValue* whitelists = |
384 local_state_->GetDictionary(prefs::kRegisteredSupervisedUserWhitelists); | 384 local_state_->GetDictionary(prefs::kRegisteredSupervisedUserWhitelists); |
385 for (base::DictionaryValue::Iterator it(*whitelists); !it.IsAtEnd(); | 385 for (base::DictionaryValue::Iterator it(*whitelists); !it.IsAtEnd(); |
386 it.Advance()) { | 386 it.Advance()) { |
387 const base::DictionaryValue* dict = nullptr; | 387 const base::DictionaryValue* dict = nullptr; |
388 it.value().GetAsDictionary(&dict); | 388 it.value().GetAsDictionary(&dict); |
| 389 |
| 390 // Skip whitelists with no clients. This can happen when a whitelist was |
| 391 // previously registered with an empty client ID. |
| 392 const base::ListValue* clients = nullptr; |
| 393 if (!dict->GetList(kClients, &clients) || clients->empty()) |
| 394 continue; |
| 395 |
389 std::string name; | 396 std::string name; |
390 bool result = dict->GetString(kName, &name); | 397 bool result = dict->GetString(kName, &name); |
391 DCHECK(result); | 398 DCHECK(result); |
392 const std::string& id = it.key(); | 399 const std::string& id = it.key(); |
393 RegisterComponent(id, name, base::Closure()); | 400 RegisterComponent(id, name, base::Closure()); |
394 | 401 |
395 registered_whitelists.insert(id); | 402 registered_whitelists.insert(id); |
396 } | 403 } |
397 | 404 |
398 cus_->GetSequencedTaskRunner()->PostTask( | 405 cus_->GetSequencedTaskRunner()->PostTask( |
399 FROM_HERE, base::Bind(&RemoveUnregisteredWhitelistsOnTaskRunner, | 406 FROM_HERE, base::Bind(&RemoveUnregisteredWhitelistsOnTaskRunner, |
400 registered_whitelists)); | 407 registered_whitelists)); |
401 } | 408 } |
402 | 409 |
403 void SupervisedUserWhitelistInstallerImpl::Subscribe( | 410 void SupervisedUserWhitelistInstallerImpl::Subscribe( |
404 const WhitelistReadyCallback& callback) { | 411 const WhitelistReadyCallback& callback) { |
405 return callbacks_.push_back(callback); | 412 return callbacks_.push_back(callback); |
406 } | 413 } |
407 | 414 |
408 void SupervisedUserWhitelistInstallerImpl::RegisterWhitelist( | 415 void SupervisedUserWhitelistInstallerImpl::RegisterWhitelist( |
409 const std::string& client_id, | 416 const std::string& client_id, |
410 const std::string& crx_id, | 417 const std::string& crx_id, |
411 const std::string& name) { | 418 const std::string& name) { |
412 DictionaryPrefUpdate update(local_state_, | 419 DictionaryPrefUpdate update(local_state_, |
413 prefs::kRegisteredSupervisedUserWhitelists); | 420 prefs::kRegisteredSupervisedUserWhitelists); |
414 base::DictionaryValue* pref_dict = update.Get(); | 421 base::DictionaryValue* pref_dict = update.Get(); |
415 base::DictionaryValue* whitelist_dict = nullptr; | 422 base::DictionaryValue* whitelist_dict = nullptr; |
416 bool newly_added = false; | 423 const bool newly_added = |
417 if (!pref_dict->GetDictionaryWithoutPathExpansion(crx_id, &whitelist_dict)) { | 424 !pref_dict->GetDictionaryWithoutPathExpansion(crx_id, &whitelist_dict); |
| 425 if (newly_added) { |
418 whitelist_dict = new base::DictionaryValue; | 426 whitelist_dict = new base::DictionaryValue; |
419 whitelist_dict->SetString(kName, name); | 427 whitelist_dict->SetString(kName, name); |
420 pref_dict->SetWithoutPathExpansion(crx_id, whitelist_dict); | 428 pref_dict->SetWithoutPathExpansion(crx_id, whitelist_dict); |
421 newly_added = true; | |
422 } | 429 } |
423 | 430 |
424 base::ListValue* clients = nullptr; | 431 if (!client_id.empty()) { |
425 if (!whitelist_dict->GetList(kClients, &clients)) { | 432 base::ListValue* clients = nullptr; |
426 DCHECK(newly_added); | 433 if (!whitelist_dict->GetList(kClients, &clients)) { |
427 clients = new base::ListValue; | 434 DCHECK(newly_added); |
428 whitelist_dict->Set(kClients, clients); | 435 clients = new base::ListValue; |
| 436 whitelist_dict->Set(kClients, clients); |
| 437 } |
| 438 bool success = |
| 439 clients->AppendIfNotPresent(new base::StringValue(client_id)); |
| 440 DCHECK(success); |
429 } | 441 } |
430 bool success = clients->AppendIfNotPresent(new base::StringValue(client_id)); | |
431 DCHECK(success); | |
432 | 442 |
433 if (!newly_added) { | 443 if (!newly_added) { |
434 // Sanity-check that the stored name is equal to the name passed in. | 444 // Sanity-check that the stored name is equal to the name passed in. |
435 // In release builds this is a no-op. | 445 // In release builds this is a no-op. |
436 std::string stored_name; | 446 std::string stored_name; |
437 DCHECK(whitelist_dict->GetString(kName, &stored_name)); | 447 DCHECK(whitelist_dict->GetString(kName, &stored_name)); |
438 DCHECK_EQ(stored_name, name); | 448 DCHECK_EQ(stored_name, name); |
439 return; | 449 return; |
440 } | 450 } |
441 | 451 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 | 524 |
515 // static | 525 // static |
516 void SupervisedUserWhitelistInstaller::TriggerComponentUpdate( | 526 void SupervisedUserWhitelistInstaller::TriggerComponentUpdate( |
517 OnDemandUpdater* updater, | 527 OnDemandUpdater* updater, |
518 const std::string& crx_id) { | 528 const std::string& crx_id) { |
519 const bool result = updater->OnDemandUpdate(crx_id); | 529 const bool result = updater->OnDemandUpdate(crx_id); |
520 DCHECK(result); | 530 DCHECK(result); |
521 } | 531 } |
522 | 532 |
523 } // namespace component_updater | 533 } // namespace component_updater |
OLD | NEW |