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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
// 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.
#ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_SUBSYSTEM_H_
#define CHROME_BROWSER_POLICY_CLOUD_POLICY_SUBSYSTEM_H_
#pragma once
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/prefs/pref_member.h"
#include "content/common/notification_observer.h"
#include "net/base/network_change_notifier.h"
class PrefService;
namespace net {
class URLRequestContextGetter;
}
namespace policy {
class CloudPolicyCacheBase;
class CloudPolicyController;
class CloudPolicyIdentityStrategy;
class ConfigurationPolicyProvider;
class DeviceManagementService;
class DeviceTokenFetcher;
class PolicyNotifier;
// This class is a container for the infrastructure required to support cloud
// policy. It glues together the backend, the policy controller and manages the
// life cycle of the policy providers.
class CloudPolicySubsystem
: public NotificationObserver,
public net::NetworkChangeNotifier::IPAddressObserver {
public:
enum PolicySubsystemState {
UNENROLLED, // No enrollment attempt has been performed yet.
BAD_GAIA_TOKEN, // The server rejected the GAIA auth token.
UNMANAGED, // This device is unmanaged.
NETWORK_ERROR, // A network error occurred, retrying makes sense.
LOCAL_ERROR, // Retrying is futile.
SUCCESS // Policy has been fetched successfully and is in effect.
};
enum ErrorDetails {
NO_DETAILS, // No error, so no error details either.
DMTOKEN_NETWORK_ERROR, // DeviceTokenFetcher encountered a network error.
POLICY_NETWORK_ERROR, // CloudPolicyController encountered a network error.
BAD_DMTOKEN, // The server rejected the DMToken.
POLICY_LOCAL_ERROR, // The policy cache encountered a local error.
SIGNATURE_MISMATCH, // The policy cache detected a signature mismatch.
};
class Observer {
public:
virtual ~Observer() {}
virtual void OnPolicyStateChanged(PolicySubsystemState state,
ErrorDetails error_details) = 0;
};
class ObserverRegistrar {
public:
ObserverRegistrar(CloudPolicySubsystem* cloud_policy_subsystem,
CloudPolicySubsystem::Observer* observer);
~ObserverRegistrar();
private:
PolicyNotifier* policy_notifier_;
CloudPolicySubsystem::Observer* observer_;
DISALLOW_COPY_AND_ASSIGN(ObserverRegistrar);
};
CloudPolicySubsystem(CloudPolicyIdentityStrategy* identity_strategy,
CloudPolicyCacheBase* policy_cache);
virtual ~CloudPolicySubsystem();
// net::NetworkChangeNotifier::IPAddressObserver:
virtual void OnIPAddressChanged() OVERRIDE;
// Initializes the subsystem.
void Initialize(PrefService* prefs,
net::URLRequestContextGetter* request_context);
// Shuts the subsystem down. This must be called before threading and network
// infrastructure goes away.
void Shutdown();
// Returns the externally visible state and corresponding error details.
PolicySubsystemState state();
ErrorDetails error_details();
// Stops all auto-retrying error handling behavior inside the policy
// subsystem.
void StopAutoRetry();
ConfigurationPolicyProvider* GetManagedPolicyProvider();
ConfigurationPolicyProvider* GetRecommendedPolicyProvider();
// Registers cloud policy related prefs.
static void RegisterPrefs(PrefService* pref_service);
private:
// Updates the policy controller with a new refresh rate value.
void UpdatePolicyRefreshRate();
// Returns a weak pointer to this subsystem's PolicyNotifier.
PolicyNotifier* notifier() {
return notifier_.get();
}
// NotificationObserver overrides.
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);
// The pref service that controls the refresh rate.
PrefService* prefs_;
// Tracks the pref value for the policy refresh rate.
IntegerPrefMember policy_refresh_rate_;
// Cloud policy infrastructure stuff.
scoped_ptr<PolicyNotifier> notifier_;
scoped_ptr<DeviceManagementService> device_management_service_;
scoped_ptr<DeviceTokenFetcher> device_token_fetcher_;
scoped_ptr<CloudPolicyCacheBase> cloud_policy_cache_;
scoped_ptr<CloudPolicyController> cloud_policy_controller_;
DISALLOW_COPY_AND_ASSIGN(CloudPolicySubsystem);
};
} // namespace policy
#endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_SUBSYSTEM_H_
|