OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/policy/cloud/cloud_policy_store.h" | 5 #include "chrome/browser/policy/cloud/cloud_policy_store.h" |
6 | 6 |
7 #include "base/hash.h" | |
8 | |
7 namespace policy { | 9 namespace policy { |
8 | 10 |
9 CloudPolicyStore::Observer::~Observer() {} | 11 CloudPolicyStore::Observer::~Observer() {} |
10 | 12 |
11 CloudPolicyStore::CloudPolicyStore() | 13 CloudPolicyStore::CloudPolicyStore() |
12 : status_(STATUS_OK), | 14 : status_(STATUS_OK), |
13 validation_status_(CloudPolicyValidatorBase::VALIDATION_OK), | 15 validation_status_(CloudPolicyValidatorBase::VALIDATION_OK), |
14 is_initialized_(false) {} | 16 invalidation_version_(0), |
17 is_initialized_(false), | |
18 policy_changed_(false), | |
19 hash_value_(0) {} | |
15 | 20 |
16 CloudPolicyStore::~CloudPolicyStore() {} | 21 CloudPolicyStore::~CloudPolicyStore() {} |
17 | 22 |
23 void CloudPolicyStore::Store( | |
24 const enterprise_management::PolicyFetchResponse& policy, | |
25 int64 invalidation_version) { | |
26 invalidation_version_ = invalidation_version; | |
27 Store(policy); | |
28 } | |
29 | |
18 void CloudPolicyStore::AddObserver(CloudPolicyStore::Observer* observer) { | 30 void CloudPolicyStore::AddObserver(CloudPolicyStore::Observer* observer) { |
19 observers_.AddObserver(observer); | 31 observers_.AddObserver(observer); |
20 } | 32 } |
21 | 33 |
22 void CloudPolicyStore::RemoveObserver(CloudPolicyStore::Observer* observer) { | 34 void CloudPolicyStore::RemoveObserver(CloudPolicyStore::Observer* observer) { |
23 observers_.RemoveObserver(observer); | 35 observers_.RemoveObserver(observer); |
24 } | 36 } |
25 | 37 |
26 void CloudPolicyStore::NotifyStoreLoaded() { | 38 void CloudPolicyStore::NotifyStoreLoaded() { |
39 // Determine if the policy changed by comparing the new policy's hash value | |
40 // to the previous. | |
41 uint32 new_hash_value = 0; | |
42 if (policy_.get() && policy_->has_policy_value()) | |
Joao da Silva
2013/07/24 15:34:07
.get() is not needed to test the policy_ scoped_pt
Steve Condie
2013/07/25 01:18:08
Done.
| |
43 new_hash_value = base::Hash(policy_->policy_value()); | |
Joao da Silva
2013/07/24 15:34:07
Note that base::Hash does a single pass over the s
| |
44 policy_changed_ = new_hash_value != hash_value_; | |
45 hash_value_ = new_hash_value; | |
46 | |
27 is_initialized_ = true; | 47 is_initialized_ = true; |
28 FOR_EACH_OBSERVER(Observer, observers_, OnStoreLoaded(this)); | 48 FOR_EACH_OBSERVER(Observer, observers_, OnStoreLoaded(this)); |
29 } | 49 } |
30 | 50 |
31 void CloudPolicyStore::NotifyStoreError() { | 51 void CloudPolicyStore::NotifyStoreError() { |
32 is_initialized_ = true; | 52 is_initialized_ = true; |
33 FOR_EACH_OBSERVER(Observer, observers_, OnStoreError(this)); | 53 FOR_EACH_OBSERVER(Observer, observers_, OnStoreError(this)); |
34 } | 54 } |
35 | 55 |
36 } // namespace | 56 } // namespace policy |
OLD | NEW |