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/device_policy_cache.h" | |
6 | |
7 #include "base/file_util.h" | |
8 #include "base/logging.h" | |
9 #include "base/task.h" | |
10 #include "base/values.h" | |
11 #include "content/browser/browser_thread.h" | |
12 #include "chrome/browser/policy/configuration_policy_pref_store.h" | |
13 #include "chrome/browser/policy/policy_map.h" | |
14 #include "chrome/browser/policy/proto/cloud_policy.pb.h" | |
15 #include "chrome/browser/policy/proto/device_management_constants.h" | |
16 #include "chrome/browser/policy/proto/device_management_local.pb.h" | |
17 #include "policy/configuration_policy_type.h" | |
18 | |
19 using google::protobuf::RepeatedPtrField; | |
20 | |
21 namespace policy { | |
22 | |
23 // Lives in <generated code output directory>/policy/cloud_policy_generated.cc. | |
24 void DecodeIntegerValue(google::protobuf::int64 value); | |
Mattias Nissler (ping if slow)
2011/03/24 18:55:57
We shouldn't make use of this here, since this cla
Jakob Kummerow
2011/03/28 13:53:53
Done (has become a moot point since we've scratche
| |
25 | |
26 DevicePolicyCache::DevicePolicyCache() | |
27 : signed_settings_helper_(chromeos::SignedSettingsHelper::Get()) { | |
28 } | |
29 | |
30 DevicePolicyCache::DevicePolicyCache( | |
31 chromeos::SignedSettingsHelper* signed_settings_helper) | |
32 : signed_settings_helper_(signed_settings_helper) { | |
33 } | |
34 | |
35 DevicePolicyCache::~DevicePolicyCache() { | |
36 signed_settings_helper_->CancelCallback(this); | |
37 } | |
38 | |
39 void DevicePolicyCache::Load() { | |
40 // TODO(jkummerow): check if we're unmanaged; if so, set is_unmanaged_ = true | |
41 // and return immediately. | |
42 | |
43 signed_settings_helper_->StartRetrievePolicyOp(this); | |
44 } | |
45 | |
46 void DevicePolicyCache::SetPolicy(const em::PolicyFetchResponse& policy) { | |
47 std::string data; | |
48 if (!policy.SerializeToString(&data)) { | |
49 LOG(WARNING) << "Failed to serialize policy data."; | |
50 return; | |
51 } | |
52 signed_settings_helper_->StartStorePolicyOp(data, this); | |
53 } | |
54 | |
55 void DevicePolicyCache::SetUnmanaged() { | |
56 LOG(WARNING) << "Tried to set DevicePolicyCache to 'unmanaged'!"; | |
57 // This is not supported for DevicePolicyCache. | |
58 } | |
59 | |
60 void DevicePolicyCache::OnRetrievePolicyCompleted( | |
61 chromeos::SignedSettings::ReturnCode code, | |
62 const std::string& value) { | |
63 DCHECK(CalledOnValidThread()); | |
64 if (code != chromeos::SignedSettings::SUCCESS) { | |
65 // TODO(jkummerow): error handling? | |
Mattias Nissler (ping if slow)
2011/03/24 18:55:57
Maybe make this comment a bit more elaborate, some
Jakob Kummerow
2011/03/28 13:53:53
Done.
| |
66 return; | |
67 } | |
68 em::PolicyFetchResponse policy; | |
69 if (!policy.ParseFromArray(value.c_str(), value.size())) { | |
70 LOG(WARNING) << "Failed to parse policy blob fetched from SignedSettings!"; | |
71 return; | |
72 } | |
73 SetPolicyInternal(policy); | |
74 } | |
75 | |
76 void DevicePolicyCache::OnStorePolicyCompleted( | |
77 chromeos::SignedSettings::ReturnCode code) { | |
78 if (code != chromeos::SignedSettings::SUCCESS) { | |
79 // TODO(jkummerow): error handling? | |
Mattias Nissler (ping if slow)
2011/03/24 18:55:57
Same here.
Jakob Kummerow
2011/03/28 13:53:53
Done.
| |
80 return; | |
81 } | |
82 Load(); | |
83 } | |
84 | |
85 bool DevicePolicyCache::DecodePolicyData(const em::PolicyData& policy_data, | |
86 PolicyMap* mandatory, | |
87 PolicyMap* recommended) { | |
88 em::ChromeDeviceSettingsProto policy; | |
89 if (!policy.ParseFromString(policy_data.policy_value())) { | |
90 LOG(WARNING) << "Failed to parse ChromeDeviceSettingsProto."; | |
91 return false; | |
92 } | |
93 DecodeDevicePolicy(policy, mandatory, recommended); | |
94 return true; | |
95 } | |
96 | |
97 // static | |
98 void DevicePolicyCache::DecodeDevicePolicy( | |
99 const em::ChromeDeviceSettingsProto& policy, | |
100 PolicyMap* mandatory, | |
101 PolicyMap* recommended) { | |
102 DCHECK(mandatory); | |
103 // |recommended| isn't used yet; it is passed in for consistency with | |
104 // user-level policy, and for future extensibility. | |
105 if (policy.has_policy_refresh_rate()) { | |
106 const em::DevicePolicyRefreshRateProto& refresh_rate = | |
107 policy.policy_refresh_rate(); | |
108 if (refresh_rate.has_policy_refresh_rate()) { | |
109 // TODO(jkummerow): define kPolicyDevicePolicyRefreshRate. | |
Mattias Nissler (ping if slow)
2011/03/24 18:55:57
So why not do it?
Jakob Kummerow
2011/03/28 13:53:53
As discussed, let's remove all of this protobuf-de
| |
110 // mandatory->Set(kPolicyDevicePolicyRefreshRate, | |
111 // DecodeIntegerValue(refresh_rate.policy_refresh_rate())); | |
112 } | |
113 } | |
114 if (policy.has_user_whitelist()) { | |
Mattias Nissler (ping if slow)
2011/03/24 18:55:57
I guess we don't need the user whitelist in prefs
Jakob Kummerow
2011/03/28 13:53:53
As discussed, let's remove all of this protobuf-de
| |
115 const em::UserWhitelistProto user_whitelist = policy.user_whitelist(); | |
116 ListValue* list = new ListValue(); | |
117 RepeatedPtrField<std::string>::const_iterator entry; | |
118 for (entry = user_whitelist.user_whitelist().begin(); | |
119 entry != user_whitelist.user_whitelist().end(); ++entry) { | |
120 list->Append(Value::CreateStringValue(*entry)); | |
121 } | |
122 if (!list->empty()) { | |
123 // TODO(jkummerow): define kPolicyUserWhitelist. | |
124 // mandatory->Set(kPolicyUserWhitelist, list); | |
125 } | |
126 // TODO(jkummerow): remove this when |mandatory->Set()| is enabled. | |
Mattias Nissler (ping if slow)
2011/03/24 18:55:57
If list is empty, you still need to delete!
Jakob Kummerow
2011/03/28 13:53:53
Good point. Solved by using a scoped_ptr.
| |
127 delete list; | |
128 } | |
129 if (policy.has_guest_mode_enabled()) { | |
130 const em::GuestModeEnabledProto guest_mode = policy.guest_mode_enabled(); | |
131 if (guest_mode.has_guest_mode_enabled()) { | |
132 // TODO(jkummerow): define kPolicyGuestModeEnabled. | |
133 // mandatory->Set( | |
134 // kPolicyGuestModeEnabled, | |
135 // Value::CreateBooleanValue(guest_mode.guest_mode_enabled())); | |
136 } | |
137 } | |
138 if (policy.has_device_proxy_settings()) { | |
139 const em::DeviceProxySettingsProto proxy = policy.device_proxy_settings(); | |
140 if (proxy.has_proxy_mode()) { | |
141 Value* value = Value::CreateStringValue(proxy.proxy_mode()); | |
142 mandatory->Set(kPolicyProxyMode, value); | |
143 } | |
144 if (proxy.has_proxy_server()) { | |
145 Value* value = Value::CreateStringValue(proxy.proxy_server()); | |
146 mandatory->Set(kPolicyProxyServer, value); | |
147 } | |
148 if (proxy.has_proxy_pac_url()) { | |
149 Value* value = Value::CreateStringValue(proxy.proxy_pac_url()); | |
150 mandatory->Set(kPolicyProxyPacUrl, value); | |
151 } | |
152 if (proxy.has_proxy_bypass_list()) { | |
153 Value* value = Value::CreateStringValue(proxy.proxy_bypass_list()); | |
154 mandatory->Set(kPolicyProxyBypassList, value); | |
155 } | |
156 } | |
157 } | |
158 | |
159 } // namespace policy | |
OLD | NEW |