Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: remoting/host/policy_hack/policy_watcher_chromeos.cc

Issue 639233002: Remote assistance on Chrome OS Part IV - It2MeHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "chrome/browser/browser_process.h"
9 #include "components/policy/core/common/policy_service.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 virtual ~PolicyWatcherChromeOS() {}
25
26 // PolicyService::Observer implementation.
27 virtual void OnPolicyUpdated(const PolicyNamespace& ns,
28 const PolicyMap& previous,
29 const PolicyMap& current) OVERRIDE;
30
31 protected:
32 // PolicyWatcher overrides.
33 virtual void Reload() OVERRIDE;
34 virtual void StartWatchingInternal() OVERRIDE;
35 virtual void StopWatchingInternal() OVERRIDE;
36
37 private:
38 // Converts a policy map to DictionaryValues.
39 scoped_ptr<base::DictionaryValue> GetPolicyValues(const PolicyMap& map);
40
41 PolicyService* policy_service_;
42
43 DISALLOW_COPY_AND_ASSIGN(PolicyWatcherChromeOS);
44 };
45
46 PolicyWatcherChromeOS::PolicyWatcherChromeOS(
47 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
48 PolicyService* policy_service)
49 : PolicyWatcher(task_runner), policy_service_(policy_service) {
50 DCHECK(policy_service_);
51 }
52
53 void PolicyWatcherChromeOS::OnPolicyUpdated(const PolicyNamespace& ns,
54 const PolicyMap& previous,
55 const PolicyMap& current) {
56 Reload();
57 }
58
59 void PolicyWatcherChromeOS::Reload(){
60 const PolicyMap& map = policy_service_->GetPolicies(
61 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
62 scoped_ptr<base::DictionaryValue> policy_dict = GetPolicyValues(map);
63 DCHECK(policy_dict);
64 UpdatePolicies(policy_dict.get());
65 };
66
67 void PolicyWatcherChromeOS::StartWatchingInternal() {
68 policy_service_->AddObserver(POLICY_DOMAIN_CHROME, this);
69 Reload();
70 };
71
72 void PolicyWatcherChromeOS::StopWatchingInternal(){
73 policy_service_->RemoveObserver(POLICY_DOMAIN_CHROME, this);
74 };
75
76 scoped_ptr<base::DictionaryValue> PolicyWatcherChromeOS::GetPolicyValues(
77 const PolicyMap& map) {
78 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
79 for (PolicyMap::const_iterator it = map.begin(); it != map.end(); it++) {
80 result->Set(it->first, it->second.value->DeepCopy());
81 }
82 return result.Pass();
83 }
84
85 } // namespace
86
87 PolicyWatcher* PolicyWatcher::Create(
88 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
89 return new PolicyWatcherChromeOS(task_runner,
90 g_browser_process->policy_service());
91 }
92
93 } // namespace policy_hack
94 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698