Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 "remoting/host/policy_hack/policy_watcher.h" | |
| 6 | |
| 7 #include "base/single_thread_task_runner.h" | |
| 8 #include "components/policy/core/common/policy_service.h" | |
| 9 | |
| 10 using namespace policy; | |
| 11 | |
| 12 namespace remoting { | |
| 13 namespace policy_hack { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 class PolicyWatcherChromeOS : public PolicyWatcher, | |
| 18 public PolicyService::Observer { | |
| 19 public: | |
| 20 PolicyWatcherChromeOS(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 21 PolicyService* policy_service); | |
| 22 | |
| 23 virtual ~PolicyWatcherChromeOS() {} | |
| 24 | |
| 25 // PolicyService::Observer implementation. | |
| 26 virtual void OnPolicyUpdated(const PolicyNamespace& ns, | |
| 27 const PolicyMap& previous, | |
| 28 const PolicyMap& current) OVERRIDE; | |
| 29 | |
| 30 protected: | |
| 31 // PolicyWatcher overrides. | |
| 32 virtual void Reload() OVERRIDE; | |
| 33 virtual void StartWatchingInternal() OVERRIDE; | |
| 34 virtual void StopWatchingInternal() OVERRIDE; | |
| 35 | |
| 36 private: | |
| 37 // Converts a policy map to DictionaryValues. | |
| 38 scoped_ptr<base::DictionaryValue> GetPolicyValues(const PolicyMap& map); | |
|
Jamie
2014/10/14 01:18:42
I don't think this needs to be a separate method,
kelvinp
2014/10/15 23:03:10
Done.
| |
| 39 | |
| 40 PolicyService* policy_service_; | |
| 41 | |
| 42 DISALLOW_COPY_AND_ASSIGN(PolicyWatcherChromeOS); | |
| 43 }; | |
| 44 | |
| 45 PolicyWatcherChromeOS::PolicyWatcherChromeOS( | |
| 46 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 47 PolicyService* policy_service) | |
| 48 : PolicyWatcher(task_runner), policy_service_(policy_service) { | |
| 49 DCHECK(policy_service_); | |
| 50 } | |
| 51 | |
| 52 void PolicyWatcherChromeOS::OnPolicyUpdated(const PolicyNamespace& ns, | |
| 53 const PolicyMap& previous, | |
|
Jamie
2014/10/14 01:18:42
Indentation.
kelvinp
2014/10/15 23:03:10
Done.
| |
| 54 const PolicyMap& current) { | |
| 55 Reload(); | |
| 56 } | |
| 57 | |
| 58 void PolicyWatcherChromeOS::Reload(){ | |
| 59 const PolicyMap& map = policy_service_->GetPolicies( | |
| 60 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | |
| 61 scoped_ptr<base::DictionaryValue> policy_dict = GetPolicyValues(map); | |
| 62 DCHECK(policy_dict); | |
| 63 UpdatePolicies(policy_dict.get()); | |
| 64 }; | |
| 65 | |
| 66 void PolicyWatcherChromeOS::StartWatchingInternal() { | |
| 67 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, this); | |
| 68 Reload(); | |
| 69 }; | |
| 70 | |
| 71 void PolicyWatcherChromeOS::StopWatchingInternal(){ | |
| 72 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, this); | |
| 73 }; | |
| 74 | |
| 75 scoped_ptr<base::DictionaryValue> PolicyWatcherChromeOS::GetPolicyValues( | |
| 76 const PolicyMap& map) { | |
| 77 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | |
| 78 for (PolicyMap::const_iterator it = map.begin(); it != map.end(); it++) { | |
| 79 result->Set(it->first, it->second.value->DeepCopy()); | |
| 80 } | |
| 81 return result.Pass(); | |
| 82 } | |
| 83 | |
| 84 } // namespace | |
| 85 | |
| 86 PolicyWatcher* PolicyWatcher::Create( | |
| 87 ChromotingHostContext* context, | |
| 88 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
| 89 return new PolicyWatcherChromeOS(task_runner, | |
| 90 context->policy_service()); | |
| 91 } | |
| 92 | |
| 93 } // namespace policy_hack | |
| 94 } // namespace remoting | |
| OLD | NEW |