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

Side by Side Diff: chrome/browser/policy/cloud_policy_cache_base.cc

Issue 6705031: Send policy blobs to session_manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "chrome/browser/policy/cloud_policy_cache_base.h"
6
7 #include <string>
8
9 #include "base/logging.h"
10 #include "base/values.h"
11 #include "chrome/browser/policy/configuration_policy_pref_store.h"
12
13 namespace policy {
14
15 // A thin ConfigurationPolicyProvider implementation sitting on top of
16 // CloudPolicyCache for hooking up with ConfigurationPolicyPrefStore.
17 class CloudPolicyCacheBase::CloudPolicyProvider
18 : public ConfigurationPolicyProvider {
19 public:
20 CloudPolicyProvider(const PolicyDefinitionList* policy_list,
21 CloudPolicyCacheBase* cache,
22 CloudPolicyCacheBase::PolicyLevel level)
23 : ConfigurationPolicyProvider(policy_list),
24 cache_(cache),
25 level_(level) {}
26 virtual ~CloudPolicyProvider() {}
27
28 virtual bool Provide(ConfigurationPolicyStoreInterface* store) {
29 if (level_ == POLICY_LEVEL_MANDATORY)
30 ApplyPolicyMap(&cache_->mandatory_policy_, store);
31 else if (level_ == POLICY_LEVEL_RECOMMENDED)
32 ApplyPolicyMap(&cache_->recommended_policy_, store);
33 return true;
34 }
35
36 virtual bool IsInitializationComplete() const {
37 return cache_->initialization_complete_;
38 }
39
40 virtual void AddObserver(ConfigurationPolicyProvider::Observer* observer) {
41 cache_->observer_list_.AddObserver(observer);
42 }
43 virtual void RemoveObserver(ConfigurationPolicyProvider::Observer* observer) {
44 cache_->observer_list_.RemoveObserver(observer);
45 }
46
47 private:
48 // The underlying policy cache.
49 CloudPolicyCacheBase* cache_;
50 // Policy level this provider will handle.
51 CloudPolicyCacheBase::PolicyLevel level_;
52
53 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider);
54 };
55
56 CloudPolicyCacheBase::CloudPolicyCacheBase()
57 : initialization_complete_(false),
58 is_unmanaged_(false) {
59 managed_policy_provider_.reset(
60 new CloudPolicyProvider(
61 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
62 this,
63 POLICY_LEVEL_MANDATORY));
64 recommended_policy_provider_.reset(
65 new CloudPolicyProvider(
66 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
67 this,
68 POLICY_LEVEL_RECOMMENDED));
69 }
70
71 CloudPolicyCacheBase::~CloudPolicyCacheBase() {
72 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
73 observer_list_, OnProviderGoingAway());
74 }
75
76 bool CloudPolicyCacheBase::SetPolicyInternal(
77 const em::PolicyFetchResponse& policy) {
78 DCHECK(CalledOnValidThread());
79 bool initialization_was_not_complete = !initialization_complete_;
80 is_unmanaged_ = false;
81 base::Time timestamp;
82 PolicyMap mandatory_policy;
83 PolicyMap recommended_policy;
84 bool ok = DecodePolicyResponse(policy, &mandatory_policy, &recommended_policy,
85 &timestamp);
86 if (!ok)
87 return false;
88
89 const bool new_policy_differs =
90 !mandatory_policy_.Equals(mandatory_policy) ||
91 !recommended_policy_.Equals(recommended_policy);
92 mandatory_policy_.Swap(&mandatory_policy);
93 recommended_policy_.Swap(&recommended_policy);
94 initialization_complete_ = true;
95 last_policy_refresh_time_ = timestamp;
Mattias Nissler (ping if slow) 2011/03/24 18:55:57 This does have the same bogus-timestamp bug we've
Jakob Kummerow 2011/03/28 13:53:53 In this patch set: yes; it's already fixed in my l
96
97 if (new_policy_differs || initialization_was_not_complete) {
98 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
99 observer_list_, OnUpdatePolicy());
100 }
101 return true;
102 }
103
104 ConfigurationPolicyProvider* CloudPolicyCacheBase::GetManagedPolicyProvider() {
105 DCHECK(CalledOnValidThread());
106 return managed_policy_provider_.get();
107 }
108
109 ConfigurationPolicyProvider*
110 CloudPolicyCacheBase::GetRecommendedPolicyProvider() {
111 DCHECK(CalledOnValidThread());
112 return recommended_policy_provider_.get();
113 }
114
115 bool CloudPolicyCacheBase::DecodePolicyResponse(
116 const em::PolicyFetchResponse& policy_response,
117 PolicyMap* mandatory,
118 PolicyMap* recommended,
119 base::Time* timestamp) {
120 std::string data = policy_response.policy_data();
121 em::PolicyData policy_data;
122 if (!policy_data.ParseFromString(data)) {
123 LOG(WARNING) << "Failed to parse PolicyData protobuf.";
124 return false;
125 }
126 *timestamp = base::Time::UnixEpoch() +
127 base::TimeDelta::FromMilliseconds(policy_data.timestamp());
128 return DecodePolicyData(policy_data, mandatory, recommended);
129 }
130
131 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698