OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ |
6 #define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ | 6 #define CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "base/weak_ptr.h" | 13 #include "base/weak_ptr.h" |
14 #include "chrome/browser/policy/configuration_policy_provider.h" | 14 #include "chrome/browser/policy/configuration_policy_provider.h" |
15 #include "chrome/browser/policy/device_management_backend.h" | 15 #include "chrome/browser/policy/device_management_backend.h" |
16 #include "chrome/common/notification_details.h" | 16 #include "chrome/common/notification_details.h" |
17 #include "chrome/common/notification_observer.h" | 17 #include "chrome/common/notification_observer.h" |
18 #include "chrome/common/notification_registrar.h" | 18 #include "chrome/common/notification_registrar.h" |
19 #include "chrome/common/notification_source.h" | 19 #include "chrome/common/notification_source.h" |
20 | 20 |
| 21 class TokenService; |
| 22 |
21 namespace policy { | 23 namespace policy { |
22 | 24 |
23 class DeviceManagementBackend; | 25 class DeviceManagementBackend; |
24 class DeviceManagementPolicyCache; | 26 class DeviceManagementPolicyCache; |
25 class DeviceTokenFetcher; | 27 class DeviceTokenFetcher; |
26 | 28 |
27 // Provides policy fetched from the device management server. With the exception | 29 // Provides policy fetched from the device management server. With the exception |
28 // of the Provide method, which can be called on the FILE thread, all public | 30 // of the Provide method, which can be called on the FILE thread, all public |
29 // methods must be called on the UI thread. | 31 // methods must be called on the UI thread. |
30 class DeviceManagementPolicyProvider | 32 class DeviceManagementPolicyProvider |
31 : public ConfigurationPolicyProvider, | 33 : public ConfigurationPolicyProvider, |
32 public NotificationObserver, | 34 public NotificationObserver, |
33 public DeviceManagementBackend::DevicePolicyResponseDelegate, | 35 public DeviceManagementBackend::DevicePolicyResponseDelegate, |
34 public base::SupportsWeakPtr<DeviceManagementPolicyProvider> { | 36 public base::SupportsWeakPtr<DeviceManagementPolicyProvider> { |
35 public: | 37 public: |
36 explicit DeviceManagementPolicyProvider( | 38 DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list, |
37 const PolicyDefinitionList* policy_list); | 39 DeviceManagementBackend* backend, |
| 40 TokenService* token_service, |
| 41 const FilePath& storage_dir); |
| 42 |
38 virtual ~DeviceManagementPolicyProvider(); | 43 virtual ~DeviceManagementPolicyProvider(); |
39 | 44 |
40 // ConfigurationPolicyProvider implementation: | 45 // ConfigurationPolicyProvider implementation: |
41 virtual bool Provide(ConfigurationPolicyStoreInterface* store); | 46 virtual bool Provide(ConfigurationPolicyStoreInterface* store); |
42 | 47 |
43 // NotificationObserver implementation: | 48 // NotificationObserver implementation: |
44 virtual void Observe(NotificationType type, | 49 virtual void Observe(NotificationType type, |
45 const NotificationSource& source, | 50 const NotificationSource& source, |
46 const NotificationDetails& details); | 51 const NotificationDetails& details); |
47 | 52 |
48 // DevicePolicyResponseDelegate implementation: | 53 // DevicePolicyResponseDelegate implementation: |
49 virtual void HandlePolicyResponse( | 54 virtual void HandlePolicyResponse( |
50 const em::DevicePolicyResponse& response); | 55 const em::DevicePolicyResponse& response); |
51 virtual void OnError(DeviceManagementBackend::ErrorCode code); | 56 virtual void OnError(DeviceManagementBackend::ErrorCode code); |
52 | 57 |
53 // True if a policy request has been sent to the device management backend | 58 // True if a policy request has been sent to the device management backend |
54 // server and no response or error has yet been received. | 59 // server and no response or error has yet been received. |
55 bool IsPolicyRequestPending() const { return policy_request_pending_; } | 60 bool IsPolicyRequestPending() const { return policy_request_pending_; } |
56 | 61 |
57 protected: | 62 // Tells the provider that the passed in token service reference is about to |
58 friend class DeviceManagementPolicyProviderTest; | 63 // become invalid. |
59 | 64 void Shutdown(); |
60 // Called only by unit tests, this constructor allows the caller to specify in | |
61 // |backend| the device management backend to which policy requests are | |
62 // sent. The provider takes over ownership of |backend|. The directory | |
63 // specified in |storage_dir| is used to store the device token and persisted | |
64 // policy, rather than the user's data directory. | |
65 DeviceManagementPolicyProvider( | |
66 const PolicyDefinitionList* policy_list, | |
67 DeviceManagementBackend* backend, | |
68 const FilePath& storage_dir); | |
69 | 65 |
70 private: | 66 private: |
71 class InitializeAfterIOThreadExistsTask; | 67 class InitializeAfterIOThreadExistsTask; |
72 | 68 |
73 // Returns the device management backend to use for backend requests, lazily | 69 // Returns the device management backend to use for backend requests, lazily |
74 // creating a new one if one doesn't already exist. | 70 // creating a new one if one doesn't already exist. |
75 DeviceManagementBackend* GetBackend(); | 71 DeviceManagementBackend* GetBackend(); |
76 | 72 |
77 // Called by constructors to perform shared initialization. Initialization | 73 // Called by constructors to perform shared initialization. Initialization |
78 // requiring the IOThread must not be performed directly in this method, | 74 // requiring the IOThread must not be performed directly in this method, |
(...skipping 16 matching lines...) Expand all Loading... |
95 // Provides the URL at which requests are sent to from the device management | 91 // Provides the URL at which requests are sent to from the device management |
96 // backend. | 92 // backend. |
97 static std::string GetDeviceManagementURL(); | 93 static std::string GetDeviceManagementURL(); |
98 | 94 |
99 // Returns the path to the sub-directory in the user data directory | 95 // Returns the path to the sub-directory in the user data directory |
100 // in which device management persistent state is stored. | 96 // in which device management persistent state is stored. |
101 static FilePath GetOrCreateDeviceManagementDir( | 97 static FilePath GetOrCreateDeviceManagementDir( |
102 const FilePath& user_data_dir); | 98 const FilePath& user_data_dir); |
103 | 99 |
104 scoped_ptr<DeviceManagementBackend> backend_; | 100 scoped_ptr<DeviceManagementBackend> backend_; |
| 101 TokenService* token_service_; // weak |
105 scoped_ptr<DeviceManagementPolicyCache> cache_; | 102 scoped_ptr<DeviceManagementPolicyCache> cache_; |
106 scoped_refptr<DeviceTokenFetcher> token_fetcher_; | 103 scoped_refptr<DeviceTokenFetcher> token_fetcher_; |
107 NotificationRegistrar registrar_; | 104 NotificationRegistrar registrar_; |
108 FilePath storage_dir_; | 105 FilePath storage_dir_; |
109 bool policy_request_pending_; | 106 bool policy_request_pending_; |
110 | 107 |
111 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); | 108 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); |
112 }; | 109 }; |
113 | 110 |
114 } // namespace policy | 111 } // namespace policy |
115 | 112 |
116 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ | 113 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ |
OLD | NEW |