Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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/policy/policy_status_info.h" | 5 #include "chrome/browser/policy/policy_status_info.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 | 13 |
| 14 namespace policy { | 14 namespace policy { |
| 15 | 15 |
| 16 const char PolicyStatusInfo::kLevelDictPath[] = "level"; | 16 const char PolicyStatusInfo::kLevelDictPath[] = "level"; |
| 17 const char PolicyStatusInfo::kNameDictPath[] = "name"; | 17 const char PolicyStatusInfo::kNameDictPath[] = "name"; |
| 18 const char PolicyStatusInfo::kScopeDictPath[] = "scope"; | |
| 18 const char PolicyStatusInfo::kSetDictPath[] = "set"; | 19 const char PolicyStatusInfo::kSetDictPath[] = "set"; |
| 19 const char PolicyStatusInfo::kSourceTypeDictPath[] = "sourceType"; | |
| 20 const char PolicyStatusInfo::kStatusDictPath[] = "status"; | 20 const char PolicyStatusInfo::kStatusDictPath[] = "status"; |
| 21 const char PolicyStatusInfo::kValueDictPath[] = "value"; | 21 const char PolicyStatusInfo::kValueDictPath[] = "value"; |
| 22 | 22 |
| 23 // PolicyStatusInfo | 23 // PolicyStatusInfo |
| 24 PolicyStatusInfo::PolicyStatusInfo() | 24 PolicyStatusInfo::PolicyStatusInfo() |
| 25 : source_type(SOURCE_TYPE_UNDEFINED), | 25 : scope(POLICY_SCOPE_USER), |
| 26 level(LEVEL_UNDEFINED), | 26 level(POLICY_LEVEL_MANDATORY), |
| 27 status(STATUS_UNDEFINED) { | 27 status(STATUS_UNDEFINED) { |
| 28 } | 28 } |
| 29 | 29 |
| 30 PolicyStatusInfo::PolicyStatusInfo( | 30 PolicyStatusInfo::PolicyStatusInfo( |
| 31 const string16& name, | 31 const string16& name, |
| 32 PolicySourceType source_type, | 32 PolicyScope scope, |
| 33 PolicyLevel level, | 33 PolicyLevel level, |
| 34 Value* value, | 34 Value* value, |
| 35 PolicyStatus status, | 35 PolicyStatus status, |
| 36 const string16& error_message) | 36 const string16& error_message) |
| 37 : name(name), | 37 : name(name), |
| 38 source_type(source_type), | 38 scope(scope), |
| 39 level(level), | 39 level(level), |
| 40 value(value), | 40 value(value), |
| 41 status(status), | 41 status(status), |
| 42 error_message(error_message) { | 42 error_message(error_message) { |
| 43 } | 43 } |
| 44 | 44 |
| 45 PolicyStatusInfo::~PolicyStatusInfo() { | 45 PolicyStatusInfo::~PolicyStatusInfo() { |
| 46 } | 46 } |
| 47 | 47 |
| 48 DictionaryValue* PolicyStatusInfo::GetDictionaryValue() const { | 48 DictionaryValue* PolicyStatusInfo::GetDictionaryValue() const { |
| 49 string16 level_string = GetPolicyLevelString(level); | 49 string16 level_string = GetPolicyLevelString(level); |
| 50 string16 source_type_string = GetSourceTypeString(source_type); | 50 string16 scope_string = GetPolicyScopeString(scope); |
| 51 string16 status_message = | 51 string16 status_message = |
| 52 status == ENFORCED ? l10n_util::GetStringUTF16(IDS_OK) : error_message; | 52 status == ENFORCED ? l10n_util::GetStringUTF16(IDS_OK) : error_message; |
| 53 DictionaryValue* result = new DictionaryValue(); | 53 DictionaryValue* result = new DictionaryValue(); |
| 54 result->SetString(std::string(kNameDictPath), name); | 54 result->SetString(std::string(kNameDictPath), name); |
| 55 result->SetString(std::string(kLevelDictPath), level_string); | 55 result->SetString(std::string(kLevelDictPath), level_string); |
| 56 result->SetString(std::string(kSourceTypeDictPath), source_type_string); | 56 result->SetString(std::string(kScopeDictPath), scope_string); |
| 57 result->Set(std::string(kValueDictPath), value->DeepCopy()); | 57 result->Set(std::string(kValueDictPath), value->DeepCopy()); |
| 58 result->SetBoolean(std::string(kSetDictPath), level != LEVEL_UNDEFINED); | 58 result->SetBoolean(std::string(kSetDictPath), status != STATUS_UNDEFINED); |
| 59 result->SetString(std::string(kStatusDictPath), status_message); | 59 result->SetString(std::string(kStatusDictPath), status_message); |
| 60 | 60 |
| 61 return result; | 61 return result; |
| 62 } | 62 } |
| 63 | 63 |
| 64 bool PolicyStatusInfo::Equals(const PolicyStatusInfo* other_info) const { | 64 bool PolicyStatusInfo::Equals(const PolicyStatusInfo* other_info) const { |
| 65 return name == other_info->name && | 65 return name == other_info->name && |
| 66 source_type == other_info->source_type && | 66 scope == other_info->scope && |
| 67 level == other_info->level && | 67 level == other_info->level && |
| 68 value->Equals(other_info->value.get()) && | 68 value->Equals(other_info->value.get()) && |
| 69 status == other_info->status && | 69 status == other_info->status && |
| 70 error_message == other_info->error_message; | 70 error_message == other_info->error_message; |
| 71 } | 71 } |
| 72 | 72 |
| 73 // static | 73 // static |
| 74 string16 PolicyStatusInfo::GetSourceTypeString( | 74 string16 PolicyStatusInfo::GetPolicyScopeString(PolicyScope scope) { |
| 75 PolicySourceType source_type) { | 75 static const char* strings[] = { "User", "Device" }; |
|
Mattias Nissler (ping if slow)
2012/01/18 15:07:07
Shouldn't this now be "Machine"?
Joao da Silva
2012/01/18 16:49:29
Yes, done. "Mandatory" and "Recommended" below hav
| |
| 76 static const char* strings[] = { "user", "device", "undefined" }; | 76 DCHECK(static_cast<size_t>(scope) < arraysize(strings)); |
| 77 DCHECK(static_cast<size_t>(source_type) < arraysize(strings)); | 77 return ASCIIToUTF16(strings[scope]); |
| 78 return ASCIIToUTF16(strings[source_type]); | |
| 79 } | 78 } |
| 80 | 79 |
| 81 // static | 80 // static |
| 82 string16 PolicyStatusInfo::GetPolicyLevelString(PolicyLevel level) { | 81 string16 PolicyStatusInfo::GetPolicyLevelString(PolicyLevel level) { |
| 83 static const char* strings[] = { "mandatory", "recommended", "undefined" }; | 82 static const char* strings[] = { "Mandatory", "Recommended" }; |
| 84 DCHECK(static_cast<size_t>(level) < arraysize(strings)); | 83 DCHECK(static_cast<size_t>(level) < arraysize(strings)); |
| 85 return ASCIIToUTF16(strings[level]); | 84 return ASCIIToUTF16(strings[level]); |
| 86 } | 85 } |
| 87 | 86 |
| 88 } // namespace policy | 87 } // namespace policy |
| OLD | NEW |