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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 return callbacks_.push_back(callback); | 526 return callbacks_.push_back(callback); |
527 } | 527 } |
528 | 528 |
529 void SupervisedUserWhitelistInstallerImpl::RegisterWhitelist( | 529 void SupervisedUserWhitelistInstallerImpl::RegisterWhitelist( |
530 const std::string& client_id, | 530 const std::string& client_id, |
531 const std::string& crx_id, | 531 const std::string& crx_id, |
532 const std::string& name) { | 532 const std::string& name) { |
533 DictionaryPrefUpdate update(local_state_, | 533 DictionaryPrefUpdate update(local_state_, |
534 prefs::kRegisteredSupervisedUserWhitelists); | 534 prefs::kRegisteredSupervisedUserWhitelists); |
535 base::DictionaryValue* pref_dict = update.Get(); | 535 base::DictionaryValue* pref_dict = update.Get(); |
536 base::DictionaryValue* whitelist_dict = nullptr; | 536 base::DictionaryValue* whitelist_dict_weak = nullptr; |
537 const bool newly_added = | 537 const bool newly_added = !pref_dict->GetDictionaryWithoutPathExpansion( |
538 !pref_dict->GetDictionaryWithoutPathExpansion(crx_id, &whitelist_dict); | 538 crx_id, &whitelist_dict_weak); |
539 if (newly_added) { | 539 if (newly_added) { |
540 whitelist_dict = new base::DictionaryValue; | 540 auto whitelist_dict = base::MakeUnique<base::DictionaryValue>(); |
| 541 whitelist_dict_weak = whitelist_dict.get(); |
541 whitelist_dict->SetString(kName, name); | 542 whitelist_dict->SetString(kName, name); |
542 pref_dict->SetWithoutPathExpansion(crx_id, whitelist_dict); | 543 pref_dict->SetWithoutPathExpansion(crx_id, std::move(whitelist_dict)); |
543 } | 544 } |
544 | 545 |
545 if (!client_id.empty()) { | 546 if (!client_id.empty()) { |
546 base::ListValue* clients = nullptr; | 547 base::ListValue* clients_weak = nullptr; |
547 if (!whitelist_dict->GetList(kClients, &clients)) { | 548 if (!whitelist_dict_weak->GetList(kClients, &clients_weak)) { |
548 DCHECK(newly_added); | 549 DCHECK(newly_added); |
549 clients = new base::ListValue; | 550 auto clients = base::MakeUnique<base::ListValue>(); |
550 whitelist_dict->Set(kClients, clients); | 551 clients_weak = clients.get(); |
| 552 whitelist_dict_weak->Set(kClients, std::move(clients)); |
551 } | 553 } |
552 bool success = | 554 bool success = clients_weak->AppendIfNotPresent( |
553 clients->AppendIfNotPresent(base::MakeUnique<base::Value>(client_id)); | 555 base::MakeUnique<base::Value>(client_id)); |
554 DCHECK(success); | 556 DCHECK(success); |
555 } | 557 } |
556 | 558 |
557 if (!newly_added) { | 559 if (!newly_added) { |
558 // Sanity-check that the stored name is equal to the name passed in. | 560 // Sanity-check that the stored name is equal to the name passed in. |
559 // In release builds this is a no-op. | 561 // In release builds this is a no-op. |
560 std::string stored_name; | 562 std::string stored_name; |
561 DCHECK(whitelist_dict->GetString(kName, &stored_name)); | 563 DCHECK(whitelist_dict_weak->GetString(kName, &stored_name)); |
562 DCHECK_EQ(stored_name, name); | 564 DCHECK_EQ(stored_name, name); |
563 return; | 565 return; |
564 } | 566 } |
565 | 567 |
566 RegisterNewComponent(crx_id, name); | 568 RegisterNewComponent(crx_id, name); |
567 } | 569 } |
568 | 570 |
569 void SupervisedUserWhitelistInstallerImpl::UnregisterWhitelist( | 571 void SupervisedUserWhitelistInstallerImpl::UnregisterWhitelist( |
570 const std::string& client_id, | 572 const std::string& client_id, |
571 const std::string& crx_id) { | 573 const std::string& crx_id) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 | 649 |
648 // static | 650 // static |
649 void SupervisedUserWhitelistInstaller::TriggerComponentUpdate( | 651 void SupervisedUserWhitelistInstaller::TriggerComponentUpdate( |
650 OnDemandUpdater* updater, | 652 OnDemandUpdater* updater, |
651 const std::string& crx_id) { | 653 const std::string& crx_id) { |
652 // TODO(sorin): use a callback to check the result (crbug.com/639189). | 654 // TODO(sorin): use a callback to check the result (crbug.com/639189). |
653 updater->OnDemandUpdate(crx_id, component_updater::Callback()); | 655 updater->OnDemandUpdate(crx_id, component_updater::Callback()); |
654 } | 656 } |
655 | 657 |
656 } // namespace component_updater | 658 } // namespace component_updater |
OLD | NEW |