blob: 9b993345ab80f386d5934c2e72a7b06843acd304 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/policy/policy_notifier.h"
namespace policy {
void PolicyNotifier::AddObserver(CloudPolicySubsystem::Observer* observer) {
observer_list_.AddObserver(observer);
}
void PolicyNotifier::RemoveObserver(CloudPolicySubsystem::Observer* observer) {
observer_list_.RemoveObserver(observer);
}
PolicyNotifier::PolicyNotifier()
: state_(CloudPolicySubsystem::UNENROLLED),
error_details_(CloudPolicySubsystem::NO_DETAILS) {
for (int i = 0; i < NUM_SOURCES; ++i) {
component_states_[i] = CloudPolicySubsystem::UNENROLLED;
component_error_details_[i] = CloudPolicySubsystem::NO_DETAILS;
}
}
PolicyNotifier::~PolicyNotifier() {
}
void PolicyNotifier::Inform(PolicySubsystemState state,
ErrorDetails error_details,
StatusSource source) {
component_states_[source] = state;
component_error_details_[source] = error_details;
RecomputeState();
}
void PolicyNotifier::RecomputeState() {
// Define shortcuts.
PolicySubsystemState* s = component_states_;
ErrorDetails* e = component_error_details_;
// Compute overall state. General idea: If any component knows we're
// unmanaged, set that as global state. Otherwise, ask components in the
// order they normally do work in. If anyone reports 'SUCCESS' or 'UNENROLLED'
// (which can also be read as 'undefined/unknown', ask the next component.
if (s[TOKEN_FETCHER] == CloudPolicySubsystem::UNMANAGED ||
s[POLICY_CONTROLLER] == CloudPolicySubsystem::UNMANAGED ||
s[POLICY_CACHE] == CloudPolicySubsystem::UNMANAGED) {
state_ = CloudPolicySubsystem::UNMANAGED;
error_details_ = CloudPolicySubsystem::NO_DETAILS;
} else if (s[TOKEN_FETCHER] == CloudPolicySubsystem::NETWORK_ERROR) {
state_ = s[TOKEN_FETCHER];
error_details_ = e[TOKEN_FETCHER];
} else if (s[TOKEN_FETCHER] == CloudPolicySubsystem::BAD_GAIA_TOKEN) {
state_ = s[TOKEN_FETCHER];
error_details_ = e[TOKEN_FETCHER];
} else if (s[POLICY_CONTROLLER] == CloudPolicySubsystem::NETWORK_ERROR) {
state_ = s[POLICY_CONTROLLER];
error_details_ = e[POLICY_CONTROLLER];
} else {
state_ = s[POLICY_CACHE];
error_details_ = e[POLICY_CACHE];
}
FOR_EACH_OBSERVER(CloudPolicySubsystem::Observer, observer_list_,
OnPolicyStateChanged(state_, error_details_));
}
} // namespace policy
|