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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/policy/PolicyManager.java

Issue 1220683008: Move AppRestriction to Policy code out of //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/android/chrome_jni_registrar.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 package org.chromium.chrome.browser.policy; 5 package org.chromium.chrome.browser.policy;
6 6
7 import android.os.Bundle; 7 import android.os.Bundle;
8 8
9 import org.chromium.base.CalledByNative; 9 import org.chromium.base.CalledByNative;
10 import org.chromium.base.ThreadUtils; 10 import org.chromium.base.ThreadUtils;
11 import org.chromium.policy.PolicyConverter;
11 12
12 import java.util.ArrayList; 13 import java.util.ArrayList;
13 import java.util.List; 14 import java.util.List;
14 15
15 /** 16 /**
16 * Reads enterprise policies from one or more policy providers 17 * Reads enterprise policies from one or more policy providers
17 * and plumbs them through to the policy subsystem. 18 * and plumbs them through to the policy subsystem.
18 */ 19 */
19 public class PolicyManager { 20 public class PolicyManager {
20 private long mNativePolicyManager; 21 private long mNativePolicyManager;
21 22
23 private PolicyConverter mPolicyConverter;
22 private final List<PolicyProvider> mPolicyProviders = new ArrayList<>(); 24 private final List<PolicyProvider> mPolicyProviders = new ArrayList<>();
23 private final List<Bundle> mCachedPolicies = new ArrayList<>(); 25 private final List<Bundle> mCachedPolicies = new ArrayList<>();
24 private final List<PolicyChangeListener> mPolicyChangeListeners = new ArrayL ist<>(); 26 private final List<PolicyChangeListener> mPolicyChangeListeners = new ArrayL ist<>();
25 27
26 public void initializeNative() { 28 public void initializeNative() {
27 ThreadUtils.assertOnUiThread(); 29 ThreadUtils.assertOnUiThread();
28 mNativePolicyManager = nativeInit(); 30 mNativePolicyManager = nativeInit();
31 mPolicyConverter = nativeCreatePolicyConverter(mNativePolicyManager);
29 } 32 }
30 33
31 /** 34 /**
32 * PolicyProviders are assigned a unique precedence based on their order of registration. 35 * PolicyProviders are assigned a unique precedence based on their order of registration.
33 * Later Registration -> Higher Precedence. 36 * Later Registration -> Higher Precedence.
34 * This precedence is also used as a 'source' tag for disambiguating updates . 37 * This precedence is also used as a 'source' tag for disambiguating updates .
35 */ 38 */
36 public void registerProvider(PolicyProvider provider) { 39 public void registerProvider(PolicyProvider provider) {
37 mPolicyProviders.add(provider); 40 mPolicyProviders.add(provider);
38 mCachedPolicies.add(null); 41 mCachedPolicies.add(null);
39 provider.setManagerAndSource(this, mPolicyProviders.size() - 1); 42 provider.setManagerAndSource(this, mPolicyProviders.size() - 1);
40 provider.refresh(); 43 provider.refresh();
41 } 44 }
42 45
43 public void destroy() { 46 public void destroy() {
44 // All the activities registered should have been destroyed by then. 47 // All the activities registered should have been destroyed by then.
45 assert mPolicyChangeListeners.isEmpty(); 48 assert mPolicyChangeListeners.isEmpty();
46 49
47 for (PolicyProvider provider : mPolicyProviders) { 50 for (PolicyProvider provider : mPolicyProviders) {
48 provider.destroy(); 51 provider.destroy();
49 } 52 }
50 mPolicyProviders.clear(); 53 mPolicyProviders.clear();
51 54
52 nativeDestroy(mNativePolicyManager); 55 nativeDestroy(mNativePolicyManager);
53 mNativePolicyManager = 0; 56 mNativePolicyManager = 0;
57 mPolicyConverter = null;
54 } 58 }
55 59
56 void onSettingsAvailable(int source, Bundle newSettings) { 60 void onSettingsAvailable(int source, Bundle newSettings) {
57 mCachedPolicies.set(source, newSettings); 61 mCachedPolicies.set(source, newSettings);
58 // Check if we have policies from all the providers before applying them . 62 // Check if we have policies from all the providers before applying them .
59 for (Bundle settings : mCachedPolicies) { 63 for (Bundle settings : mCachedPolicies) {
60 if (settings == null) return; 64 if (settings == null) return;
61 } 65 }
62 for (Bundle settings : mCachedPolicies) { 66 for (Bundle settings : mCachedPolicies) {
63 for (String key : settings.keySet()) { 67 for (String key : settings.keySet()) {
64 Object value = settings.get(key); 68 mPolicyConverter.setPolicy(key, settings.get(key));
65 if (value instanceof Boolean) {
66 nativeSetPolicyBoolean(mNativePolicyManager, key, (Boolean) value);
67 continue;
68 }
69 if (value instanceof String) {
70 nativeSetPolicyString(mNativePolicyManager, key, (String) va lue);
71 continue;
72 }
73 if (value instanceof Integer) {
74 nativeSetPolicyInteger(mNativePolicyManager, key, (Integer) value);
75 continue;
76 }
77 if (value instanceof String[]) {
78 nativeSetPolicyStringArray(mNativePolicyManager, key, (Strin g[]) value);
79 continue;
80 }
81 assert false : "Invalid setting " + value + " for key " + key;
82 } 69 }
83 } 70 }
84 nativeFlushPolicies(mNativePolicyManager); 71 nativeFlushPolicies(mNativePolicyManager);
85 } 72 }
86 73
87 void terminateIncognitoSession() { 74 void terminateIncognitoSession() {
88 for (PolicyChangeListener listener : mPolicyChangeListeners) { 75 for (PolicyChangeListener listener : mPolicyChangeListeners) {
89 listener.terminateIncognitoSession(); 76 listener.terminateIncognitoSession();
90 } 77 }
91 } 78 }
(...skipping 22 matching lines...) Expand all
114 * Interface to handle actions related with policy changes. 101 * Interface to handle actions related with policy changes.
115 */ 102 */
116 public interface PolicyChangeListener { 103 public interface PolicyChangeListener {
117 /** 104 /**
118 * Call to notify the listener that incognito browsing is unavailable du e to policy. 105 * Call to notify the listener that incognito browsing is unavailable du e to policy.
119 */ 106 */
120 void terminateIncognitoSession(); 107 void terminateIncognitoSession();
121 } 108 }
122 109
123 private native long nativeInit(); 110 private native long nativeInit();
111 private native PolicyConverter nativeCreatePolicyConverter(long nativePolicy Manager);
124 private native void nativeDestroy(long nativePolicyManager); 112 private native void nativeDestroy(long nativePolicyManager);
125
126 private native void nativeSetPolicyBoolean(
127 long nativePolicyManager, String policyKey, boolean value);
128 private native void nativeSetPolicyInteger(
129 long nativePolicyManager, String policyKey, int value);
130 private native void nativeSetPolicyString(
131 long nativePolicyManager, String policyKey, String value);
132 private native void nativeSetPolicyStringArray(
133 long nativePolicyManager, String policyKey, String[] value);
134 private native void nativeFlushPolicies(long nativePolicyManager); 113 private native void nativeFlushPolicies(long nativePolicyManager);
135 } 114 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/chrome_jni_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698