Home | History | Annotate | Download | only in common
      1 // Copyright 2014 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 #include "components/policy/core/common/policy_provider_android.h"
      6 #include "components/policy/core/common/policy_provider_android_delegate.h"
      7 
      8 namespace policy {
      9 
     10 namespace {
     11 
     12 bool g_wait_for_policies = false;
     13 
     14 }  // namespace
     15 
     16 PolicyProviderAndroid::PolicyProviderAndroid()
     17     : delegate_(NULL),
     18       initialized_(!g_wait_for_policies) {}
     19 
     20 PolicyProviderAndroid::~PolicyProviderAndroid() {}
     21 
     22 const Schema* PolicyProviderAndroid::GetChromeSchema() const {
     23   PolicyNamespace ns(POLICY_DOMAIN_CHROME, std::string());
     24   return schema_map()->GetSchema(ns);
     25 }
     26 
     27 // static
     28 void PolicyProviderAndroid::SetShouldWaitForPolicy(
     29     bool should_wait_for_policy) {
     30   g_wait_for_policies = should_wait_for_policy;
     31 }
     32 
     33 void PolicyProviderAndroid::SetDelegate(
     34     PolicyProviderAndroidDelegate* delegate) {
     35   delegate_ = delegate;
     36 }
     37 
     38 void PolicyProviderAndroid::SetPolicies(scoped_ptr<PolicyBundle> policy) {
     39   initialized_ = true;
     40   UpdatePolicy(policy.Pass());
     41 }
     42 
     43 void PolicyProviderAndroid::Shutdown() {
     44   if (delegate_)
     45     delegate_->PolicyProviderShutdown();
     46 
     47   ConfigurationPolicyProvider::Shutdown();
     48 }
     49 
     50 bool PolicyProviderAndroid::IsInitializationComplete(
     51     PolicyDomain domain) const {
     52   return initialized_;
     53 }
     54 
     55 void PolicyProviderAndroid::RefreshPolicies() {
     56   if (delegate_) {
     57     delegate_->RefreshPolicies();
     58   } else {
     59     // If we don't have a delegate, pass a copy of the current policies.
     60     scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
     61     bundle->CopyFrom(policies());
     62     UpdatePolicy(bundle.Pass());
     63   }
     64 }
     65 
     66 }  // namespace policy
     67