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

Unified Diff: chrome/browser/chromeos/arc/arc_policy_bridge.cc

Issue 1864523002: Pass policy VideoCaptureAllowed to ARC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modify testcases 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/arc/arc_policy_bridge.cc
diff --git a/chrome/browser/chromeos/arc/arc_policy_bridge.cc b/chrome/browser/chromeos/arc/arc_policy_bridge.cc
index e472d9ad5d5cfe7b2903ad00a0e400ded09f0c7f..15f7bf78cb47343bf12fd9fc865f9a94de5293b3 100644
--- a/chrome/browser/chromeos/arc/arc_policy_bridge.cc
+++ b/chrome/browser/chromeos/arc/arc_policy_bridge.cc
@@ -4,6 +4,9 @@
#include "chrome/browser/chromeos/arc/arc_policy_bridge.h"
+#include <string>
+
+#include "base/json/json_reader.h"
#include "base/json/json_string_value_serializer.h"
#include "base/logging.h"
#include "base/values.h"
@@ -18,6 +21,60 @@
namespace arc {
+namespace {
+
+// invert_bool_value: If the Chrome policy and the ARC policy with boolean value
+// have opposite semantics, set this to true so the bool is inverted before
+// being added. Otherwise, set it to false.
+void AddPolicy(const std::string arc_policy_name,
+ const std::string policy_name,
+ const policy::PolicyMap& policy_map,
+ bool invert_bool_value,
+ base::DictionaryValue& filtered_policies) {
+ const base::Value* const policy_value = policy_map.GetValue(policy_name);
+ if (policy_value) {
+ if (invert_bool_value && policy_value->IsType(base::Value::TYPE_BOOLEAN)) {
+ bool bool_value;
+ policy_value->GetAsBoolean(&bool_value);
+ filtered_policies.SetBoolean(arc_policy_name, !bool_value);
+ } else {
+ filtered_policies.Set(arc_policy_name,
+ policy_value->CreateDeepCopy().release());
+ }
+ }
+}
+
+std::string GetFilteredJSONPolicies(const policy::PolicyMap& policy_map) {
+ base::DictionaryValue filtered_policies;
+ // Parse ArcApplicationPolicy as JSON string before adding other policies to
+ // the dictionary.
+ const base::Value* const app_policy_value =
+ policy_map.GetValue(policy::key::kArcApplicationPolicy);
+ if (app_policy_value) {
+ std::string app_policy_string;
+ app_policy_value->GetAsString(&app_policy_string);
+ std::unique_ptr<base::DictionaryValue> app_policy_dict =
bartfab (slow) 2016/04/07 12:46:29 Nit: #include <memory>
+ base::DictionaryValue::From(base::JSONReader::Read(app_policy_string));
+ if (app_policy_dict) {
+ filtered_policies.Swap(app_policy_dict.get());
bartfab (slow) 2016/04/07 12:46:29 This is correct but dangerous: The Swap() throws a
+ } else {
+ LOG(ERROR) << "Value of ArcApplicationPolicy has invalid format: "
bartfab (slow) 2016/04/07 12:46:29 We would ideally surface this on the chrome://poli
+ << app_policy_string;
+ }
+ }
+
+ // Keep them sorted by the ARC policy names.
+ AddPolicy("cameraDisabled", policy::key::kVideoCaptureAllowed, policy_map,
+ true, filtered_policies);
+
+ std::string policy_json;
+ JSONStringValueSerializer serializer(&policy_json);
+ serializer.Serialize(filtered_policies);
+ return policy_json;
+}
+
+} // namespace
+
ArcPolicyBridge::ArcPolicyBridge(ArcBridgeService* bridge_service)
: ArcService(bridge_service), binding_(this) {
VLOG(1) << "ArcPolicyBridge::ArcPolicyBridge";
@@ -89,23 +146,4 @@ void ArcPolicyBridge::InitializePolicyService() {
->policy_service();
}
-std::string ArcPolicyBridge::GetFilteredJSONPolicies(
- const policy::PolicyMap& policy_map) {
- // TODO(phweiss): Implement general filtering mechanism when more policies
- // need to be passed on.
- // Create dictionary with the desired policies.
- base::DictionaryValue filtered_policies;
- const std::string policy_name = policy::key::kArcApplicationPolicy;
- const base::Value* const policy_value = policy_map.GetValue(policy_name);
- if (policy_value) {
- filtered_policies.Set(policy_name,
- policy_value->CreateDeepCopy().release());
- }
- // Convert dictionary to JSON.
- std::string policy_json;
- JSONStringValueSerializer serializer(&policy_json);
- serializer.Serialize(filtered_policies);
- return policy_json;
-}
-
} // namespace arc
« 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