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" | 7 #include "base/hash.h" |
| 8 #include "base/logging.h" |
| 9 #include "chrome/browser/policy/cloud/cloud_external_data_manager.h" |
8 | 10 |
9 namespace policy { | 11 namespace policy { |
10 | 12 |
11 CloudPolicyStore::Observer::~Observer() {} | 13 CloudPolicyStore::Observer::~Observer() {} |
12 | 14 |
13 CloudPolicyStore::CloudPolicyStore() | 15 CloudPolicyStore::CloudPolicyStore() |
14 : status_(STATUS_OK), | 16 : status_(STATUS_OK), |
15 validation_status_(CloudPolicyValidatorBase::VALIDATION_OK), | 17 validation_status_(CloudPolicyValidatorBase::VALIDATION_OK), |
16 invalidation_version_(0), | 18 invalidation_version_(0), |
17 is_initialized_(false), | 19 is_initialized_(false), |
(...skipping 20 matching lines...) Expand all Loading... |
38 void CloudPolicyStore::NotifyStoreLoaded() { | 40 void CloudPolicyStore::NotifyStoreLoaded() { |
39 // Determine if the policy changed by comparing the new policy's hash value | 41 // Determine if the policy changed by comparing the new policy's hash value |
40 // to the previous. | 42 // to the previous. |
41 uint32 new_hash_value = 0; | 43 uint32 new_hash_value = 0; |
42 if (policy_ && policy_->has_policy_value()) | 44 if (policy_ && policy_->has_policy_value()) |
43 new_hash_value = base::Hash(policy_->policy_value()); | 45 new_hash_value = base::Hash(policy_->policy_value()); |
44 policy_changed_ = new_hash_value != hash_value_; | 46 policy_changed_ = new_hash_value != hash_value_; |
45 hash_value_ = new_hash_value; | 47 hash_value_ = new_hash_value; |
46 | 48 |
47 is_initialized_ = true; | 49 is_initialized_ = true; |
| 50 // The |external_data_manager_| must be notified first so that when other |
| 51 // observers are informed about the changed policies and try to fetch external |
| 52 // data referenced by these, the |external_data_manager_| has the required |
| 53 // metadata already. |
| 54 if (external_data_manager_) |
| 55 external_data_manager_->OnPolicyStoreLoaded(); |
48 FOR_EACH_OBSERVER(Observer, observers_, OnStoreLoaded(this)); | 56 FOR_EACH_OBSERVER(Observer, observers_, OnStoreLoaded(this)); |
49 } | 57 } |
50 | 58 |
51 void CloudPolicyStore::NotifyStoreError() { | 59 void CloudPolicyStore::NotifyStoreError() { |
52 is_initialized_ = true; | 60 is_initialized_ = true; |
53 FOR_EACH_OBSERVER(Observer, observers_, OnStoreError(this)); | 61 FOR_EACH_OBSERVER(Observer, observers_, OnStoreError(this)); |
54 } | 62 } |
55 | 63 |
| 64 void CloudPolicyStore::SetExternalDataManager( |
| 65 base::WeakPtr<CloudExternalDataManager> external_data_manager) { |
| 66 DCHECK(!external_data_manager_); |
| 67 external_data_manager_ = external_data_manager; |
| 68 if (is_initialized_) |
| 69 external_data_manager_->OnPolicyStoreLoaded(); |
| 70 } |
| 71 |
56 } // namespace policy | 72 } // namespace policy |
OLD | NEW |