OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_ | 5 #ifndef CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_ |
6 #define CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_ | 6 #define CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/task.h" | 13 #include "base/task.h" |
14 #include "chrome/browser/policy/enterprise_install_attributes.h" | 14 #include "chrome/browser/policy/enterprise_install_attributes.h" |
| 15 #include "content/common/notification_observer.h" |
| 16 #include "content/common/notification_registrar.h" |
15 | 17 |
16 class PrefService; | 18 class FilePath; |
17 class TestingBrowserProcess; | 19 class TestingBrowserProcess; |
18 class TokenService; | 20 class TokenService; |
19 | 21 |
20 namespace net { | |
21 class URLRequestContextGetter; | |
22 } | |
23 | |
24 namespace policy { | 22 namespace policy { |
25 | 23 |
| 24 class CloudPolicyProvider; |
26 class CloudPolicySubsystem; | 25 class CloudPolicySubsystem; |
27 class ConfigurationPolicyProvider; | 26 class ConfigurationPolicyProvider; |
| 27 class UserPolicyIdentityStrategy; |
| 28 |
| 29 #if defined(OS_CHROMEOS) |
28 class DevicePolicyIdentityStrategy; | 30 class DevicePolicyIdentityStrategy; |
| 31 #endif |
29 | 32 |
30 // Manages the lifecycle of browser-global policy infrastructure, such as the | 33 // Manages the lifecycle of browser-global policy infrastructure, such as the |
31 // platform policy providers. | 34 // platform policy providers, device- and the user-cloud policy infrastructure. |
32 class BrowserPolicyConnector { | 35 // TODO(gfeher,mnissler): Factor out device and user specific methods into their |
| 36 // respective classes. |
| 37 class BrowserPolicyConnector : public NotificationObserver { |
33 public: | 38 public: |
34 static BrowserPolicyConnector* Create(); | 39 static BrowserPolicyConnector* Create(); |
35 ~BrowserPolicyConnector(); | 40 virtual ~BrowserPolicyConnector(); |
36 | 41 |
37 ConfigurationPolicyProvider* GetManagedPlatformProvider() const; | 42 ConfigurationPolicyProvider* GetManagedPlatformProvider() const; |
38 ConfigurationPolicyProvider* GetManagedCloudProvider() const; | 43 ConfigurationPolicyProvider* GetManagedCloudProvider() const; |
39 ConfigurationPolicyProvider* GetRecommendedPlatformProvider() const; | 44 ConfigurationPolicyProvider* GetRecommendedPlatformProvider() const; |
40 ConfigurationPolicyProvider* GetRecommendedCloudProvider() const; | 45 ConfigurationPolicyProvider* GetRecommendedCloudProvider() const; |
41 | 46 |
42 // Returns a weak pointer to the CloudPolicySubsystem managed by this | 47 // Returns a weak pointer to the CloudPolicySubsystem corresponding to the |
43 // policy connector, or NULL if no such subsystem exists (i.e. when running | 48 // device policy managed by this policy connector, or NULL if no such |
44 // outside ChromeOS). | 49 // subsystem exists (i.e. when running outside ChromeOS). |
45 CloudPolicySubsystem* cloud_policy_subsystem() { | 50 CloudPolicySubsystem* device_cloud_policy_subsystem() { |
46 return cloud_policy_subsystem_.get(); | 51 #if defined(OS_CHROMEOS) |
| 52 return device_cloud_policy_subsystem_.get(); |
| 53 #else |
| 54 return NULL; |
| 55 #endif |
| 56 } |
| 57 |
| 58 // Returns a weak pointer to the CloudPolicySubsystem corresponding to the |
| 59 // user policy managed by this policy connector, or NULL if no such |
| 60 // subsystem exists (i.e. when user cloud policy is not active due to |
| 61 // unmanaged or not logged in). |
| 62 CloudPolicySubsystem* user_cloud_policy_subsystem() { |
| 63 return user_cloud_policy_subsystem_.get(); |
47 } | 64 } |
48 | 65 |
49 // Used to set the credentials stored in the identity strategy associated | 66 // Used to set the credentials stored in the identity strategy associated |
50 // with this policy connector. | 67 // with this policy connector. |
51 void SetCredentials(const std::string& owner_email, | 68 void SetDeviceCredentials(const std::string& owner_email, |
52 const std::string& gaia_token); | 69 const std::string& gaia_token); |
53 | 70 |
54 // Returns true if this device is managed by an enterprise (as opposed to | 71 // Returns true if this device is managed by an enterprise (as opposed to |
55 // a local owner). | 72 // a local owner). |
56 bool IsEnterpriseManaged(); | 73 bool IsEnterpriseManaged(); |
57 | 74 |
58 // Locks the device to an enterprise domain. | 75 // Locks the device to an enterprise domain. |
59 EnterpriseInstallAttributes::LockResult LockDevice(const std::string& user); | 76 EnterpriseInstallAttributes::LockResult LockDevice(const std::string& user); |
60 | 77 |
61 // Returns the enterprise domain if device is managed. | 78 // Returns the enterprise domain if device is managed. |
62 std::string GetEnterpriseDomain(); | 79 std::string GetEnterpriseDomain(); |
63 | 80 |
64 // Exposes the StopAutoRetry() method of the CloudPolicySubsystem managed | 81 // Exposes the StopAutoRetry() method of the CloudPolicySubsystem managed |
65 // by this connector, which can be used to disable automatic | 82 // by this connector, which can be used to disable automatic |
66 // retrying behavior. | 83 // retrying behavior. |
67 void StopAutoRetry(); | 84 void DeviceStopAutoRetry(); |
68 | 85 |
69 // Initiates a policy fetch after a successful device registration. | 86 // Initiates a policy fetch after a successful device registration. |
70 void FetchPolicy(); | 87 void FetchDevicePolicy(); |
71 | 88 |
72 // Schedules initialization of the policy backend service, if the service is | 89 // Schedules initialization of the cloud policy backend services, if the |
73 // already constructed. | 90 // services are already constructed. |
74 void ScheduleServiceInitialization(int64 delay_milliseconds); | 91 void ScheduleServiceInitialization(int64 delay_milliseconds); |
75 | 92 |
| 93 // Initializes the user cloud policy infrasturcture. |
| 94 // TODO(sfeuz): Listen to log-out or going-away messages of TokenService and |
| 95 // reset the backend at that point. |
| 96 void InitializeUserPolicy(const std::string& user_name, |
| 97 const FilePath& policy_dir, |
| 98 TokenService* token_service); |
| 99 |
76 private: | 100 private: |
77 friend class ::TestingBrowserProcess; | 101 friend class ::TestingBrowserProcess; |
78 | 102 |
79 BrowserPolicyConnector(); | 103 BrowserPolicyConnector(); |
80 | 104 |
81 static BrowserPolicyConnector* CreateForTests(); | 105 static BrowserPolicyConnector* CreateForTests(); |
82 static ConfigurationPolicyProvider* CreateManagedPlatformProvider(); | 106 static ConfigurationPolicyProvider* CreateManagedPlatformProvider(); |
83 static ConfigurationPolicyProvider* CreateRecommendedPlatformProvider(); | 107 static ConfigurationPolicyProvider* CreateRecommendedPlatformProvider(); |
84 | 108 |
85 // Constructor for tests that allows tests to use fake platform policy | 109 // Constructor for tests that allows tests to use fake platform and cloud |
86 // providers instead of using the actual ones. | 110 // policy providers instead of using the actual ones. |
87 BrowserPolicyConnector( | 111 BrowserPolicyConnector( |
88 ConfigurationPolicyProvider* managed_platform_provider, | 112 ConfigurationPolicyProvider* managed_platform_provider, |
89 ConfigurationPolicyProvider* recommended_platform_provider); | 113 ConfigurationPolicyProvider* recommended_platform_provider, |
| 114 CloudPolicyProvider* managed_cloud_provider, |
| 115 CloudPolicyProvider* recommended_cloud_provider); |
90 | 116 |
91 // Activates the cloud policy subsystem. | 117 // NotificationObserver method overrides: |
92 void Initialize(); | 118 virtual void Observe(NotificationType type, |
| 119 const NotificationSource& source, |
| 120 const NotificationDetails& details) OVERRIDE; |
| 121 |
| 122 // Initializes the device cloud policy infrasturcture. |
| 123 void InitializeDevicePolicy(); |
| 124 |
| 125 // Activates the device cloud policy subsystem. This will be posted as a task |
| 126 // from InitializeDevicePolicy since it needs to wait for the message loops to |
| 127 // be running. |
| 128 void InitializeDevicePolicySubsystem(); |
93 | 129 |
94 scoped_ptr<ConfigurationPolicyProvider> managed_platform_provider_; | 130 scoped_ptr<ConfigurationPolicyProvider> managed_platform_provider_; |
95 scoped_ptr<ConfigurationPolicyProvider> recommended_platform_provider_; | 131 scoped_ptr<ConfigurationPolicyProvider> recommended_platform_provider_; |
96 | 132 |
| 133 scoped_ptr<CloudPolicyProvider> managed_cloud_provider_; |
| 134 scoped_ptr<CloudPolicyProvider> recommended_cloud_provider_; |
| 135 |
97 #if defined(OS_CHROMEOS) | 136 #if defined(OS_CHROMEOS) |
98 scoped_ptr<DevicePolicyIdentityStrategy> identity_strategy_; | 137 scoped_ptr<DevicePolicyIdentityStrategy> device_identity_strategy_; |
| 138 scoped_ptr<CloudPolicySubsystem> device_cloud_policy_subsystem_; |
99 scoped_ptr<EnterpriseInstallAttributes> install_attributes_; | 139 scoped_ptr<EnterpriseInstallAttributes> install_attributes_; |
100 #endif | 140 #endif |
101 scoped_ptr<CloudPolicySubsystem> cloud_policy_subsystem_; | 141 |
| 142 scoped_ptr<UserPolicyIdentityStrategy> user_identity_strategy_; |
| 143 scoped_ptr<CloudPolicySubsystem> user_cloud_policy_subsystem_; |
102 | 144 |
103 ScopedRunnableMethodFactory<BrowserPolicyConnector> method_factory_; | 145 ScopedRunnableMethodFactory<BrowserPolicyConnector> method_factory_; |
104 | 146 |
| 147 // Registers the provider for notification of successful Gaia logins. |
| 148 NotificationRegistrar registrar_; |
| 149 |
| 150 // Weak reference to the TokenService we are listening to for user cloud |
| 151 // policy authentication tokens. |
| 152 TokenService* token_service_; |
| 153 |
105 DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnector); | 154 DISALLOW_COPY_AND_ASSIGN(BrowserPolicyConnector); |
106 }; | 155 }; |
107 | 156 |
108 } // namespace policy | 157 } // namespace policy |
109 | 158 |
110 #endif // CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_ | 159 #endif // CHROME_BROWSER_POLICY_BROWSER_POLICY_CONNECTOR_H_ |
OLD | NEW |