OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.policy; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.os.Bundle; |
| 9 |
| 10 /** |
| 11 * Base class for Policy providers. |
| 12 */ |
| 13 public abstract class PolicyProvider { |
| 14 private PolicyManager mPolicyManager; |
| 15 protected final Context mContext; |
| 16 private int mSource = -1; |
| 17 |
| 18 protected PolicyProvider(Context context) { |
| 19 mContext = context.getApplicationContext(); |
| 20 } |
| 21 |
| 22 protected void notifySettingsAvailable(Bundle settings) { |
| 23 mPolicyManager.onSettingsAvailable(mSource, settings); |
| 24 } |
| 25 |
| 26 protected void terminateIncognitoSession() { |
| 27 mPolicyManager.terminateIncognitoSession(); |
| 28 } |
| 29 |
| 30 /** |
| 31 * Called to request a refreshed set of policies. |
| 32 * This method must handle notifying the PolicyManager whenever applicable. |
| 33 */ |
| 34 public abstract void refresh(); |
| 35 |
| 36 /** |
| 37 * Register the PolicyProvider for receiving policy changes. |
| 38 */ |
| 39 protected void startListeningForPolicyChanges() { |
| 40 } |
| 41 |
| 42 /** |
| 43 * Called by the {@link PolicyManager} to correctly hook it with the Policy
system. |
| 44 * @param policyManager reference to the PolicyManager to be used like a del
egate. |
| 45 * @param source tags the PolicyProvider with a source. |
| 46 */ |
| 47 final void setManagerAndSource(PolicyManager policyManager, int source) { |
| 48 assert mSource < 0; |
| 49 assert source >= 0; |
| 50 mSource = source; |
| 51 assert mPolicyManager == null; |
| 52 mPolicyManager = policyManager; |
| 53 startListeningForPolicyChanges(); |
| 54 } |
| 55 |
| 56 /** Called when the provider is unregistered */ |
| 57 public void destroy() { |
| 58 } |
| 59 } |
OLD | NEW |