OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_INVALIDATOR_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_INVALIDATOR_H_ |
6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_INVALIDATOR_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_INVALIDATOR_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
14 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
15 | 15 |
16 namespace invalidation { | 16 namespace invalidation { |
17 class InvalidationService; | 17 class InvalidationService; |
18 class TiclInvalidationService; | 18 class TiclInvalidationService; |
19 } | 19 } |
20 | 20 |
21 namespace policy { | 21 namespace policy { |
22 | 22 |
23 class CloudPolicyInvalidator; | 23 class CloudPolicyInvalidator; |
24 | 24 |
25 // This class provides invalidations for device policy via a | 25 // This class provides invalidations for device policy via a |
26 // |CloudPolicyInvalidator| backed by an |InvalidationService|. If a user with a | 26 // |CloudPolicyInvalidator| backed by an |InvalidationService|. If an affiliated |
27 // connected invalidation service is logged in, that service is used to conserve | 27 // user with a connected invalidation service is logged in, that service is used |
28 // server resources. If there are no logged-in users or none of them have | 28 // to conserve server resources. If there are no logged-in users matching these |
29 // connected invalidation services, a device-global |TiclInvalidationService| is | 29 // criteria, a device-global |TiclInvalidationService| is spun up. |
30 // spun up. | 30 // The class monitors the status of the invalidation services and switches |
31 // The class monitors the status of all invalidation services and switches | |
32 // between them whenever the service currently in use disconnects or the | 31 // between them whenever the service currently in use disconnects or the |
33 // device-global invalidation service can be replaced with another service that | 32 // device-global invalidation service can be replaced with another service that |
34 // just connected. | 33 // just connected. |
35 class DeviceCloudPolicyInvalidator : public content::NotificationObserver { | 34 class DeviceCloudPolicyInvalidator : public content::NotificationObserver { |
36 public: | 35 public: |
37 DeviceCloudPolicyInvalidator(); | 36 DeviceCloudPolicyInvalidator(); |
38 virtual ~DeviceCloudPolicyInvalidator(); | 37 virtual ~DeviceCloudPolicyInvalidator(); |
39 | 38 |
40 // content::NotificationObserver: | 39 // content::NotificationObserver: |
41 virtual void Observe(int type, | 40 virtual void Observe(int type, |
42 const content::NotificationSource& source, | 41 const content::NotificationSource& source, |
43 const content::NotificationDetails& details) OVERRIDE; | 42 const content::NotificationDetails& details) OVERRIDE; |
44 | 43 |
45 private: | 44 private: |
46 friend class DeviceCloudPolicyInvalidatorTest; | 45 friend class DeviceCloudPolicyInvalidatorTest; |
47 | 46 |
48 // Helper that monitors the status of a single |InvalidationService|. | 47 // Helper that monitors the status of a single |InvalidationService|. |
49 class InvalidationServiceObserver; | 48 class InvalidationServiceObserver; |
50 | 49 |
51 // Status updates received from |InvalidationServiceObserver|s. | 50 // Status updates received from |InvalidationServiceObserver|s. |
52 void OnInvalidationServiceConnected( | 51 void OnInvalidationServiceConnected( |
53 invalidation::InvalidationService* invalidation_service); | 52 invalidation::InvalidationService* invalidation_service); |
54 void OnInvalidationServiceDisconnected( | 53 void OnInvalidationServiceDisconnected( |
55 invalidation::InvalidationService* invalidation_service); | 54 invalidation::InvalidationService* invalidation_service); |
56 | 55 |
57 // Attempt to create a |CloudPolicyInvalidator| backed by a connected | 56 // Attempt to create a |CloudPolicyInvalidator| backed by a connected |
58 // invalidation service. If there is no connected invalidation service, a | 57 // invalidation service. If no connected invalidation service is available for |
59 // |CloudPolicyInvalidator| will be created later when a connected service | 58 // use, a |CloudPolicyInvalidator| will be created later when a connected |
60 // becomes available. | 59 // service becomes available. |
61 // Further ensures that a device-global invalidation service is running iff | 60 // Further ensures that a device-global invalidation service is running iff |
62 // there is no other connected service. | 61 // there is no other connected service available for use. |
63 void TryToCreateInvalidator(); | 62 void TryToCreateInvalidator(); |
64 | 63 |
65 // Create a |CloudPolicyInvalidator| backed by the |invalidation_service|. | 64 // Create a |CloudPolicyInvalidator| backed by the |invalidation_service|. |
66 void CreateInvalidator( | 65 void CreateInvalidator( |
67 invalidation::InvalidationService* invalidation_service); | 66 invalidation::InvalidationService* invalidation_service); |
68 | 67 |
69 // Destroy the current |CloudPolicyInvalidator|, if any. | 68 // Destroy the current |CloudPolicyInvalidator|, if any. |
70 void DestroyInvalidator(); | 69 void DestroyInvalidator(); |
71 | 70 |
72 // Destroy the device-global invalidation service, if any. | 71 // Destroy the device-global invalidation service, if any. |
(...skipping 22 matching lines...) Expand all Loading... |
95 // The current |CloudPolicyInvalidator|. NULL if no connected invalidation | 94 // The current |CloudPolicyInvalidator|. NULL if no connected invalidation |
96 // service is available. | 95 // service is available. |
97 scoped_ptr<CloudPolicyInvalidator> invalidator_; | 96 scoped_ptr<CloudPolicyInvalidator> invalidator_; |
98 | 97 |
99 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyInvalidator); | 98 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyInvalidator); |
100 }; | 99 }; |
101 | 100 |
102 } // namespace policy | 101 } // namespace policy |
103 | 102 |
104 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_INVALIDATOR_H_ | 103 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_INVALIDATOR_H_ |
OLD | NEW |