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 Profile; |
21 class TokenService; | 22 class TokenService; |
22 | 23 |
23 namespace policy { | 24 namespace policy { |
24 | 25 |
25 class DeviceManagementBackend; | 26 class DeviceManagementBackend; |
26 class DeviceManagementPolicyCache; | 27 class DeviceManagementPolicyCache; |
27 class DeviceTokenFetcher; | 28 class DeviceTokenFetcher; |
28 | 29 |
29 // Provides policy fetched from the device management server. With the exception | 30 // Provides policy fetched from the device management server. With the exception |
30 // of the Provide method, which can be called on the FILE thread, all public | 31 // of the Provide method, which can be called on the FILE thread, all public |
31 // methods must be called on the UI thread. | 32 // methods must be called on the UI thread. |
32 class DeviceManagementPolicyProvider | 33 class DeviceManagementPolicyProvider |
33 : public ConfigurationPolicyProvider, | 34 : public ConfigurationPolicyProvider, |
34 public NotificationObserver, | 35 public NotificationObserver, |
35 public DeviceManagementBackend::DevicePolicyResponseDelegate, | 36 public DeviceManagementBackend::DevicePolicyResponseDelegate, |
36 public base::SupportsWeakPtr<DeviceManagementPolicyProvider> { | 37 public base::SupportsWeakPtr<DeviceManagementPolicyProvider> { |
37 public: | 38 public: |
38 DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list, | 39 DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list, |
39 DeviceManagementBackend* backend, | 40 DeviceManagementBackend* backend, |
40 TokenService* token_service, | 41 Profile* profile); |
41 const FilePath& storage_dir); | |
42 | 42 |
43 virtual ~DeviceManagementPolicyProvider(); | 43 virtual ~DeviceManagementPolicyProvider(); |
44 | 44 |
45 // ConfigurationPolicyProvider implementation: | 45 // ConfigurationPolicyProvider implementation: |
46 virtual bool Provide(ConfigurationPolicyStoreInterface* store); | 46 virtual bool Provide(ConfigurationPolicyStoreInterface* store); |
47 | 47 |
48 // NotificationObserver implementation: | 48 // NotificationObserver implementation: |
49 virtual void Observe(NotificationType type, | 49 virtual void Observe(NotificationType type, |
50 const NotificationSource& source, | 50 const NotificationSource& source, |
51 const NotificationDetails& details); | 51 const NotificationDetails& details); |
52 | 52 |
53 // DevicePolicyResponseDelegate implementation: | 53 // DevicePolicyResponseDelegate implementation: |
54 virtual void HandlePolicyResponse( | 54 virtual void HandlePolicyResponse( |
55 const em::DevicePolicyResponse& response); | 55 const em::DevicePolicyResponse& response); |
56 virtual void OnError(DeviceManagementBackend::ErrorCode code); | 56 virtual void OnError(DeviceManagementBackend::ErrorCode code); |
57 | 57 |
58 // 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 |
59 // server and no response or error has yet been received. | 59 // server and no response or error has yet been received. |
60 bool IsPolicyRequestPending() const { return policy_request_pending_; } | 60 bool IsPolicyRequestPending() const { return policy_request_pending_; } |
61 | 61 |
62 // Tells the provider that the passed in token service reference is about to | 62 // Tells the provider that the passed in token service reference is about to |
63 // become invalid. | 63 // become invalid. |
64 void Shutdown(); | 64 void Shutdown(); |
65 | 65 |
66 private: | 66 private: |
| 67 friend class DeviceManagementPolicyProviderTest; |
| 68 |
67 class InitializeAfterIOThreadExistsTask; | 69 class InitializeAfterIOThreadExistsTask; |
68 | 70 |
| 71 // Used for testing only. |
| 72 DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list, |
| 73 DeviceManagementBackend* backend, |
| 74 Profile* profile, |
| 75 DeviceTokenFetcher* token_fetcher); |
| 76 |
69 // Returns the device management backend to use for backend requests, lazily | 77 // Returns the device management backend to use for backend requests, lazily |
70 // creating a new one if one doesn't already exist. | 78 // creating a new one if one doesn't already exist. |
71 DeviceManagementBackend* GetBackend(); | 79 DeviceManagementBackend* GetBackend(); |
72 | 80 |
73 // Called by constructors to perform shared initialization. Initialization | 81 // Called by constructors to perform shared initialization. Initialization |
74 // requiring the IOThread must not be performed directly in this method, | 82 // requiring the IOThread must not be performed directly in this method, |
75 // rather must be deferred until the IOThread is fully initialized. This is | 83 // rather must be deferred until the IOThread is fully initialized. This is |
76 // the case in InitializeAfterIOThreadExists. | 84 // the case in InitializeAfterIOThreadExists. |
77 void Initialize(); | 85 void Initialize(); |
78 | 86 |
(...skipping 12 matching lines...) Expand all Loading... |
91 // Provides the URL at which requests are sent to from the device management | 99 // Provides the URL at which requests are sent to from the device management |
92 // backend. | 100 // backend. |
93 static std::string GetDeviceManagementURL(); | 101 static std::string GetDeviceManagementURL(); |
94 | 102 |
95 // Returns the path to the sub-directory in the user data directory | 103 // Returns the path to the sub-directory in the user data directory |
96 // in which device management persistent state is stored. | 104 // in which device management persistent state is stored. |
97 static FilePath GetOrCreateDeviceManagementDir( | 105 static FilePath GetOrCreateDeviceManagementDir( |
98 const FilePath& user_data_dir); | 106 const FilePath& user_data_dir); |
99 | 107 |
100 scoped_ptr<DeviceManagementBackend> backend_; | 108 scoped_ptr<DeviceManagementBackend> backend_; |
101 TokenService* token_service_; // weak | 109 Profile* profile_; // weak |
102 scoped_ptr<DeviceManagementPolicyCache> cache_; | 110 scoped_ptr<DeviceManagementPolicyCache> cache_; |
103 scoped_refptr<DeviceTokenFetcher> token_fetcher_; | 111 scoped_refptr<DeviceTokenFetcher> token_fetcher_; |
104 NotificationRegistrar registrar_; | 112 NotificationRegistrar registrar_; |
105 FilePath storage_dir_; | 113 FilePath storage_dir_; |
106 bool policy_request_pending_; | 114 bool policy_request_pending_; |
107 | 115 |
108 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); | 116 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); |
109 }; | 117 }; |
110 | 118 |
111 } // namespace policy | 119 } // namespace policy |
112 | 120 |
113 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ | 121 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ |
OLD | NEW |