Index: chrome/browser/policy/policy_status_info.cc |
diff --git a/chrome/browser/policy/policy_status_info.cc b/chrome/browser/policy/policy_status_info.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bf722418afff5493ec69ba53ec82e6a492bcb36b |
--- /dev/null |
+++ b/chrome/browser/policy/policy_status_info.cc |
@@ -0,0 +1,101 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/policy/policy_status_info.h" |
+ |
+#include <algorithm> |
+ |
+#include "base/utf_string_conversions.h" |
+ |
+namespace policy { |
+ |
+// PolicyStatusInfo |
+PolicyStatusInfo::PolicyStatusInfo() { |
+} |
+ |
+PolicyStatusInfo::PolicyStatusInfo(const PolicyStatusInfo& rhs) |
+ : name(rhs.name), |
+ source_type(rhs.source_type), |
+ level(rhs.level), |
+ status(rhs.status), |
+ error_message(rhs.error_message) { |
+ if (rhs.value.get()) |
+ value.reset(rhs.value->DeepCopy()); |
+ else |
+ value.reset(NULL); |
+} |
+ |
+PolicyStatusInfo::PolicyStatusInfo( |
+ string16 name, |
+ PolicySourceType source_type, |
+ PolicyLevel level, |
+ Value* value, |
+ PolicyStatus status, |
+ string16 error_message) |
+ : name(name), |
+ source_type(source_type), |
+ level(level), |
+ value(value), |
+ status(status), |
+ error_message(error_message) { |
+} |
+ |
+PolicyStatusInfo::~PolicyStatusInfo() { |
+} |
+ |
+PolicyStatusInfo& PolicyStatusInfo::operator=(const PolicyStatusInfo& rhs) { |
+ name = rhs.name; |
+ source_type = rhs.source_type; |
+ level = rhs.level; |
+ status = rhs.status; |
+ error_message = rhs.error_message; |
+ if (rhs.value.get()) |
+ value.reset(rhs.value->DeepCopy()); |
Mattias Nissler (ping if slow)
2011/08/24 11:57:09
AFAICS, you have operator= and the copy constructo
simo
2011/08/25 10:06:36
Yeah, that works.
On 2011/08/24 11:57:09, Mattias
|
+ else |
+ value.reset(NULL); |
+ return *this; |
+} |
+ |
+DictionaryValue* PolicyStatusInfo::GetDictionaryValue() const { |
+ string16 level_string = GetPolicyLevelString(level); |
+ string16 source_type_string = GetSourceTypeString(source_type); |
+ string16 status_message = status == ENFORCED ? ASCIIToUTF16("ok") |
+ : error_message; |
+ DictionaryValue* result = new DictionaryValue(); |
+ result->SetString("name", name); |
Mattias Nissler (ping if slow)
2011/08/24 11:57:09
Declare static class members for these string cons
simo
2011/08/25 10:06:36
Done.
|
+ result->SetString("level", level_string); |
+ result->SetString("sourceType", source_type_string); |
+ result->Set("value", value->DeepCopy()); |
+ result->SetBoolean("set", level != LEVEL_UNDEFINED); |
+ result->SetString("status", status_message); |
+ |
+ return result; |
+} |
+ |
+bool PolicyStatusInfo::Equals(const PolicyStatusInfo* other_info) const { |
+ return name == other_info->name && |
+ source_type == other_info->source_type && |
+ level == other_info->level && |
+ value->Equals(other_info->value.get()) && |
+ status == other_info->status && |
+ error_message == other_info->error_message; |
+} |
+ |
+// static |
+string16 PolicyStatusInfo::GetSourceTypeString(PolicySourceType source_type) { |
+ static string16 strings[] = { ASCIIToUTF16("user"), |
+ ASCIIToUTF16("device"), |
+ ASCIIToUTF16("undefined") }; |
Mattias Nissler (ping if slow)
2011/08/24 11:57:09
Can you put a DCHECK that makes sure the numeric v
simo
2011/08/25 10:06:36
Done.
|
+ return strings[source_type]; |
+} |
+ |
+// static |
+string16 PolicyStatusInfo::GetPolicyLevelString(PolicyLevel level) { |
+ static string16 strings[] = { ASCIIToUTF16("mandatory"), |
+ ASCIIToUTF16("recommended"), |
+ ASCIIToUTF16("undefined") }; |
Mattias Nissler (ping if slow)
2011/08/24 11:57:09
same here.
simo
2011/08/25 10:06:36
Done.
|
+ return strings[level]; |
+} |
+ |
+} // namespace policy |