OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/policy/policy_status_info.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/utf_string_conversions.h" | |
11 | |
12 namespace policy { | |
13 | |
14 const std::string PolicyStatusInfo::kLevelDictPath = "level"; | |
15 const std::string PolicyStatusInfo::kNameDictPath = "name"; | |
16 const std::string PolicyStatusInfo::kSetDictPath = "set"; | |
17 const std::string PolicyStatusInfo::kSourceTypeDictPath = "sourceType"; | |
18 const std::string PolicyStatusInfo::kStatusDictPath = "status"; | |
19 const std::string PolicyStatusInfo::kValueDictPath = "value"; | |
20 | |
21 // PolicyStatusInfo | |
22 PolicyStatusInfo::PolicyStatusInfo() { | |
23 } | |
24 | |
25 PolicyStatusInfo::PolicyStatusInfo( | |
26 string16 name, | |
27 PolicySourceType source_type, | |
28 PolicyLevel level, | |
29 Value* value, | |
30 PolicyStatus status, | |
31 string16 error_message) | |
32 : name(name), | |
33 source_type(source_type), | |
34 level(level), | |
35 value(value), | |
36 status(status), | |
37 error_message(error_message) { | |
38 } | |
39 | |
40 PolicyStatusInfo::~PolicyStatusInfo() { | |
41 } | |
42 | |
43 DictionaryValue* PolicyStatusInfo::GetDictionaryValue() const { | |
44 string16 level_string = GetPolicyLevelString(level); | |
45 string16 source_type_string = GetSourceTypeString(source_type); | |
46 string16 status_message = status == ENFORCED ? ASCIIToUTF16("ok") | |
47 : error_message; | |
48 DictionaryValue* result = new DictionaryValue(); | |
49 result->SetString(kNameDictPath, name); | |
50 result->SetString(kLevelDictPath, level_string); | |
51 result->SetString(kSourceTypeDictPath, source_type_string); | |
52 result->Set(kValueDictPath, value->DeepCopy()); | |
53 result->SetBoolean(kSetDictPath, level != LEVEL_UNDEFINED); | |
54 result->SetString(kStatusDictPath, status_message); | |
55 | |
56 return result; | |
57 } | |
58 | |
59 bool PolicyStatusInfo::Equals(const PolicyStatusInfo* other_info) const { | |
60 return name == other_info->name && | |
61 source_type == other_info->source_type && | |
62 level == other_info->level && | |
63 value->Equals(other_info->value.get()) && | |
64 status == other_info->status && | |
65 error_message == other_info->error_message; | |
66 } | |
67 | |
68 // static | |
69 string16 PolicyStatusInfo::GetSourceTypeString(PolicySourceType source_type) { | |
70 static string16 strings[] = { ASCIIToUTF16("user"), | |
71 ASCIIToUTF16("device"), | |
72 ASCIIToUTF16("undefined") }; | |
joth
2011/09/05 11:09:38
to avoid having static class instances (against st
| |
73 DCHECK(static_cast<size_t>(source_type) < arraysize(strings)); | |
74 return strings[source_type]; | |
75 } | |
76 | |
77 // static | |
78 string16 PolicyStatusInfo::GetPolicyLevelString(PolicyLevel level) { | |
79 static string16 strings[] = { ASCIIToUTF16("mandatory"), | |
80 ASCIIToUTF16("recommended"), | |
81 ASCIIToUTF16("undefined") }; | |
82 DCHECK(static_cast<size_t>(level) < arraysize(strings)); | |
83 return strings[level]; | |
84 } | |
85 | |
86 } // namespace policy | |
OLD | NEW |