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

Side by Side Diff: chrome/browser/chromeos/policy/device_local_account_policy_provider.cc

Issue 1940153002: Use std::unique_ptr to express ownership of base::Value in PolicyMap::Entry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another-fix Created 4 years, 7 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
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 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" 5 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "chrome/browser/chromeos/policy/device_local_account.h" 12 #include "chrome/browser/chromeos/policy/device_local_account.h"
12 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana ger.h" 13 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana ger.h"
13 #include "chromeos/dbus/power_policy_controller.h" 14 #include "chromeos/dbus/power_policy_controller.h"
14 #include "components/policy/core/common/cloud/cloud_policy_core.h" 15 #include "components/policy/core/common/cloud/cloud_policy_core.h"
15 #include "components/policy/core/common/cloud/cloud_policy_service.h" 16 #include "components/policy/core/common/cloud/cloud_policy_service.h"
16 #include "components/policy/core/common/cloud/component_cloud_policy_service.h" 17 #include "components/policy/core/common/cloud/component_cloud_policy_service.h"
17 #include "components/policy/core/common/policy_bundle.h" 18 #include "components/policy/core/common/policy_bundle.h"
18 #include "components/policy/core/common/policy_map.h" 19 #include "components/policy/core/common/policy_map.h"
19 #include "components/policy/core/common/policy_namespace.h" 20 #include "components/policy/core/common/policy_namespace.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 53 }
53 54
54 std::unique_ptr<PolicyMap> chrome_policy_overrides; 55 std::unique_ptr<PolicyMap> chrome_policy_overrides;
55 if (type == DeviceLocalAccount::TYPE_PUBLIC_SESSION) { 56 if (type == DeviceLocalAccount::TYPE_PUBLIC_SESSION) {
56 chrome_policy_overrides.reset(new PolicyMap()); 57 chrome_policy_overrides.reset(new PolicyMap());
57 58
58 // Exit the session when the lid is closed. The default behavior is to 59 // Exit the session when the lid is closed. The default behavior is to
59 // suspend while leaving the session running, which is not desirable for 60 // suspend while leaving the session running, which is not desirable for
60 // public sessions. 61 // public sessions.
61 chrome_policy_overrides->Set( 62 chrome_policy_overrides->Set(
62 key::kLidCloseAction, 63 key::kLidCloseAction, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
63 POLICY_LEVEL_MANDATORY,
64 POLICY_SCOPE_MACHINE,
65 POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE, 64 POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE,
66 new base::FundamentalValue( 65 base::WrapUnique(new base::FundamentalValue(
67 chromeos::PowerPolicyController::ACTION_STOP_SESSION), 66 chromeos::PowerPolicyController::ACTION_STOP_SESSION)),
68 NULL); 67 nullptr);
69 // Force the |ShelfAutoHideBehavior| policy to |Never|, ensuring that the 68 // Force the |ShelfAutoHideBehavior| policy to |Never|, ensuring that the
70 // ash shelf does not auto-hide. 69 // ash shelf does not auto-hide.
71 chrome_policy_overrides->Set( 70 chrome_policy_overrides->Set(
72 key::kShelfAutoHideBehavior, 71 key::kShelfAutoHideBehavior, POLICY_LEVEL_MANDATORY,
73 POLICY_LEVEL_MANDATORY, 72 POLICY_SCOPE_MACHINE, POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE,
74 POLICY_SCOPE_MACHINE, 73 base::WrapUnique(new base::StringValue("Never")), nullptr);
75 POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE,
76 new base::StringValue("Never"),
77 NULL);
78 // Force the |ShowLogoutButtonInTray| policy to |true|, ensuring that a big, 74 // Force the |ShowLogoutButtonInTray| policy to |true|, ensuring that a big,
79 // red logout button is shown in the ash system tray. 75 // red logout button is shown in the ash system tray.
80 chrome_policy_overrides->Set( 76 chrome_policy_overrides->Set(
81 key::kShowLogoutButtonInTray, 77 key::kShowLogoutButtonInTray, POLICY_LEVEL_MANDATORY,
82 POLICY_LEVEL_MANDATORY, 78 POLICY_SCOPE_MACHINE, POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE,
83 POLICY_SCOPE_MACHINE, 79 base::WrapUnique(new base::FundamentalValue(true)), nullptr);
84 POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE,
85 new base::FundamentalValue(true),
86 NULL);
87 // Force the |FullscreenAllowed| policy to |false|, ensuring that the ash 80 // Force the |FullscreenAllowed| policy to |false|, ensuring that the ash
88 // shelf cannot be hidden by entering fullscreen mode. 81 // shelf cannot be hidden by entering fullscreen mode.
89 chrome_policy_overrides->Set( 82 chrome_policy_overrides->Set(
90 key::kFullscreenAllowed, 83 key::kFullscreenAllowed, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
91 POLICY_LEVEL_MANDATORY,
92 POLICY_SCOPE_MACHINE,
93 POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE, 84 POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE,
94 new base::FundamentalValue(false), 85 base::WrapUnique(new base::FundamentalValue(false)), nullptr);
95 NULL);
96 } 86 }
97 87
98 std::unique_ptr<DeviceLocalAccountPolicyProvider> provider( 88 std::unique_ptr<DeviceLocalAccountPolicyProvider> provider(
99 new DeviceLocalAccountPolicyProvider(user_id, 89 new DeviceLocalAccountPolicyProvider(user_id,
100 device_local_account_policy_service, 90 device_local_account_policy_service,
101 std::move(chrome_policy_overrides))); 91 std::move(chrome_policy_overrides)));
102 return provider; 92 return provider;
103 } 93 }
104 94
105 bool DeviceLocalAccountPolicyProvider::IsInitializationComplete( 95 bool DeviceLocalAccountPolicyProvider::IsInitializationComplete(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // Keep existing policy, but do send an update. 156 // Keep existing policy, but do send an update.
167 waiting_for_policy_refresh_ = false; 157 waiting_for_policy_refresh_ = false;
168 weak_factory_.InvalidateWeakPtrs(); 158 weak_factory_.InvalidateWeakPtrs();
169 bundle->CopyFrom(policies()); 159 bundle->CopyFrom(policies());
170 } 160 }
171 161
172 // Apply overrides. 162 // Apply overrides.
173 if (chrome_policy_overrides_) { 163 if (chrome_policy_overrides_) {
174 PolicyMap& chrome_policy = 164 PolicyMap& chrome_policy =
175 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); 165 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
176 for (PolicyMap::const_iterator it(chrome_policy_overrides_->begin()); 166 for (const auto& policy_override : *chrome_policy_overrides_) {
177 it != chrome_policy_overrides_->end(); 167 const PolicyMap::Entry& entry = policy_override.second;
178 ++it) { 168 chrome_policy.Set(policy_override.first, entry.level, entry.scope,
179 const PolicyMap::Entry& entry = it->second; 169 entry.source, entry.value->CreateDeepCopy(), nullptr);
180 chrome_policy.Set(it->first,
181 entry.level,
182 entry.scope,
183 entry.source,
184 entry.value->DeepCopy(),
185 nullptr);
186 } 170 }
187 } 171 }
188 172
189 UpdatePolicy(std::move(bundle)); 173 UpdatePolicy(std::move(bundle));
190 } 174 }
191 175
192 } // namespace policy 176 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698