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 // The caller must ensure that |policy_service| remains valid for the lifetime | |
22 // of PolicyWatcherChromeOS. | |
Wez
2014/10/24 00:28:48
This is a contract on the Create API, so put the c
kelvinp
2014/10/24 21:39:42
Done.
| |
23 PolicyWatcherChromeOS(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
24 PolicyService* policy_service); | |
25 | |
26 ~PolicyWatcherChromeOS() override; | |
27 | |
28 // PolicyService::Observer interface. | |
29 void OnPolicyUpdated(const PolicyNamespace& ns, | |
30 const PolicyMap& previous, | |
31 const PolicyMap& current) override; | |
32 | |
33 protected: | |
34 // PolicyWatcher interface. | |
35 void Reload() override; | |
36 void StartWatchingInternal() override; | |
37 void StopWatchingInternal() override; | |
38 | |
39 private: | |
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 } | |
50 | |
51 PolicyWatcherChromeOS::~PolicyWatcherChromeOS() { | |
52 } | |
53 | |
54 void PolicyWatcherChromeOS::OnPolicyUpdated(const PolicyNamespace& ns, | |
55 const PolicyMap& previous, | |
56 const PolicyMap& current) { | |
57 scoped_ptr<base::DictionaryValue> policy_dict(new base::DictionaryValue()); | |
58 for (PolicyMap::const_iterator it = current.begin(); it != current.end(); | |
59 it++) { | |
60 policy_dict->Set(it->first, it->second.value->DeepCopy()); | |
61 } | |
62 UpdatePolicies(policy_dict.get()); | |
63 } | |
64 | |
65 void PolicyWatcherChromeOS::Reload() { | |
66 PolicyNamespace ns(POLICY_DOMAIN_CHROME, std::string()); | |
67 const PolicyMap& current = policy_service_->GetPolicies(ns); | |
68 OnPolicyUpdated(ns, current, current); | |
69 }; | |
70 | |
71 void PolicyWatcherChromeOS::StartWatchingInternal() { | |
72 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, this); | |
73 Reload(); | |
74 }; | |
75 | |
76 void PolicyWatcherChromeOS::StopWatchingInternal() { | |
77 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, this); | |
78 }; | |
79 | |
80 } // namespace | |
81 | |
82 scoped_ptr<PolicyWatcher> PolicyWatcher::Create( | |
83 policy::PolicyService* policy_service, | |
84 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | |
85 return make_scoped_ptr(new PolicyWatcherChromeOS( | |
86 content::BrowserThread::GetMessageLoopProxyForThread( | |
87 content::BrowserThread::UI), | |
88 policy_service)); | |
89 } | |
90 | |
91 } // namespace policy_hack | |
92 } // namespace remoting | |
OLD | NEW |