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