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 "content/public/browser/browser_thread.h" | |
9 #include "remoting/base/auto_thread_task_runner.h" | |
10 | |
11 using namespace policy; | |
12 | |
13 namespace remoting { | |
14 namespace policy_hack { | |
15 | |
16 namespace { | |
17 | |
18 class PolicyWatcherChromeOS : public PolicyWatcher, | |
19 public PolicyService::Observer { | |
20 public: | |
21 PolicyWatcherChromeOS(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
22 PolicyService* policy_service); | |
23 | |
24 ~PolicyWatcherChromeOS() override; | |
25 | |
26 // PolicyService::Observer interface. | |
27 void OnPolicyUpdated(const PolicyNamespace& ns, | |
28 const PolicyMap& previous, | |
29 const PolicyMap& current) override; | |
30 | |
31 protected: | |
32 // PolicyWatcher interface. | |
33 void Reload() override; | |
34 void StartWatchingInternal() override; | |
35 void StopWatchingInternal() override; | |
36 | |
37 private: | |
38 PolicyService* policy_service_; | |
39 | |
40 DISALLOW_COPY_AND_ASSIGN(PolicyWatcherChromeOS); | |
41 }; | |
42 | |
43 PolicyWatcherChromeOS::PolicyWatcherChromeOS( | |
44 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
45 PolicyService* policy_service) | |
46 : PolicyWatcher(task_runner), policy_service_(policy_service) { | |
47 } | |
48 | |
49 PolicyWatcherChromeOS::~PolicyWatcherChromeOS() { | |
50 } | |
51 | |
52 void PolicyWatcherChromeOS::OnPolicyUpdated(const PolicyNamespace& ns, | |
53 const PolicyMap& previous, | |
54 const PolicyMap& current) { | |
55 scoped_ptr<base::DictionaryValue> policy_dict(new base::DictionaryValue()); | |
56 for (PolicyMap::const_iterator it = current.begin(); it != current.end(); | |
57 it++) { | |
58 policy_dict->Set(it->first, it->second.value->DeepCopy()); | |
59 } | |
60 UpdatePolicies(policy_dict.get()); | |
61 } | |
62 | |
63 void PolicyWatcherChromeOS::Reload() { | |
64 PolicyNamespace ns(POLICY_DOMAIN_CHROME, std::string()); | |
65 const PolicyMap& current = policy_service_->GetPolicies(ns); | |
66 OnPolicyUpdated(ns, current, current); | |
67 }; | |
68 | |
69 void PolicyWatcherChromeOS::StartWatchingInternal() { | |
70 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, this); | |
71 Reload(); | |
72 }; | |
73 | |
74 void PolicyWatcherChromeOS::StopWatchingInternal() { | |
75 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, this); | |
76 }; | |
77 | |
78 } // namespace | |
79 | |
80 scoped_ptr<PolicyWatcher> PolicyWatcher::Create( | |
81 policy::PolicyService* policy_service, | |
82 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
83 return make_scoped_ptr(new PolicyWatcherChromeOS( | |
84 content::BrowserThread::GetMessageLoopProxyForThread( | |
85 content::BrowserThread::UI), | |
86 policy_service)); | |
87 } | |
88 | |
89 } // namespace policy_hack | |
90 } // namespace remoting | |
OLD | NEW |