| 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" | |
| 10 #include "base/macros.h" | 9 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/scoped_vector.h" | 11 #include "chrome/browser/chromeos/policy/affiliated_invalidation_service_provide
r.h" |
| 13 #include "content/public/browser/notification_observer.h" | |
| 14 #include "content/public/browser/notification_registrar.h" | |
| 15 | 12 |
| 16 namespace invalidation { | 13 namespace invalidation { |
| 17 class InvalidationService; | 14 class InvalidationService; |
| 18 class TiclInvalidationService; | |
| 19 } | 15 } |
| 20 | 16 |
| 21 namespace policy { | 17 namespace policy { |
| 22 | 18 |
| 23 class CloudPolicyInvalidator; | 19 class CloudPolicyInvalidator; |
| 24 | 20 |
| 25 // This class provides invalidations for device policy via a | 21 // This class manages the lifetime of a device-global |CloudPolicyInvalidator| |
| 26 // |CloudPolicyInvalidator| backed by an |InvalidationService|. If an affiliated | 22 // that handles device policy invalidations. It relies on an |
| 27 // user with a connected invalidation service is logged in, that service is used | 23 // |AffiliatedInvalidationServiceProvider| to provide it with access to a shared |
| 28 // to conserve server resources. If there are no logged-in users matching these | 24 // |InvalidationService| to back the |CloudPolicyInvalidator|. Whenever the |
| 29 // criteria, a device-global |TiclInvalidationService| is spun up. | 25 // shared |InvalidationService| changes, the |CloudPolicyInvalidator| destroyed |
| 30 // The class monitors the status of the invalidation services and switches | 26 // and re-created. |
| 31 // between them whenever the service currently in use disconnects or the | 27 class DeviceCloudPolicyInvalidator |
| 32 // device-global invalidation service can be replaced with another service that | 28 : public AffiliatedInvalidationServiceProvider::Consumer { |
| 33 // just connected. | |
| 34 class DeviceCloudPolicyInvalidator : public content::NotificationObserver { | |
| 35 public: | 29 public: |
| 36 DeviceCloudPolicyInvalidator(); | 30 explicit DeviceCloudPolicyInvalidator( |
| 31 AffiliatedInvalidationServiceProvider* invalidation_service_provider); |
| 37 ~DeviceCloudPolicyInvalidator() override; | 32 ~DeviceCloudPolicyInvalidator() override; |
| 38 | 33 |
| 39 // content::NotificationObserver: | 34 // AffiliatedInvalidationServiceProvider::Consumer: |
| 40 void Observe(int type, | 35 void OnInvalidationServiceSet( |
| 41 const content::NotificationSource& source, | 36 invalidation::InvalidationService* invalidation_service) override; |
| 42 const content::NotificationDetails& details) override; | 37 |
| 38 CloudPolicyInvalidator* GetInvalidatorForTest() const; |
| 43 | 39 |
| 44 private: | 40 private: |
| 45 friend class DeviceCloudPolicyInvalidatorTest; | |
| 46 | |
| 47 // Helper that monitors the status of a single |InvalidationService|. | |
| 48 class InvalidationServiceObserver; | |
| 49 | |
| 50 // Status updates received from |InvalidationServiceObserver|s. | |
| 51 void OnInvalidationServiceConnected( | |
| 52 invalidation::InvalidationService* invalidation_service); | |
| 53 void OnInvalidationServiceDisconnected( | |
| 54 invalidation::InvalidationService* invalidation_service); | |
| 55 | |
| 56 // Attempt to create a |CloudPolicyInvalidator| backed by a connected | |
| 57 // invalidation service. If no connected invalidation service is available for | |
| 58 // use, a |CloudPolicyInvalidator| will be created later when a connected | |
| 59 // service becomes available. | |
| 60 // Further ensures that a device-global invalidation service is running iff | |
| 61 // there is no other connected service available for use. | |
| 62 void TryToCreateInvalidator(); | |
| 63 | |
| 64 // Create a |CloudPolicyInvalidator| backed by the |invalidation_service|. | 41 // Create a |CloudPolicyInvalidator| backed by the |invalidation_service|. |
| 65 void CreateInvalidator( | 42 void CreateInvalidator( |
| 66 invalidation::InvalidationService* invalidation_service); | 43 invalidation::InvalidationService* invalidation_service); |
| 67 | 44 |
| 68 // Destroy the current |CloudPolicyInvalidator|, if any. | 45 // Destroy the current |CloudPolicyInvalidator|, if any. |
| 69 void DestroyInvalidator(); | 46 void DestroyInvalidator(); |
| 70 | 47 |
| 71 // Destroy the device-global invalidation service, if any. | 48 AffiliatedInvalidationServiceProvider* invalidation_service_provider_; |
| 72 void DestroyDeviceInvalidationService(); | |
| 73 | |
| 74 content::NotificationRegistrar registrar_; | |
| 75 | |
| 76 // Device-global invalidation service. | |
| 77 scoped_ptr<invalidation::TiclInvalidationService> | |
| 78 device_invalidation_service_; | |
| 79 | |
| 80 // State observer for the device-global invalidation service. | |
| 81 scoped_ptr<InvalidationServiceObserver> device_invalidation_service_observer_; | |
| 82 | |
| 83 // State observers for logged-in users' invalidation services. | |
| 84 ScopedVector<InvalidationServiceObserver> | |
| 85 profile_invalidation_service_observers_; | |
| 86 | |
| 87 // The invalidation service backing the current |CloudPolicyInvalidator|. NULL | |
| 88 // if no |CloudPolicyInvalidator| exists. | |
| 89 invalidation::InvalidationService* invalidation_service_; | |
| 90 | 49 |
| 91 // The highest invalidation version that was handled already. | 50 // The highest invalidation version that was handled already. |
| 92 int64 highest_handled_invalidation_version_; | 51 int64 highest_handled_invalidation_version_; |
| 93 | 52 |
| 94 // The current |CloudPolicyInvalidator|. NULL if no connected invalidation | 53 // The current |CloudPolicyInvalidator|. nullptr if no connected invalidation |
| 95 // service is available. | 54 // service is available. |
| 96 scoped_ptr<CloudPolicyInvalidator> invalidator_; | 55 scoped_ptr<CloudPolicyInvalidator> invalidator_; |
| 97 | 56 |
| 98 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyInvalidator); | 57 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyInvalidator); |
| 99 }; | 58 }; |
| 100 | 59 |
| 101 } // namespace policy | 60 } // namespace policy |
| 102 | 61 |
| 103 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_INVALIDATOR_H_ | 62 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_INVALIDATOR_H_ |
| OLD | NEW |