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

Side by Side Diff: remoting/host/policy_hack/policy_watcher.cc

Issue 10816036: [Chromoting] Add a host domain policy to the PolicyWatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix to match r148833. Created 8 years, 4 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 | Annotate | Revision Log
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 // Most of this code is copied from: 5 // Most of this code is copied from:
6 // src/chrome/browser/policy/asynchronous_policy_loader.{h,cc} 6 // src/chrome/browser/policy/asynchronous_policy_loader.{h,cc}
7 7
8 #include "remoting/host/policy_hack/policy_watcher.h" 8 #include "remoting/host/policy_hack/policy_watcher.h"
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 23 matching lines...) Expand all
34 } 34 }
35 const base::Value* value; 35 const base::Value* value;
36 if (dict->Get(key, &value) && value->IsType(base::Value::TYPE_BOOLEAN)) { 36 if (dict->Get(key, &value) && value->IsType(base::Value::TYPE_BOOLEAN)) {
37 bool bool_value; 37 bool bool_value;
38 CHECK(value->GetAsBoolean(&bool_value)); 38 CHECK(value->GetAsBoolean(&bool_value));
39 return bool_value; 39 return bool_value;
40 } 40 }
41 return default_if_value_not_boolean; 41 return default_if_value_not_boolean;
42 } 42 }
43 43
44 // Gets a string from a dictionary, or returns a default value if the string
45 // couldn't be read.
46 std::string GetStringOrDefault(const base::DictionaryValue* dict,
47 const char* key,
48 const std::string& default_if_value_missing,
49 const std::string& default_if_value_not_string) {
50 if (!dict->HasKey(key)) {
51 return default_if_value_missing;
52 }
53 const base::Value* value;
54 if (dict->Get(key, &value) && value->IsType(base::Value::TYPE_STRING)) {
55 std::string string_value;
56 CHECK(value->GetAsString(&string_value));
57 return string_value;
58 }
59 return default_if_value_not_string;
60 }
61
44 // Copies a boolean from one dictionary to another, using a default value 62 // Copies a boolean from one dictionary to another, using a default value
45 // if the boolean couldn't be read from the first dictionary. 63 // if the boolean couldn't be read from the first dictionary.
46 void CopyBooleanOrDefault(base::DictionaryValue* to, 64 void CopyBooleanOrDefault(base::DictionaryValue* to,
47 const base::DictionaryValue* from, const char* key, 65 const base::DictionaryValue* from, const char* key,
48 bool default_if_value_missing, 66 bool default_if_value_missing,
49 bool default_if_value_not_boolean) { 67 bool default_if_value_not_boolean) {
50 to->Set(key, base::Value::CreateBooleanValue( 68 to->Set(key, base::Value::CreateBooleanValue(
51 GetBooleanOrDefault(from, key, default_if_value_missing, 69 GetBooleanOrDefault(from, key, default_if_value_missing,
52 default_if_value_not_boolean))); 70 default_if_value_not_boolean)));
53 } 71 }
54 72
73 // Copies a string from one dictionary to another, using a default value
74 // if the string couldn't be read from the first dictionary.
75 void CopyStringOrDefault(base::DictionaryValue* to,
76 const base::DictionaryValue* from, const char* key,
77 const std::string& default_if_value_missing,
78 const std::string& default_if_value_not_string) {
79 to->Set(key, base::Value::CreateStringValue(
80 GetStringOrDefault(from, key, default_if_value_missing,
81 default_if_value_not_string)));
82 }
83
55 // Copies all policy values from one dictionary to another, using default values 84 // Copies all policy values from one dictionary to another, using default values
56 // when necessary. 85 // when necessary.
57 scoped_ptr<base::DictionaryValue> AddDefaultValuesWhenNecessary( 86 scoped_ptr<base::DictionaryValue> AddDefaultValuesWhenNecessary(
58 const base::DictionaryValue* from) { 87 const base::DictionaryValue* from) {
59 scoped_ptr<base::DictionaryValue> to(new base::DictionaryValue()); 88 scoped_ptr<base::DictionaryValue> to(new base::DictionaryValue());
60 CopyBooleanOrDefault(to.get(), from, 89 CopyBooleanOrDefault(to.get(), from,
61 PolicyWatcher::kNatPolicyName, true, false); 90 PolicyWatcher::kNatPolicyName, true, false);
91 CopyStringOrDefault(to.get(), from,
92 PolicyWatcher::kHostDomainPolicyName, "", "");
62 return to.Pass(); 93 return to.Pass();
63 } 94 }
64 95
65 } // namespace 96 } // namespace
66 97
67 const char PolicyWatcher::kNatPolicyName[] = 98 const char PolicyWatcher::kNatPolicyName[] =
68 "RemoteAccessHostFirewallTraversal"; 99 "RemoteAccessHostFirewallTraversal";
69 100
101 const char PolicyWatcher::kHostDomainPolicyName[] =
102 "RemoteAccessHostDomain";
103
70 const char* const PolicyWatcher::kBooleanPolicyNames[] = 104 const char* const PolicyWatcher::kBooleanPolicyNames[] =
71 { PolicyWatcher::kNatPolicyName }; 105 { PolicyWatcher::kNatPolicyName };
72 106
73 const int PolicyWatcher::kBooleanPolicyNamesNum = 107 const int PolicyWatcher::kBooleanPolicyNamesNum =
74 arraysize(kBooleanPolicyNames); 108 arraysize(kBooleanPolicyNames);
75 109
110 const char* const PolicyWatcher::kStringPolicyNames[] =
111 { PolicyWatcher::kHostDomainPolicyName };
112
113 const int PolicyWatcher::kStringPolicyNamesNum =
114 arraysize(kStringPolicyNames);
115
76 PolicyWatcher::PolicyWatcher( 116 PolicyWatcher::PolicyWatcher(
77 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 117 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
78 : task_runner_(task_runner), 118 : task_runner_(task_runner),
79 old_policies_(new base::DictionaryValue()), 119 old_policies_(new base::DictionaryValue()),
80 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 120 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
81 } 121 }
82 122
83 PolicyWatcher::~PolicyWatcher() { 123 PolicyWatcher::~PolicyWatcher() {
84 } 124 }
85 125
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 old_policies_.swap(new_policies); 194 old_policies_.swap(new_policies);
155 195
156 // Notify our client of the changed policies. 196 // Notify our client of the changed policies.
157 if (!changed_policies->empty()) { 197 if (!changed_policies->empty()) {
158 policy_callback_.Run(changed_policies.Pass()); 198 policy_callback_.Run(changed_policies.Pass());
159 } 199 }
160 } 200 }
161 201
162 } // namespace policy_hack 202 } // namespace policy_hack
163 } // namespace remoting 203 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/policy_hack/policy_watcher.h ('k') | remoting/host/policy_hack/policy_watcher_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698