| 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/policy_notifier.h" | |
| 6 | |
| 7 namespace policy { | |
| 8 | |
| 9 void PolicyNotifier::AddObserver(CloudPolicySubsystem::Observer* observer) { | |
| 10 observer_list_.AddObserver(observer); | |
| 11 } | |
| 12 | |
| 13 void PolicyNotifier::RemoveObserver(CloudPolicySubsystem::Observer* observer) { | |
| 14 observer_list_.RemoveObserver(observer); | |
| 15 } | |
| 16 | |
| 17 PolicyNotifier::PolicyNotifier() | |
| 18 : state_(CloudPolicySubsystem::UNENROLLED), | |
| 19 error_details_(CloudPolicySubsystem::NO_DETAILS) { | |
| 20 for (int i = 0; i < NUM_SOURCES; ++i) { | |
| 21 component_states_[i] = CloudPolicySubsystem::UNENROLLED; | |
| 22 component_error_details_[i] = CloudPolicySubsystem::NO_DETAILS; | |
| 23 } | |
| 24 } | |
| 25 | |
| 26 PolicyNotifier::~PolicyNotifier() { | |
| 27 } | |
| 28 | |
| 29 void PolicyNotifier::Inform(PolicySubsystemState state, | |
| 30 ErrorDetails error_details, | |
| 31 StatusSource source) { | |
| 32 component_states_[source] = state; | |
| 33 component_error_details_[source] = error_details; | |
| 34 RecomputeState(); | |
| 35 } | |
| 36 | |
| 37 void PolicyNotifier::RecomputeState() { | |
| 38 // Define shortcuts. | |
| 39 PolicySubsystemState* s = component_states_; | |
| 40 ErrorDetails* e = component_error_details_; | |
| 41 | |
| 42 // Compute overall state. General idea: If any component knows we're | |
| 43 // unmanaged, set that as global state. Otherwise, ask components in the | |
| 44 // order they normally do work in. If anyone reports 'SUCCESS' or 'UNENROLLED' | |
| 45 // (which can also be read as 'undefined/unknown', ask the next component. | |
| 46 if (s[TOKEN_FETCHER] == CloudPolicySubsystem::UNMANAGED || | |
| 47 s[POLICY_CONTROLLER] == CloudPolicySubsystem::UNMANAGED || | |
| 48 s[POLICY_CACHE] == CloudPolicySubsystem::UNMANAGED) { | |
| 49 state_ = CloudPolicySubsystem::UNMANAGED; | |
| 50 error_details_ = CloudPolicySubsystem::NO_DETAILS; | |
| 51 } else if (s[TOKEN_FETCHER] == CloudPolicySubsystem::UNENROLLED && | |
| 52 (e[TOKEN_FETCHER] == CloudPolicySubsystem::BAD_SERIAL_NUMBER || | |
| 53 e[TOKEN_FETCHER] == CloudPolicySubsystem::BAD_ENROLLMENT_MODE || | |
| 54 e[TOKEN_FETCHER] == CloudPolicySubsystem::MISSING_LICENSES)) { | |
| 55 state_ = s[TOKEN_FETCHER]; | |
| 56 error_details_ = e[TOKEN_FETCHER]; | |
| 57 } else if (s[TOKEN_FETCHER] == CloudPolicySubsystem::NETWORK_ERROR) { | |
| 58 state_ = s[TOKEN_FETCHER]; | |
| 59 error_details_ = e[TOKEN_FETCHER]; | |
| 60 } else if (s[TOKEN_FETCHER] == CloudPolicySubsystem::BAD_GAIA_TOKEN) { | |
| 61 state_ = s[TOKEN_FETCHER]; | |
| 62 error_details_ = e[TOKEN_FETCHER]; | |
| 63 } else if (s[POLICY_CONTROLLER] == CloudPolicySubsystem::NETWORK_ERROR) { | |
| 64 state_ = s[POLICY_CONTROLLER]; | |
| 65 error_details_ = e[POLICY_CONTROLLER]; | |
| 66 } else if (s[TOKEN_FETCHER] == CloudPolicySubsystem::SUCCESS && | |
| 67 s[POLICY_CONTROLLER] != CloudPolicySubsystem::SUCCESS) { | |
| 68 // We need to be able to differentiate between token fetch success or | |
| 69 // policy fetch success. | |
| 70 state_ = CloudPolicySubsystem::TOKEN_FETCHED; | |
| 71 error_details_ = CloudPolicySubsystem::NO_DETAILS; | |
| 72 } else { | |
| 73 state_ = s[POLICY_CACHE]; | |
| 74 error_details_ = e[POLICY_CACHE]; | |
| 75 } | |
| 76 | |
| 77 FOR_EACH_OBSERVER(CloudPolicySubsystem::Observer, observer_list_, | |
| 78 OnPolicyStateChanged(state_, error_details_)); | |
| 79 } | |
| 80 | |
| 81 } // namespace policy | |
| OLD | NEW |