Home | History | Annotate | Download | only in policy
      1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_
      6 #define CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_
      7 #pragma once
      8 
      9 #include "base/basictypes.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "base/observer_list.h"
     12 #include "chrome/browser/policy/configuration_policy_provider.h"
     13 
     14 class Profile;
     15 
     16 namespace policy {
     17 
     18 class CloudPolicySubsystem;
     19 class UserPolicyIdentityStrategy;
     20 
     21 // This class is a container for the profile-specific policy bits located in the
     22 // profile. Since the subsystem owns the policy provider, it's vital that it
     23 // gets initialized before the profile's prefs and destroyed after the prefs
     24 // are gone.
     25 class ProfilePolicyConnector {
     26  public:
     27   explicit ProfilePolicyConnector(Profile* profile);
     28   ~ProfilePolicyConnector();
     29 
     30   // Initializes the context. Should be called only after the profile's request
     31   // context is up.
     32   void Initialize();
     33 
     34   // Shuts the context down. This must be called before the networking
     35   // infrastructure in the profile goes away.
     36   void Shutdown();
     37 
     38   ConfigurationPolicyProvider* GetManagedCloudProvider();
     39   ConfigurationPolicyProvider* GetRecommendedCloudProvider();
     40 
     41  private:
     42   Profile* profile_;
     43 
     44   scoped_ptr<UserPolicyIdentityStrategy> identity_strategy_;
     45   scoped_ptr<CloudPolicySubsystem> cloud_policy_subsystem_;
     46 
     47   scoped_ptr<ConfigurationPolicyProvider> managed_cloud_provider_;
     48   scoped_ptr<ConfigurationPolicyProvider> recommended_cloud_provider_;
     49 
     50   DISALLOW_COPY_AND_ASSIGN(ProfilePolicyConnector);
     51 };
     52 
     53 // A wrapper for the ProfilePolicyConnector's cloud providers.
     54 //
     55 // Some well-known policies that are not provided by the
     56 // |profile_policy_provider_| are instead provided by the
     57 // |browser_policy_provider_|, thus merging device policies into
     58 // profile policies.
     59 //
     60 // Currently used to pass the device proxy settings into the profile
     61 // preferences.
     62 class MergingPolicyProvider: public ConfigurationPolicyProvider,
     63                              public ConfigurationPolicyProvider::Observer {
     64  public:
     65   MergingPolicyProvider(ConfigurationPolicyProvider* browser_policy_provider,
     66                         ConfigurationPolicyProvider* profile_policy_provider);
     67   virtual ~MergingPolicyProvider();
     68 
     69   // ConfigurationPolicyProvider methods:
     70   virtual bool Provide(ConfigurationPolicyStoreInterface* store) OVERRIDE;
     71   virtual void AddObserver(
     72       ConfigurationPolicyProvider::Observer* observer) OVERRIDE;
     73   virtual void RemoveObserver(
     74       ConfigurationPolicyProvider::Observer* observer) OVERRIDE;
     75 
     76   // ConfigurationPolicyProvider::Observer methods:
     77   virtual void OnUpdatePolicy() OVERRIDE;
     78   virtual void OnProviderGoingAway() OVERRIDE;
     79 
     80  private:
     81   ConfigurationPolicyProvider* browser_policy_provider_;
     82   ConfigurationPolicyProvider* profile_policy_provider_;
     83   scoped_ptr<ConfigurationPolicyObserverRegistrar> browser_registrar_;
     84   scoped_ptr<ConfigurationPolicyObserverRegistrar> profile_registrar_;
     85   ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_;
     86 
     87   DISALLOW_COPY_AND_ASSIGN(MergingPolicyProvider);
     88 };
     89 
     90 
     91 }  // namespace policy
     92 
     93 #endif  // CHROME_BROWSER_POLICY_PROFILE_POLICY_CONNECTOR_H_
     94