Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Side by Side Diff: chrome/browser/policy/device_management_policy_provider.h

Issue 5219006: Refresh policies from DM server periodically (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/time.h"
13 #include "base/weak_ptr.h" 14 #include "base/weak_ptr.h"
14 #include "chrome/browser/policy/configuration_policy_provider.h" 15 #include "chrome/browser/policy/configuration_policy_provider.h"
15 #include "chrome/browser/policy/device_management_backend.h" 16 #include "chrome/browser/policy/device_management_backend.h"
16 #include "chrome/common/notification_details.h" 17 #include "chrome/browser/policy/device_token_fetcher.h"
17 #include "chrome/common/notification_observer.h"
18 #include "chrome/common/notification_registrar.h"
19 #include "chrome/common/notification_source.h"
20 18
21 class TokenService; 19 class TokenService;
22 20
23 namespace policy { 21 namespace policy {
24 22
25 class DeviceManagementBackend; 23 class DeviceManagementBackend;
26 class DeviceManagementPolicyCache; 24 class DeviceManagementPolicyCache;
27 class DeviceTokenFetcher;
28 25
29 // Provides policy fetched from the device management server. With the exception 26 // 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 27 // of the Provide method, which can be called on the FILE thread, all public
31 // methods must be called on the UI thread. 28 // methods must be called on the UI thread.
32 class DeviceManagementPolicyProvider 29 class DeviceManagementPolicyProvider
33 : public ConfigurationPolicyProvider, 30 : public ConfigurationPolicyProvider,
34 public NotificationObserver,
35 public DeviceManagementBackend::DevicePolicyResponseDelegate, 31 public DeviceManagementBackend::DevicePolicyResponseDelegate,
36 public base::SupportsWeakPtr<DeviceManagementPolicyProvider> { 32 public base::SupportsWeakPtr<DeviceManagementPolicyProvider>,
33 public DeviceTokenFetcher::Observer {
37 public: 34 public:
38 DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list, 35 DeviceManagementPolicyProvider(const PolicyDefinitionList* policy_list,
39 DeviceManagementBackend* backend, 36 DeviceManagementBackend* backend,
40 TokenService* token_service, 37 TokenService* token_service,
41 const FilePath& storage_dir); 38 const FilePath& storage_dir);
42 39
43 virtual ~DeviceManagementPolicyProvider(); 40 virtual ~DeviceManagementPolicyProvider();
44 41
45 // ConfigurationPolicyProvider implementation: 42 // ConfigurationPolicyProvider implementation:
46 virtual bool Provide(ConfigurationPolicyStoreInterface* store); 43 virtual bool Provide(ConfigurationPolicyStoreInterface* store);
47 44
48 // NotificationObserver implementation:
49 virtual void Observe(NotificationType type,
50 const NotificationSource& source,
51 const NotificationDetails& details);
52
53 // DevicePolicyResponseDelegate implementation: 45 // DevicePolicyResponseDelegate implementation:
54 virtual void HandlePolicyResponse( 46 virtual void HandlePolicyResponse(
55 const em::DevicePolicyResponse& response); 47 const em::DevicePolicyResponse& response);
56 virtual void OnError(DeviceManagementBackend::ErrorCode code); 48 virtual void OnError(DeviceManagementBackend::ErrorCode code);
57 49
50 // DeviceTokenFetcher::Observer implementation:
51 void OnTokenSuccess();
52 void OnTokenError();
53
58 // True if a policy request has been sent to the device management backend 54 // True if a policy request has been sent to the device management backend
59 // server and no response or error has yet been received. 55 // server and no response or error has yet been received.
60 bool IsPolicyRequestPending() const { return policy_request_pending_; } 56 bool IsPolicyRequestPending() const { return policy_request_pending_; }
61 57
62 // Tells the provider that the passed in token service reference is about to 58 // Tells the provider that the passed in token service reference is about to
63 // become invalid. 59 // become invalid.
64 void Shutdown(); 60 void Shutdown();
65 61
62 // Give unit tests the ability to override timeout settings.
danno 2010/11/22 13:47:50 All of these should definitely be private/protecte
Jakob Kummerow (corp) 2010/11/22 16:56:08 Done.
63 void set_policy_refresh_rate_ms(int64 policy_refresh_rate_ms) {
64 policy_refresh_rate_ms_ = policy_refresh_rate_ms;
65 }
66 void set_policy_refresh_max_earlier_ms(int64 policy_refresh_max_earlier_ms) {
67 policy_refresh_max_earlier_ms_ = policy_refresh_max_earlier_ms;
68 }
69 void set_policy_refresh_error_delay_ms(int64 policy_refresh_error_delay_ms) {
70 policy_refresh_error_delay_ms_ = policy_refresh_error_delay_ms;
71 }
72 void set_token_fetch_error_delay_ms(int64 token_fetch_error_delay_ms) {
73 token_fetch_error_delay_ms_ = token_fetch_error_delay_ms;
74 }
75
66 private: 76 private:
67 class InitializeAfterIOThreadExistsTask; 77 class InitializeAfterIOThreadExistsTask;
78 class RefreshTask;
68 79
69 // Returns the device management backend to use for backend requests, lazily 80 // Returns the device management backend to use for backend requests, lazily
70 // creating a new one if one doesn't already exist. 81 // creating a new one if one doesn't already exist.
71 DeviceManagementBackend* GetBackend(); 82 DeviceManagementBackend* GetBackend();
72 83
73 // Called by constructors to perform shared initialization. Initialization 84 // Called by constructors to perform shared initialization. Initialization
74 // requiring the IOThread must not be performed directly in this method, 85 // requiring the IOThread must not be performed directly in this method,
75 // rather must be deferred until the IOThread is fully initialized. This is 86 // rather must be deferred until the IOThread is fully initialized. This is
76 // the case in InitializeAfterIOThreadExists. 87 // the case in InitializeAfterIOThreadExists.
77 void Initialize(); 88 void Initialize();
78 89
79 // Called by a deferred task posted to the UI thread to complete the portion 90 // Called by a deferred task posted to the UI thread to complete the portion
80 // of initialization that requires the IOThread. 91 // of initialization that requires the IOThread.
81 void InitializeAfterIOThreadExists(); 92 void InitializeAfterIOThreadExists();
82 93
83 // Sends a request to the device manager backend to fetch policy if one isn't 94 // Sends a request to the device manager backend to fetch policy if one isn't
84 // already outstanding. 95 // already outstanding.
85 void SendPolicyRequest(); 96 void SendPolicyRequest();
86 97
87 // True if policy must be re-fetched because the cached policy is too old or 98 // Triggers policy refresh, re-requesting device token and policy information
88 // its time stamp is invalid. 99 // as necessary.
89 bool IsPolicyStale() const; 100 void RefreshTaskExecute();
101
102 // Schedules a new RefreshTask.
103 void ScheduleRefreshTask(int64 delay_in_milliseconds);
104
105 // Calculates when the next RefreshTask shall be executed.
106 static int64 GetRefreshTaskDelay(
107 int64 policy_refresh_rate_ms,
108 int64 policy_refresh_max_random_earlier_ms);
danno 2010/11/22 13:47:50 Why pass these in? You only pass in the values of
Jakob Kummerow (corp) 2010/11/22 16:56:08 Done.
90 109
91 // Provides the URL at which requests are sent to from the device management 110 // Provides the URL at which requests are sent to from the device management
92 // backend. 111 // backend.
93 static std::string GetDeviceManagementURL(); 112 static std::string GetDeviceManagementURL();
94 113
95 // Returns the path to the sub-directory in the user data directory 114 // Returns the path to the sub-directory in the user data directory
96 // in which device management persistent state is stored. 115 // in which device management persistent state is stored.
97 static FilePath GetOrCreateDeviceManagementDir( 116 static FilePath GetOrCreateDeviceManagementDir(
98 const FilePath& user_data_dir); 117 const FilePath& user_data_dir);
99 118
100 scoped_ptr<DeviceManagementBackend> backend_; 119 scoped_ptr<DeviceManagementBackend> backend_;
101 TokenService* token_service_; // weak 120 TokenService* token_service_; // weak
102 scoped_ptr<DeviceManagementPolicyCache> cache_; 121 scoped_ptr<DeviceManagementPolicyCache> cache_;
103 scoped_refptr<DeviceTokenFetcher> token_fetcher_; 122 scoped_refptr<DeviceTokenFetcher> token_fetcher_;
104 NotificationRegistrar registrar_;
105 FilePath storage_dir_; 123 FilePath storage_dir_;
106 bool policy_request_pending_; 124 bool policy_request_pending_;
125 bool refresh_task_pending_;
126 int64 policy_refresh_rate_ms_;
127 int64 policy_refresh_max_earlier_ms_;
128 int64 policy_refresh_error_delay_ms_;
129 int64 token_fetch_error_delay_ms_;
107 130
108 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider); 131 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyProvider);
109 }; 132 };
110 133
111 } // namespace policy 134 } // namespace policy
112 135
113 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_ 136 #endif // CHROME_BROWSER_POLICY_DEVICE_MANAGEMENT_POLICY_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698