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 "components/policy/core/common/policy_service.h" | |
| 8 #include "remoting/base/auto_thread_task_runner.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() {} | |
|
Wez
2014/10/17 17:58:01
Don't inline virtuals, even destructors (except in
kelvinp
2014/10/20 00:21:18
Done.
| |
| 24 | |
| 25 // PolicyService::Observer implementation. | |
|
Wez
2014/10/17 17:58:01
s/implementation/interface
kelvinp
2014/10/20 00:21:18
Seems like sergey prefers implementation and you p
| |
| 26 virtual void OnPolicyUpdated(const PolicyNamespace& ns, | |
| 27 const PolicyMap& previous, | |
| 28 const PolicyMap& current) OVERRIDE; | |
| 29 | |
| 30 protected: | |
| 31 // PolicyWatcher overrides. | |
|
Wez
2014/10/17 17:58:01
s/overrides/interface
kelvinp
2014/10/20 00:21:18
Done.
| |
| 32 virtual void Reload() OVERRIDE; | |
| 33 virtual void StartWatchingInternal() OVERRIDE; | |
| 34 virtual void StopWatchingInternal() OVERRIDE; | |
| 35 | |
| 36 private: | |
| 37 PolicyService* policy_service_; | |
| 38 | |
| 39 DISALLOW_COPY_AND_ASSIGN(PolicyWatcherChromeOS); | |
| 40 }; | |
| 41 | |
| 42 PolicyWatcherChromeOS::PolicyWatcherChromeOS( | |
| 43 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 44 PolicyService* policy_service) | |
|
Wez
2014/10/17 17:58:01
What's the lifetime guarantee/requirement on polic
kelvinp
2014/10/20 00:21:18
Good point. Comments added.
| |
| 45 : PolicyWatcher(task_runner), policy_service_(policy_service) { | |
| 46 DCHECK(policy_service_); | |
| 47 } | |
| 48 | |
| 49 void PolicyWatcherChromeOS::OnPolicyUpdated(const PolicyNamespace& ns, | |
| 50 const PolicyMap& previous, | |
| 51 const PolicyMap& current) { | |
| 52 Reload(); | |
| 53 } | |
| 54 | |
| 55 void PolicyWatcherChromeOS::Reload(){ | |
|
Wez
2014/10/17 17:58:01
nit: Space between () and {
kelvinp
2014/10/20 00:21:18
Done.
| |
| 56 const PolicyMap& map = policy_service_->GetPolicies( | |
| 57 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | |
|
Wez
2014/10/17 17:58:01
This is redundant in the OnPolicyUpdated case, sin
kelvinp
2014/10/20 00:21:18
Done.
| |
| 58 | |
| 59 scoped_ptr<base::DictionaryValue> policy_dict(new base::DictionaryValue()); | |
| 60 | |
| 61 for (PolicyMap::const_iterator it = map.begin(); it != map.end(); it++) { | |
| 62 policy_dict->Set(it->first, it->second.value->DeepCopy()); | |
| 63 } | |
| 64 | |
| 65 UpdatePolicies(policy_dict.get()); | |
| 66 }; | |
| 67 | |
| 68 void PolicyWatcherChromeOS::StartWatchingInternal() { | |
| 69 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, this); | |
| 70 Reload(); | |
| 71 }; | |
| 72 | |
| 73 void PolicyWatcherChromeOS::StopWatchingInternal(){ | |
| 74 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, this); | |
| 75 }; | |
| 76 | |
| 77 } // namespace | |
| 78 | |
| 79 PolicyWatcher* PolicyWatcher::Create( | |
| 80 ChromotingHostContext* context, | |
| 81 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
| 82 // The PolicyWatcher on ChromeOS accesses the PolicyService object, which must | |
| 83 // be called on the UI thread of the browser process. | |
| 84 return new PolicyWatcherChromeOS(context->ui_task_runner(), | |
| 85 context->policy_service()); | |
| 86 } | |
| 87 | |
| 88 } // namespace policy_hack | |
| 89 } // namespace remoting | |
| OLD | NEW |