OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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/network_prediction_policy_handler.h" | |
6 | |
7 #include "base/prefs/pref_value_map.h" | |
8 #include "base/values.h" | |
9 #include "chrome/browser/net/prediction_options.h" | |
10 #include "chrome/common/pref_names.h" | |
11 #include "components/policy/core/browser/policy_error_map.h" | |
12 #include "components/policy/core/common/policy_map.h" | |
13 #include "grit/components_strings.h" | |
14 #include "policy/policy_constants.h" | |
15 | |
16 namespace policy { | |
17 | |
18 NetworkPredictionPolicyHandler::NetworkPredictionPolicyHandler() { | |
19 } | |
20 | |
21 NetworkPredictionPolicyHandler::~NetworkPredictionPolicyHandler() { | |
22 } | |
23 | |
24 bool NetworkPredictionPolicyHandler::CheckPolicySettings( | |
25 const PolicyMap& policies, | |
26 PolicyErrorMap* errors) { | |
27 // Deprecated boolean preference. | |
28 const base::Value* network_prediction_enabled = | |
29 policies.GetValue(key::kDnsPrefetchingEnabled); | |
30 // New enumerated preference. | |
31 const base::Value* network_prediction_options = | |
32 policies.GetValue(key::kNetworkPredictionOptions); | |
33 | |
34 if (network_prediction_enabled && | |
35 !network_prediction_enabled->IsType(base::Value::TYPE_BOOLEAN)) { | |
36 errors->AddError(key::kDnsPrefetchingEnabled, | |
37 IDS_POLICY_TYPE_ERROR, | |
38 ValueTypeToString(base::Value::TYPE_BOOLEAN)); | |
39 } | |
40 | |
41 if (network_prediction_options && | |
42 !network_prediction_options->IsType(base::Value::TYPE_INTEGER)) { | |
43 errors->AddError(key::kNetworkPredictionOptions, | |
44 IDS_POLICY_TYPE_ERROR, | |
45 ValueTypeToString(base::Value::TYPE_INTEGER)); | |
46 } | |
47 | |
48 if (network_prediction_enabled && network_prediction_options) { | |
49 errors->AddError(key::kDnsPrefetchingEnabled, | |
50 IDS_POLICY_OVERRIDDEN, | |
51 key::kNetworkPredictionOptions); | |
52 } | |
53 | |
54 return true; | |
55 } | |
56 | |
57 void NetworkPredictionPolicyHandler::ApplyPolicySettings( | |
58 const PolicyMap& policies, | |
59 PrefValueMap* prefs) { | |
60 // If new preference is managed by policy, apply it to both preferences. | |
61 const base::Value* network_prediction_options = | |
62 policies.GetValue(key::kNetworkPredictionOptions); | |
63 int intSetting; | |
Joao da Silva
2014/07/30 13:33:32
Other variables in this file use underscores, so r
Bence
2014/07/31 20:41:12
Done.
| |
64 if (network_prediction_options && | |
65 network_prediction_options->GetAsInteger(&intSetting)) { | |
66 prefs->SetInteger(prefs::kNetworkPredictionOptions, intSetting); | |
67 // Be conservative here and only set Enabled if policy says ALWAYS. | |
68 prefs->SetBoolean( | |
69 prefs::kNetworkPredictionEnabled, | |
70 intSetting == chrome_browser_net::NETWORK_PREDICTION_ALWAYS); | |
71 return; | |
72 } | |
73 | |
74 // If deprecated preference is managed by policy, apply it to both | |
75 // preferences. | |
76 const base::Value* network_prediction_enabled = | |
77 policies.GetValue(key::kDnsPrefetchingEnabled); | |
78 bool boolSetting; | |
Joao da Silva
2014/07/30 13:33:32
bool_setting
Bence
2014/07/31 20:41:12
Done.
| |
79 if (network_prediction_enabled && | |
80 network_prediction_enabled->GetAsBoolean(&boolSetting)) { | |
81 prefs->SetBoolean(prefs::kNetworkPredictionEnabled, boolSetting); | |
82 // Be conservative here and set Options to WIFI_ONLY. | |
Joao da Silva
2014/07/30 13:33:32
Thanks for explaining the rationale for this. Can
Bence
2014/07/31 20:41:12
Done.
| |
83 prefs->SetInteger(prefs::kNetworkPredictionOptions, | |
84 boolSetting | |
85 ? chrome_browser_net::NETWORK_PREDICTION_WIFI_ONLY | |
86 : chrome_browser_net::NETWORK_PREDICTION_NEVER); | |
87 } | |
88 } | |
89 | |
90 } // namespace policy | |
OLD | NEW |