OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/policy/cloud/cloud_policy_store.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "chrome/browser/policy/cloud/cloud_external_data_manager.h" | |
9 | |
10 namespace policy { | |
11 | |
12 CloudPolicyStore::Observer::~Observer() {} | |
13 | |
14 CloudPolicyStore::CloudPolicyStore() | |
15 : status_(STATUS_OK), | |
16 validation_status_(CloudPolicyValidatorBase::VALIDATION_OK), | |
17 invalidation_version_(0), | |
18 is_initialized_(false) {} | |
19 | |
20 CloudPolicyStore::~CloudPolicyStore() { | |
21 DCHECK(!external_data_manager_); | |
22 } | |
23 | |
24 void CloudPolicyStore::Store( | |
25 const enterprise_management::PolicyFetchResponse& policy, | |
26 int64 invalidation_version) { | |
27 invalidation_version_ = invalidation_version; | |
28 Store(policy); | |
29 } | |
30 | |
31 void CloudPolicyStore::AddObserver(CloudPolicyStore::Observer* observer) { | |
32 observers_.AddObserver(observer); | |
33 } | |
34 | |
35 void CloudPolicyStore::RemoveObserver(CloudPolicyStore::Observer* observer) { | |
36 observers_.RemoveObserver(observer); | |
37 } | |
38 | |
39 void CloudPolicyStore::NotifyStoreLoaded() { | |
40 is_initialized_ = true; | |
41 // The |external_data_manager_| must be notified first so that when other | |
42 // observers are informed about the changed policies and try to fetch external | |
43 // data referenced by these, the |external_data_manager_| has the required | |
44 // metadata already. | |
45 if (external_data_manager_) | |
46 external_data_manager_->OnPolicyStoreLoaded(); | |
47 FOR_EACH_OBSERVER(Observer, observers_, OnStoreLoaded(this)); | |
48 } | |
49 | |
50 void CloudPolicyStore::NotifyStoreError() { | |
51 is_initialized_ = true; | |
52 FOR_EACH_OBSERVER(Observer, observers_, OnStoreError(this)); | |
53 } | |
54 | |
55 void CloudPolicyStore::SetExternalDataManager( | |
56 base::WeakPtr<CloudExternalDataManager> external_data_manager) { | |
57 DCHECK(!external_data_manager_); | |
58 external_data_manager_ = external_data_manager; | |
59 if (is_initialized_) | |
60 external_data_manager_->OnPolicyStoreLoaded(); | |
61 } | |
62 | |
63 void CloudPolicyStore::SetPolicyMapForTesting(const PolicyMap& policy_map) { | |
64 policy_map_.CopyFrom(policy_map); | |
65 NotifyStoreLoaded(); | |
66 } | |
67 | |
68 } // namespace policy | |
OLD | NEW |