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 #ifndef REMOTING_HOST_POLICY_HACK_POLICY_SERVICE_WATCHER_H_ |
| 6 #define REMOTING_HOST_POLICY_HACK_POLICY_SERVICE_WATCHER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "components/policy/core/common/policy_service.h" |
| 12 #include "remoting/host/policy_hack/policy_watcher.h" |
| 13 |
| 14 namespace base { |
| 15 class SingleThreadTaskRunner; |
| 16 } // namespace base |
| 17 |
| 18 namespace policy { |
| 19 class AsyncPolicyLoader; |
| 20 class ConfigurationPolicyProvider; |
| 21 class SchemaRegistry; |
| 22 } // namespace policy |
| 23 |
| 24 namespace remoting { |
| 25 namespace policy_hack { |
| 26 |
| 27 // TODO(lukasza): Merge PolicyServiceWatcher with PolicyWatcher class. |
| 28 |
| 29 // PolicyServiceWatcher is a concrete implementation of PolicyWatcher that wraps |
| 30 // an instance of PolicyService. |
| 31 class PolicyServiceWatcher : public PolicyWatcher, |
| 32 public policy::PolicyService::Observer { |
| 33 public: |
| 34 // Constructor for the case when |policy_service| is borrowed. |
| 35 // |
| 36 // |policy_service_task_runner| is the task runner where it is safe |
| 37 // to call |policy_service| methods and where we expect to get callbacks |
| 38 // from |policy_service|. |
| 39 PolicyServiceWatcher(const scoped_refptr<base::SingleThreadTaskRunner>& |
| 40 policy_service_task_runner, |
| 41 policy::PolicyService* policy_service); |
| 42 |
| 43 // Constructor for the case when |policy_service| is owned (and uses also |
| 44 // owned |owned_policy_provider| and |owned_schema_registry|. |
| 45 // |
| 46 // |policy_service_task_runner| is the task runner where it is safe |
| 47 // to call |policy_service| methods and where we expect to get callbacks |
| 48 // from |policy_service|. |
| 49 PolicyServiceWatcher( |
| 50 const scoped_refptr<base::SingleThreadTaskRunner>& |
| 51 policy_service_task_runner, |
| 52 scoped_ptr<policy::PolicyService> owned_policy_service, |
| 53 scoped_ptr<policy::ConfigurationPolicyProvider> owned_policy_provider, |
| 54 scoped_ptr<policy::SchemaRegistry> owned_schema_registry); |
| 55 |
| 56 ~PolicyServiceWatcher() override; |
| 57 |
| 58 // Creates PolicyServiceWatcher that wraps the owned |async_policy_loader| |
| 59 // with an appropriate PolicySchema. |
| 60 // |
| 61 // |policy_service_task_runner| is passed through to the constructor |
| 62 // of PolicyServiceWatcher. |
| 63 static scoped_ptr<PolicyServiceWatcher> CreateFromPolicyLoader( |
| 64 const scoped_refptr<base::SingleThreadTaskRunner>& |
| 65 policy_service_task_runner, |
| 66 scoped_ptr<policy::AsyncPolicyLoader> async_policy_loader); |
| 67 |
| 68 // PolicyService::Observer interface. |
| 69 void OnPolicyUpdated(const policy::PolicyNamespace& ns, |
| 70 const policy::PolicyMap& previous, |
| 71 const policy::PolicyMap& current) override; |
| 72 void OnPolicyServiceInitialized(policy::PolicyDomain domain) override; |
| 73 |
| 74 protected: |
| 75 // PolicyWatcher overrides. |
| 76 void StartWatchingInternal() override; |
| 77 void StopWatchingInternal() override; |
| 78 |
| 79 private: |
| 80 policy::PolicyService* policy_service_; |
| 81 |
| 82 // Order of fields below is important to ensure destruction takes object |
| 83 // dependencies into account: |
| 84 // - |owned_policy_service_| uses |owned_policy_provider_| |
| 85 // - |owned_policy_provider_| uses |owned_schema_registry_| |
| 86 scoped_ptr<policy::SchemaRegistry> owned_schema_registry_; |
| 87 scoped_ptr<policy::ConfigurationPolicyProvider> owned_policy_provider_; |
| 88 scoped_ptr<policy::PolicyService> owned_policy_service_; |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(PolicyServiceWatcher); |
| 91 }; |
| 92 |
| 93 } // namespace policy_hack |
| 94 } // namespace remoting |
| 95 |
| 96 #endif // REMOTING_HOST_POLICY_HACK_POLICY_SERVICE_WATCHER_H_ |
OLD | NEW |