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