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

Side by Side Diff: chrome/browser/ui/webui/policy_ui_handler.cc

Issue 2812953002: Stop passing raw pointers to base::Value API in c/b/ui (Closed)
Patch Set: No ListValue::SetDouble Created 3 years, 8 months 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/policy_ui_handler.h" 5 #include "chrome/browser/ui/webui/policy_ui_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 void PolicyUIHandler::SendPolicyNames() const { 637 void PolicyUIHandler::SendPolicyNames() const {
638 base::DictionaryValue names; 638 base::DictionaryValue names;
639 639
640 Profile* profile = Profile::FromWebUI(web_ui()); 640 Profile* profile = Profile::FromWebUI(web_ui());
641 policy::SchemaRegistry* registry = 641 policy::SchemaRegistry* registry =
642 policy::SchemaRegistryServiceFactory::GetForContext( 642 policy::SchemaRegistryServiceFactory::GetForContext(
643 profile->GetOriginalProfile())->registry(); 643 profile->GetOriginalProfile())->registry();
644 scoped_refptr<policy::SchemaMap> schema_map = registry->schema_map(); 644 scoped_refptr<policy::SchemaMap> schema_map = registry->schema_map();
645 645
646 // Add Chrome policy names. 646 // Add Chrome policy names.
647 base::DictionaryValue* chrome_policy_names = new base::DictionaryValue; 647 auto chrome_policy_names = base::MakeUnique<base::DictionaryValue>();
648 policy::PolicyNamespace chrome_ns(policy::POLICY_DOMAIN_CHROME, ""); 648 policy::PolicyNamespace chrome_ns(policy::POLICY_DOMAIN_CHROME, "");
649 const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns); 649 const policy::Schema* chrome_schema = schema_map->GetSchema(chrome_ns);
650 for (policy::Schema::Iterator it = chrome_schema->GetPropertiesIterator(); 650 for (policy::Schema::Iterator it = chrome_schema->GetPropertiesIterator();
651 !it.IsAtEnd(); it.Advance()) { 651 !it.IsAtEnd(); it.Advance()) {
652 AddPolicyName(it.key(), chrome_policy_names); 652 AddPolicyName(it.key(), chrome_policy_names.get());
653 } 653 }
654 names.Set("chromePolicyNames", chrome_policy_names); 654 names.Set("chromePolicyNames", std::move(chrome_policy_names));
655 655
656 #if BUILDFLAG(ENABLE_EXTENSIONS) 656 #if BUILDFLAG(ENABLE_EXTENSIONS)
657 // Add extension policy names. 657 // Add extension policy names.
658 base::DictionaryValue* extension_policy_names = new base::DictionaryValue; 658 auto extension_policy_names = base::MakeUnique<base::DictionaryValue>();
659 659
660 for (const scoped_refptr<const extensions::Extension>& extension : 660 for (const scoped_refptr<const extensions::Extension>& extension :
661 extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) { 661 extensions::ExtensionRegistry::Get(profile)->enabled_extensions()) {
662 // Skip this extension if it's not an enterprise extension. 662 // Skip this extension if it's not an enterprise extension.
663 if (!extension->manifest()->HasPath( 663 if (!extension->manifest()->HasPath(
664 extensions::manifest_keys::kStorageManagedSchema)) 664 extensions::manifest_keys::kStorageManagedSchema))
665 continue; 665 continue;
666 base::DictionaryValue* extension_value = new base::DictionaryValue; 666 auto extension_value = base::MakeUnique<base::DictionaryValue>();
667 extension_value->SetString("name", extension->name()); 667 extension_value->SetString("name", extension->name());
668 const policy::Schema* schema = 668 const policy::Schema* schema =
669 schema_map->GetSchema(policy::PolicyNamespace( 669 schema_map->GetSchema(policy::PolicyNamespace(
670 policy::POLICY_DOMAIN_EXTENSIONS, extension->id())); 670 policy::POLICY_DOMAIN_EXTENSIONS, extension->id()));
671 base::DictionaryValue* policy_names = new base::DictionaryValue; 671 auto policy_names = base::MakeUnique<base::DictionaryValue>();
672 if (schema && schema->valid()) { 672 if (schema && schema->valid()) {
673 // Get policy names from the extension's policy schema. 673 // Get policy names from the extension's policy schema.
674 // Store in a map, not an array, for faster lookup on JS side. 674 // Store in a map, not an array, for faster lookup on JS side.
675 for (policy::Schema::Iterator prop = schema->GetPropertiesIterator(); 675 for (policy::Schema::Iterator prop = schema->GetPropertiesIterator();
676 !prop.IsAtEnd(); prop.Advance()) { 676 !prop.IsAtEnd(); prop.Advance()) {
677 policy_names->SetBoolean(prop.key(), true); 677 policy_names->SetBoolean(prop.key(), true);
678 } 678 }
679 } 679 }
680 extension_value->Set("policyNames", policy_names); 680 extension_value->Set("policyNames", std::move(policy_names));
681 extension_policy_names->Set(extension->id(), extension_value); 681 extension_policy_names->Set(extension->id(), std::move(extension_value));
682 } 682 }
683 names.Set("extensionPolicyNames", extension_policy_names); 683 names.Set("extensionPolicyNames", std::move(extension_policy_names));
684 #endif // BUILDFLAG(ENABLE_EXTENSIONS) 684 #endif // BUILDFLAG(ENABLE_EXTENSIONS)
685 685
686 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.setPolicyNames", names); 686 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.setPolicyNames", names);
687 } 687 }
688 688
689 void PolicyUIHandler::SendPolicyValues() const { 689 void PolicyUIHandler::SendPolicyValues() const {
690 base::DictionaryValue all_policies; 690 base::DictionaryValue all_policies;
691 691
692 // Add Chrome policy values. 692 // Add Chrome policy values.
693 base::DictionaryValue* chrome_policies = new base::DictionaryValue; 693 auto chrome_policies = base::MakeUnique<base::DictionaryValue>();
694 GetChromePolicyValues(chrome_policies); 694 GetChromePolicyValues(chrome_policies.get());
695 all_policies.Set("chromePolicies", chrome_policies); 695 all_policies.Set("chromePolicies", std::move(chrome_policies));
696 696
697 #if BUILDFLAG(ENABLE_EXTENSIONS) 697 #if BUILDFLAG(ENABLE_EXTENSIONS)
698 // Add extension policy values. 698 // Add extension policy values.
699 extensions::ExtensionRegistry* registry = 699 extensions::ExtensionRegistry* registry =
700 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui())); 700 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui()));
701 base::DictionaryValue* extension_values = new base::DictionaryValue; 701 auto extension_values = base::MakeUnique<base::DictionaryValue>();
702 702
703 for (const scoped_refptr<const extensions::Extension>& extension : 703 for (const scoped_refptr<const extensions::Extension>& extension :
704 registry->enabled_extensions()) { 704 registry->enabled_extensions()) {
705 // Skip this extension if it's not an enterprise extension. 705 // Skip this extension if it's not an enterprise extension.
706 if (!extension->manifest()->HasPath( 706 if (!extension->manifest()->HasPath(
707 extensions::manifest_keys::kStorageManagedSchema)) 707 extensions::manifest_keys::kStorageManagedSchema))
708 continue; 708 continue;
709 base::DictionaryValue* extension_policies = new base::DictionaryValue; 709 auto extension_policies = base::MakeUnique<base::DictionaryValue>();
710 policy::PolicyNamespace policy_namespace = policy::PolicyNamespace( 710 policy::PolicyNamespace policy_namespace = policy::PolicyNamespace(
711 policy::POLICY_DOMAIN_EXTENSIONS, extension->id()); 711 policy::POLICY_DOMAIN_EXTENSIONS, extension->id());
712 policy::PolicyErrorMap empty_error_map; 712 policy::PolicyErrorMap empty_error_map;
713 GetPolicyValues(GetPolicyService()->GetPolicies(policy_namespace), 713 GetPolicyValues(GetPolicyService()->GetPolicies(policy_namespace),
714 &empty_error_map, extension_policies); 714 &empty_error_map, extension_policies.get());
715 extension_values->Set(extension->id(), extension_policies); 715 extension_values->Set(extension->id(), std::move(extension_policies));
716 } 716 }
717 all_policies.Set("extensionPolicies", extension_values); 717 all_policies.Set("extensionPolicies", std::move(extension_values));
718 #endif 718 #endif
719 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.setPolicyValues", 719 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.setPolicyValues",
720 all_policies); 720 all_policies);
721 } 721 }
722 722
723 void PolicyUIHandler::GetPolicyValues(const policy::PolicyMap& map, 723 void PolicyUIHandler::GetPolicyValues(const policy::PolicyMap& map,
724 policy::PolicyErrorMap* errors, 724 policy::PolicyErrorMap* errors,
725 base::DictionaryValue* values) const { 725 base::DictionaryValue* values) const {
726 for (const auto& entry : map) { 726 for (const auto& entry : map) {
727 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue); 727 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 device_status->SetString("domain", device_domain_); 772 device_status->SetString("domain", device_domain_);
773 std::unique_ptr<base::DictionaryValue> user_status(new base::DictionaryValue); 773 std::unique_ptr<base::DictionaryValue> user_status(new base::DictionaryValue);
774 user_status_provider_->GetStatus(user_status.get()); 774 user_status_provider_->GetStatus(user_status.get());
775 std::string username; 775 std::string username;
776 user_status->GetString("username", &username); 776 user_status->GetString("username", &username);
777 if (!username.empty()) 777 if (!username.empty())
778 user_status->SetString("domain", gaia::ExtractDomainName(username)); 778 user_status->SetString("domain", gaia::ExtractDomainName(username));
779 779
780 base::DictionaryValue status; 780 base::DictionaryValue status;
781 if (!device_status->empty()) 781 if (!device_status->empty())
782 status.Set("device", device_status.release()); 782 status.Set("device", std::move(device_status));
783 if (!user_status->empty()) 783 if (!user_status->empty())
784 status.Set("user", user_status.release()); 784 status.Set("user", std::move(user_status));
785 785
786 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.setStatus", status); 786 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.setStatus", status);
787 } 787 }
788 788
789 void PolicyUIHandler::HandleInitialized(const base::ListValue* args) { 789 void PolicyUIHandler::HandleInitialized(const base::ListValue* args) {
790 SendPolicyNames(); 790 SendPolicyNames();
791 SendPolicyValues(); 791 SendPolicyValues();
792 SendStatus(); 792 SendStatus();
793 } 793 }
794 794
(...skipping 20 matching lines...) Expand all
815 } 815 }
816 816
817 void PolicyUIHandler::OnRefreshPoliciesDone() const { 817 void PolicyUIHandler::OnRefreshPoliciesDone() const {
818 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.reloadPoliciesDone"); 818 web_ui()->CallJavascriptFunctionUnsafe("policy.Page.reloadPoliciesDone");
819 } 819 }
820 820
821 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { 821 policy::PolicyService* PolicyUIHandler::GetPolicyService() const {
822 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( 822 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext(
823 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); 823 web_ui()->GetWebContents()->GetBrowserContext())->policy_service();
824 } 824 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698