| OLD | NEW |
| 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 "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| 20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/policy/profile_policy_connector.h" | 23 #include "chrome/browser/policy/profile_policy_connector.h" |
| 23 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 24 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 24 #include "chrome/browser/policy/schema_registry_service.h" | 25 #include "chrome/browser/policy/schema_registry_service.h" |
| 25 #include "chrome/browser/policy/schema_registry_service_factory.h" | 26 #include "chrome/browser/policy/schema_registry_service_factory.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 159 } |
| 159 | 160 |
| 160 void ExtractDomainFromUsername(base::DictionaryValue* dict) { | 161 void ExtractDomainFromUsername(base::DictionaryValue* dict) { |
| 161 std::string username; | 162 std::string username; |
| 162 dict->GetString("username", &username); | 163 dict->GetString("username", &username); |
| 163 if (!username.empty()) | 164 if (!username.empty()) |
| 164 dict->SetString("domain", gaia::ExtractDomainName(username)); | 165 dict->SetString("domain", gaia::ExtractDomainName(username)); |
| 165 } | 166 } |
| 166 | 167 |
| 167 // Utility function that returns a JSON serialization of the given |dict|. | 168 // Utility function that returns a JSON serialization of the given |dict|. |
| 168 scoped_ptr<base::StringValue> DictionaryToJSONString( | 169 std::unique_ptr<base::StringValue> DictionaryToJSONString( |
| 169 const base::DictionaryValue& dict) { | 170 const base::DictionaryValue& dict) { |
| 170 std::string json_string; | 171 std::string json_string; |
| 171 base::JSONWriter::WriteWithOptions(dict, | 172 base::JSONWriter::WriteWithOptions(dict, |
| 172 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 173 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 173 &json_string); | 174 &json_string); |
| 174 return make_scoped_ptr(new base::StringValue(json_string)); | 175 return base::WrapUnique(new base::StringValue(json_string)); |
| 175 } | 176 } |
| 176 | 177 |
| 177 // Returns a copy of |value| with some values converted to a representation that | 178 // Returns a copy of |value| with some values converted to a representation that |
| 178 // i18n_template.js will display in a nicer way. | 179 // i18n_template.js will display in a nicer way. |
| 179 scoped_ptr<base::Value> CopyAndConvert(const base::Value* value) { | 180 std::unique_ptr<base::Value> CopyAndConvert(const base::Value* value) { |
| 180 const base::DictionaryValue* dict = NULL; | 181 const base::DictionaryValue* dict = NULL; |
| 181 if (value->GetAsDictionary(&dict)) | 182 if (value->GetAsDictionary(&dict)) |
| 182 return DictionaryToJSONString(*dict); | 183 return DictionaryToJSONString(*dict); |
| 183 | 184 |
| 184 scoped_ptr<base::Value> copy(value->DeepCopy()); | 185 std::unique_ptr<base::Value> copy(value->DeepCopy()); |
| 185 base::ListValue* list = NULL; | 186 base::ListValue* list = NULL; |
| 186 if (copy->GetAsList(&list)) { | 187 if (copy->GetAsList(&list)) { |
| 187 for (size_t i = 0; i < list->GetSize(); ++i) { | 188 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 188 if (list->GetDictionary(i, &dict)) | 189 if (list->GetDictionary(i, &dict)) |
| 189 list->Set(i, DictionaryToJSONString(*dict).release()); | 190 list->Set(i, DictionaryToJSONString(*dict).release()); |
| 190 } | 191 } |
| 191 } | 192 } |
| 192 | 193 |
| 193 return copy; | 194 return copy; |
| 194 } | 195 } |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 policy::PolicyErrorMap errors; | 687 policy::PolicyErrorMap errors; |
| 687 handler_list->ApplyPolicySettings(map, NULL, &errors); | 688 handler_list->ApplyPolicySettings(map, NULL, &errors); |
| 688 | 689 |
| 689 // Convert dictionary values to strings for display. | 690 // Convert dictionary values to strings for display. |
| 690 handler_list->PrepareForDisplaying(&map); | 691 handler_list->PrepareForDisplaying(&map); |
| 691 | 692 |
| 692 GetPolicyValues(map, &errors, values); | 693 GetPolicyValues(map, &errors, values); |
| 693 } | 694 } |
| 694 | 695 |
| 695 void PolicyUIHandler::SendStatus() const { | 696 void PolicyUIHandler::SendStatus() const { |
| 696 scoped_ptr<base::DictionaryValue> device_status(new base::DictionaryValue); | 697 std::unique_ptr<base::DictionaryValue> device_status( |
| 698 new base::DictionaryValue); |
| 697 device_status_provider_->GetStatus(device_status.get()); | 699 device_status_provider_->GetStatus(device_status.get()); |
| 698 if (!device_domain_.empty()) | 700 if (!device_domain_.empty()) |
| 699 device_status->SetString("domain", device_domain_); | 701 device_status->SetString("domain", device_domain_); |
| 700 scoped_ptr<base::DictionaryValue> user_status(new base::DictionaryValue); | 702 std::unique_ptr<base::DictionaryValue> user_status(new base::DictionaryValue); |
| 701 user_status_provider_->GetStatus(user_status.get()); | 703 user_status_provider_->GetStatus(user_status.get()); |
| 702 std::string username; | 704 std::string username; |
| 703 user_status->GetString("username", &username); | 705 user_status->GetString("username", &username); |
| 704 if (!username.empty()) | 706 if (!username.empty()) |
| 705 user_status->SetString("domain", gaia::ExtractDomainName(username)); | 707 user_status->SetString("domain", gaia::ExtractDomainName(username)); |
| 706 | 708 |
| 707 base::DictionaryValue status; | 709 base::DictionaryValue status; |
| 708 if (!device_status->empty()) | 710 if (!device_status->empty()) |
| 709 status.Set("device", device_status.release()); | 711 status.Set("device", device_status.release()); |
| 710 if (!user_status->empty()) | 712 if (!user_status->empty()) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 739 } | 741 } |
| 740 | 742 |
| 741 void PolicyUIHandler::OnRefreshPoliciesDone() const { | 743 void PolicyUIHandler::OnRefreshPoliciesDone() const { |
| 742 web_ui()->CallJavascriptFunction("policy.Page.reloadPoliciesDone"); | 744 web_ui()->CallJavascriptFunction("policy.Page.reloadPoliciesDone"); |
| 743 } | 745 } |
| 744 | 746 |
| 745 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { | 747 policy::PolicyService* PolicyUIHandler::GetPolicyService() const { |
| 746 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( | 748 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext( |
| 747 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); | 749 web_ui()->GetWebContents()->GetBrowserContext())->policy_service(); |
| 748 } | 750 } |
| OLD | NEW |