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

Side by Side Diff: chrome/browser/policy/network_prediction_policy_handler.cc

Issue 431493003: Implement policy for kNetworkPredictionOptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
OLDNEW
(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/content_settings.h"
Joao da Silva 2014/07/30 07:57:32 Not used
Bence 2014/07/30 13:19:31 Done.
11 #include "chrome/common/pref_names.h"
12 #include "components/policy/core/browser/policy_error_map.h"
13 #include "components/policy/core/common/policy_map.h"
14 #include "grit/components_strings.h"
15 #include "policy/policy_constants.h"
16
17 namespace policy {
18
19 NetworkPredictionPolicyHandler::NetworkPredictionPolicyHandler() {
20 }
21
22 NetworkPredictionPolicyHandler::~NetworkPredictionPolicyHandler() {
23 }
24
25 bool NetworkPredictionPolicyHandler::CheckPolicySettings(
26 const PolicyMap& policies,
27 PolicyErrorMap* errors) {
28 // Deprecated boolean preference.
29 const base::Value* network_prediction_enabled =
30 policies.GetValue(key::kDnsPrefetchingEnabled);
31 // New enumerated preference.
32 const base::Value* network_prediction_options =
33 policies.GetValue(key::kNetworkPredictionOptions);
34
35 if (network_prediction_enabled &&
36 !network_prediction_enabled->IsType(base::Value::TYPE_BOOLEAN)) {
37 errors->AddError(key::kDnsPrefetchingEnabled,
38 IDS_POLICY_TYPE_ERROR,
39 ValueTypeToString(base::Value::TYPE_BOOLEAN));
40 }
41
42 if (network_prediction_options &&
43 !network_prediction_options->IsType(base::Value::TYPE_INTEGER)) {
44 errors->AddError(key::kNetworkPredictionOptions,
45 IDS_POLICY_TYPE_ERROR,
46 ValueTypeToString(base::Value::TYPE_INTEGER));
47 }
48
49 if (network_prediction_enabled && network_prediction_options) {
50 errors->AddError(key::kDnsPrefetchingEnabled,
51 IDS_POLICY_OVERRIDDEN,
52 key::kNetworkPredictionOptions);
53 }
54
55 return true;
56 }
57
58 void NetworkPredictionPolicyHandler::ApplyPolicySettings(
59 const PolicyMap& policies,
60 PrefValueMap* prefs) {
61 // If new preference is managed by policy, apply it to both preferences.
62 const base::Value* network_prediction_options =
63 policies.GetValue(key::kNetworkPredictionOptions);
64 if (network_prediction_options) {
65 int setting;
66 network_prediction_options->GetAsInteger(&setting);
Joao da Silva 2014/07/30 07:57:32 This may fail, if the policy value isn't an intege
Bence 2014/07/30 13:19:31 Done.
67 prefs->SetInteger(prefs::kNetworkPredictionOptions, setting);
68 // Be conservative here and only set Enabled if policy says ALWAYS.
69 prefs->SetBoolean(prefs::kNetworkPredictionEnabled,
70 setting == 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 if (network_prediction_enabled) {
79 bool setting;
80 network_prediction_enabled->GetAsBoolean(&setting);
Joao da Silva 2014/07/30 07:57:32 Same here
Bence 2014/07/30 13:19:31 Done.
81 prefs->SetBoolean(prefs::kNetworkPredictionEnabled, setting);
82 // Be conservative here and set Options to WIFI_ONLY.
Joao da Silva 2014/07/30 07:57:32 The legacy semantic was equivalent to ALWAYS and I
Bence 2014/07/30 13:19:31 Good question, sorry it is not clear from comments
83 prefs->SetInteger(prefs::kNetworkPredictionOptions,
84 setting ? chrome_browser_net::NETWORK_PREDICTION_WIFI_ONLY
85 : chrome_browser_net::NETWORK_PREDICTION_NEVER);
86 }
87 }
88
89 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698