Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_H_ | 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "chrome/browser/policy/policy_bundle.h" | 12 #include "chrome/browser/policy/policy_bundle.h" |
| 13 #include "chrome/browser/policy/schema_registry.h" | |
| 13 #include "components/policy/core/common/policy_namespace.h" | 14 #include "components/policy/core/common/policy_namespace.h" |
| 14 | 15 |
| 15 namespace policy { | 16 namespace policy { |
| 16 | 17 |
| 17 class PolicyDomainDescriptor; | |
| 18 | |
| 19 // A mostly-abstract super class for platform-specific policy providers. | 18 // A mostly-abstract super class for platform-specific policy providers. |
| 20 // Platform-specific policy providers (Windows Group Policy, gconf, | 19 // Platform-specific policy providers (Windows Group Policy, gconf, |
| 21 // etc.) should implement a subclass of this class. | 20 // etc.) should implement a subclass of this class. |
| 22 class ConfigurationPolicyProvider { | 21 class ConfigurationPolicyProvider : public SchemaRegistry::Observer { |
| 23 public: | 22 public: |
| 24 class Observer { | 23 class Observer { |
| 25 public: | 24 public: |
| 26 virtual ~Observer(); | 25 virtual ~Observer(); |
| 27 virtual void OnUpdatePolicy(ConfigurationPolicyProvider* provider) = 0; | 26 virtual void OnUpdatePolicy(ConfigurationPolicyProvider* provider) = 0; |
| 28 }; | 27 }; |
| 29 | 28 |
| 30 ConfigurationPolicyProvider(); | 29 ConfigurationPolicyProvider(); |
| 31 | 30 |
| 32 // Policy providers can be deleted quite late during shutdown of the browser, | 31 // Policy providers can be deleted quite late during shutdown of the browser, |
| 33 // and it's not guaranteed that the message loops will still be running when | 32 // and it's not guaranteed that the message loops will still be running when |
| 34 // this is invoked. Override Shutdown() instead for cleanup code that needs | 33 // this is invoked. Override Shutdown() instead for cleanup code that needs |
| 35 // to post to the FILE thread, for example. | 34 // to post to the FILE thread, for example. |
| 36 virtual ~ConfigurationPolicyProvider(); | 35 virtual ~ConfigurationPolicyProvider(); |
| 37 | 36 |
| 38 // Invoked as soon as the main message loops are spinning. Policy providers | 37 // Invoked as soon as the main message loops are spinning. Policy providers |
| 39 // are created early during startup to provide the initial policies; the | 38 // are created early during startup to provide the initial policies; the |
| 40 // Init() call allows them to perform initialization tasks that require | 39 // Init() call allows them to perform initialization tasks that require |
| 41 // running message loops. | 40 // running message loops. |
| 42 virtual void Init(); | 41 // The policy provider will load policy for the components registered in |
| 42 // the |schema_registry|, and will reload whenever the registry issues | |
| 43 // updated. | |
|
bartfab (slow)
2013/11/05 15:53:04
* "whenever the registry issues updated"? This sta
Joao da Silva
2013/11/07 13:15:00
Done.
| |
| 44 virtual void Init(SchemaRegistry* registry); | |
| 43 | 45 |
| 44 // Must be invoked before deleting the provider. Implementations can override | 46 // Must be invoked before deleting the provider. Implementations can override |
| 45 // this method to do appropriate cleanup while threads are still running, and | 47 // this method to do appropriate cleanup while threads are still running, and |
| 46 // must also invoke ConfigurationPolicyProvider::Shutdown(). | 48 // must also invoke ConfigurationPolicyProvider::Shutdown(). |
| 47 // The provider should keep providing the current policies after Shutdown() | 49 // The provider should keep providing the current policies after Shutdown() |
| 48 // is invoked, it only has to stop updating. | 50 // is invoked, it only has to stop updating. |
| 49 virtual void Shutdown(); | 51 virtual void Shutdown(); |
| 50 | 52 |
| 51 // Returns the current PolicyBundle. | 53 // Returns the current PolicyBundle. |
| 52 const PolicyBundle& policies() const { return policy_bundle_; } | 54 const PolicyBundle& policies() const { return policy_bundle_; } |
| 53 | 55 |
| 54 // Check whether this provider has completed initialization for the given | 56 // Check whether this provider has completed initialization for the given |
| 55 // policy |domain|. This is used to detect whether initialization is done in | 57 // policy |domain|. This is used to detect whether initialization is done in |
| 56 // case implementations need to do asynchronous operations for initialization. | 58 // case implementations need to do asynchronous operations for initialization. |
| 57 virtual bool IsInitializationComplete(PolicyDomain domain) const; | 59 virtual bool IsInitializationComplete(PolicyDomain domain) const; |
| 58 | 60 |
| 59 // Asks the provider to refresh its policies. All the updates caused by this | 61 // Asks the provider to refresh its policies. All the updates caused by this |
| 60 // call will be visible on the next call of OnUpdatePolicy on the observers, | 62 // call will be visible on the next call of OnUpdatePolicy on the observers, |
| 61 // which are guaranteed to happen even if the refresh fails. | 63 // which are guaranteed to happen even if the refresh fails. |
| 62 // It is possible that Shutdown() is called first though, and | 64 // It is possible that Shutdown() is called first though, and |
| 63 // OnUpdatePolicy won't be called if that happens. | 65 // OnUpdatePolicy won't be called if that happens. |
| 64 virtual void RefreshPolicies() = 0; | 66 virtual void RefreshPolicies() = 0; |
| 65 | 67 |
| 66 // Observers must detach themselves before the provider is deleted. | 68 // Observers must detach themselves before the provider is deleted. |
| 67 virtual void AddObserver(Observer* observer); | 69 virtual void AddObserver(Observer* observer); |
| 68 virtual void RemoveObserver(Observer* observer); | 70 virtual void RemoveObserver(Observer* observer); |
| 69 | 71 |
| 70 // Notifies the provider that there is interest in loading policy for the | 72 // SchemaRegistry::Observer: |
| 71 // listed components in the given |descriptor|. The list is complete; all the | 73 // The base implementation just calls RefreshPolicies. |
|
bartfab (slow)
2013/11/05 15:53:04
Nit: Maybe better s/The base implementation/This b
Joao da Silva
2013/11/07 13:15:00
Done.
| |
| 72 // components that matter for the domain are included, and components not | 74 virtual void OnSchemaRegistryUpdated( |
| 73 // included can be discarded. The provider can ignore this information or use | 75 const scoped_refptr<SchemaMap>& current_map, |
|
bartfab (slow)
2013/11/05 15:53:04
Nit: SchemaMap:
* Forward-declare here.
* #include
Joao da Silva
2013/11/07 13:15:00
It's part of the interface that this is overriding
| |
| 74 // it to selectively load the corresponding policy from its sources. | 76 bool has_new_schemas) OVERRIDE; |
| 75 virtual void RegisterPolicyDomain( | |
| 76 scoped_refptr<const PolicyDomainDescriptor> descriptor); | |
| 77 | 77 |
| 78 protected: | 78 protected: |
| 79 // Subclasses must invoke this to update the policies currently served by | 79 // Subclasses must invoke this to update the policies currently served by |
| 80 // this provider. UpdatePolicy() takes ownership of |policies|. | 80 // this provider. UpdatePolicy() takes ownership of |policies|. |
| 81 // The observers are notified after the policies are updated. | 81 // The observers are notified after the policies are updated. |
| 82 void UpdatePolicy(scoped_ptr<PolicyBundle> bundle); | 82 void UpdatePolicy(scoped_ptr<PolicyBundle> bundle); |
| 83 | 83 |
| 84 const scoped_refptr<SchemaMap>& schema_map() const; | |
| 85 | |
| 84 private: | 86 private: |
| 85 // The policies currently configured at this provider. | 87 // The policies currently configured at this provider. |
| 86 PolicyBundle policy_bundle_; | 88 PolicyBundle policy_bundle_; |
| 87 | 89 |
| 88 // Whether Shutdown() has been invoked. | 90 // Whether Shutdown() has been invoked. |
| 89 bool did_shutdown_; | 91 bool did_shutdown_; |
| 90 | 92 |
| 93 SchemaRegistry* schema_registry_; | |
| 94 | |
| 91 ObserverList<Observer, true> observer_list_; | 95 ObserverList<Observer, true> observer_list_; |
| 92 | 96 |
| 93 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProvider); | 97 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProvider); |
| 94 }; | 98 }; |
| 95 | 99 |
| 96 } // namespace policy | 100 } // namespace policy |
| 97 | 101 |
| 98 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_H_ | 102 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_H_ |
| OLD | NEW |