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

Side by Side Diff: chrome/browser/chromeos/arc/arc_policy_bridge.cc

Issue 1869783006: Revert of Pass policy VideoCaptureAllowed to ARC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/arc/arc_policy_bridge.h" 5 #include "chrome/browser/chromeos/arc/arc_policy_bridge.h"
6 6
7 #include <string>
8
9 #include "base/json/json_reader.h"
10 #include "base/json/json_string_value_serializer.h" 7 #include "base/json/json_string_value_serializer.h"
11 #include "base/logging.h" 8 #include "base/logging.h"
12 #include "base/values.h" 9 #include "base/values.h"
13 #include "chrome/browser/chromeos/profiles/profile_helper.h" 10 #include "chrome/browser/chromeos/profiles/profile_helper.h"
14 #include "chrome/browser/policy/profile_policy_connector.h" 11 #include "chrome/browser/policy/profile_policy_connector.h"
15 #include "chrome/browser/policy/profile_policy_connector_factory.h" 12 #include "chrome/browser/policy/profile_policy_connector_factory.h"
16 #include "components/policy/core/common/policy_map.h" 13 #include "components/policy/core/common/policy_map.h"
17 #include "components/policy/core/common/policy_namespace.h" 14 #include "components/policy/core/common/policy_namespace.h"
18 #include "components/user_manager/user.h" 15 #include "components/user_manager/user.h"
19 #include "mojo/public/cpp/bindings/string.h" 16 #include "mojo/public/cpp/bindings/string.h"
20 #include "policy/policy_constants.h" 17 #include "policy/policy_constants.h"
21 18
22 namespace arc { 19 namespace arc {
23 20
24 namespace {
25
26 // invert_bool_value: If the Chrome policy and the ARC policy with boolean value
27 // have opposite semantics, set this to true so the bool is inverted before
28 // being added. Otherwise, set it to false.
29 void AddPolicy(const std::string arc_policy_name,
30 const std::string policy_name,
31 const policy::PolicyMap& policy_map,
32 bool invert_bool_value,
33 base::DictionaryValue& filtered_policies) {
34 const base::Value* const policy_value = policy_map.GetValue(policy_name);
35 if (policy_value) {
36 if (invert_bool_value && policy_value->IsType(base::Value::TYPE_BOOLEAN)) {
37 bool bool_value;
38 policy_value->GetAsBoolean(&bool_value);
39 filtered_policies.SetBoolean(arc_policy_name, !bool_value);
40 } else {
41 filtered_policies.Set(arc_policy_name,
42 policy_value->CreateDeepCopy().release());
43 }
44 }
45 }
46
47 std::string GetFilteredJSONPolicies(const policy::PolicyMap& policy_map) {
48 base::DictionaryValue filtered_policies;
49 // Parse ArcApplicationPolicy as JSON string before adding other policies to
50 // the dictionary.
51 const base::Value* const app_policy_value =
52 policy_map.GetValue(policy::key::kArcApplicationPolicy);
53 if (app_policy_value) {
54 std::string app_policy_string;
55 app_policy_value->GetAsString(&app_policy_string);
56 std::unique_ptr<base::DictionaryValue> app_policy_dict =
57 base::DictionaryValue::From(base::JSONReader::Read(app_policy_string));
58 if (app_policy_dict) {
59 filtered_policies.Swap(app_policy_dict.get());
60 } else {
61 LOG(ERROR) << "Value of ArcApplicationPolicy has invalid format: "
62 << app_policy_string;
63 }
64 }
65
66 // Keep them sorted by the ARC policy names.
67 AddPolicy("cameraDisabled", policy::key::kVideoCaptureAllowed, policy_map,
68 true, filtered_policies);
69
70 std::string policy_json;
71 JSONStringValueSerializer serializer(&policy_json);
72 serializer.Serialize(filtered_policies);
73 return policy_json;
74 }
75
76 } // namespace
77
78 ArcPolicyBridge::ArcPolicyBridge(ArcBridgeService* bridge_service) 21 ArcPolicyBridge::ArcPolicyBridge(ArcBridgeService* bridge_service)
79 : ArcService(bridge_service), binding_(this) { 22 : ArcService(bridge_service), binding_(this) {
80 VLOG(1) << "ArcPolicyBridge::ArcPolicyBridge"; 23 VLOG(1) << "ArcPolicyBridge::ArcPolicyBridge";
81 arc_bridge_service()->AddObserver(this); 24 arc_bridge_service()->AddObserver(this);
82 } 25 }
83 26
84 ArcPolicyBridge::ArcPolicyBridge(ArcBridgeService* bridge_service, 27 ArcPolicyBridge::ArcPolicyBridge(ArcBridgeService* bridge_service,
85 policy::PolicyService* policy_service) 28 policy::PolicyService* policy_service)
86 : ArcService(bridge_service), 29 : ArcService(bridge_service),
87 binding_(this), 30 binding_(this),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 void ArcPolicyBridge::InitializePolicyService() { 82 void ArcPolicyBridge::InitializePolicyService() {
140 const user_manager::User* const primary_user = 83 const user_manager::User* const primary_user =
141 user_manager::UserManager::Get()->GetPrimaryUser(); 84 user_manager::UserManager::Get()->GetPrimaryUser();
142 Profile* const profile = 85 Profile* const profile =
143 chromeos::ProfileHelper::Get()->GetProfileByUser(primary_user); 86 chromeos::ProfileHelper::Get()->GetProfileByUser(primary_user);
144 policy_service_ = 87 policy_service_ =
145 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile) 88 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile)
146 ->policy_service(); 89 ->policy_service();
147 } 90 }
148 91
92 std::string ArcPolicyBridge::GetFilteredJSONPolicies(
93 const policy::PolicyMap& policy_map) {
94 // TODO(phweiss): Implement general filtering mechanism when more policies
95 // need to be passed on.
96 // Create dictionary with the desired policies.
97 base::DictionaryValue filtered_policies;
98 const std::string policy_name = policy::key::kArcApplicationPolicy;
99 const base::Value* const policy_value = policy_map.GetValue(policy_name);
100 if (policy_value) {
101 filtered_policies.Set(policy_name,
102 policy_value->CreateDeepCopy().release());
103 }
104 // Convert dictionary to JSON.
105 std::string policy_json;
106 JSONStringValueSerializer serializer(&policy_json);
107 serializer.Serialize(filtered_policies);
108 return policy_json;
109 }
110
149 } // namespace arc 111 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_policy_bridge.h ('k') | chrome/browser/chromeos/arc/arc_policy_bridge_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698