OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_AFFILIATED_INVALIDATION_SERVICE_PROVIDER_ H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_INVALIDATION_SERVICE_PROVIDER_ H_ |
6 #define CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_INVALIDATION_SERVICE_PROVIDER_ H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_INVALIDATION_SERVICE_PROVIDER_ H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/memory/scoped_vector.h" | |
11 #include "base/observer_list.h" | |
12 #include "content/public/browser/notification_observer.h" | |
13 #include "content/public/browser/notification_registrar.h" | |
14 | 9 |
15 namespace invalidation { | 10 namespace invalidation { |
16 class InvalidationService; | 11 class InvalidationService; |
17 class TiclInvalidationService; | |
18 } | 12 } |
19 | 13 |
20 namespace policy { | 14 namespace policy { |
21 | 15 |
22 // This class provides access to an |InvalidationService| that can be used to | 16 // This class provides access to an |InvalidationService| that can be used to |
23 // subscribe to invalidations generated by the device's enrollment domain, e.g. | 17 // subscribe to invalidations generated by the device's enrollment domain, e.g. |
24 // policy pushing and remote commands for: | 18 // policy pushing and remote commands for: |
25 // * the device itself | 19 // * the device itself |
26 // * device-local accounts | 20 // * device-local accounts |
27 // * other users affiliated with the enrollment domain | 21 // * other users affiliated with the enrollment domain |
28 // | 22 // |
29 // If an affiliated user with a connected invalidation service is logged in, | 23 // If an affiliated user with a connected invalidation service is logged in, |
30 // that invalidation service will be used to conserve server resources. If there | 24 // that invalidation service will be used to conserve server resources. If there |
31 // are no logged-in users matching these criteria, a device-global | 25 // are no logged-in users matching these criteria, a device-global |
32 // |TiclInvalidationService| is spun up. | 26 // |TiclInvalidationService| is spun up. |
33 // The class monitors the status of the invalidation services and switches | 27 // The class monitors the status of the invalidation services and switches |
34 // between them whenever the service currently in use disconnects or the | 28 // between them whenever the service currently in use disconnects or the |
35 // device-global invalidation service can be replaced with another service that | 29 // device-global invalidation service can be replaced with another service that |
36 // just connected. | 30 // just connected. |
37 class AffiliatedInvalidationServiceProvider | 31 class AffiliatedInvalidationServiceProvider { |
38 : public content::NotificationObserver { | |
39 public: | 32 public: |
40 class Consumer { | 33 class Consumer { |
41 public: | 34 public: |
42 // This method is called when the invalidation service that the consumer | 35 // This method is called when the invalidation service that the consumer |
43 // should use changes: | 36 // should use changes: |
44 // * If |invalidation_service| is a nullptr, no invalidation service is | 37 // * If |invalidation_service| is a nullptr, no invalidation service is |
45 // currently available for use. | 38 // currently available for use. |
46 // * Otherwise, |invalidation_service| is the invalidation service that the | 39 // * Otherwise, |invalidation_service| is the invalidation service that the |
47 // consumer should use. It is guaranteed to be connected. Any previously | 40 // consumer should use. It is guaranteed to be connected. Any previously |
48 // provided invalidation services must no longer be used. | 41 // provided invalidation services must no longer be used. |
49 virtual void OnInvalidationServiceSet( | 42 virtual void OnInvalidationServiceSet( |
50 invalidation::InvalidationService* invalidation_service) = 0; | 43 invalidation::InvalidationService* invalidation_service) = 0; |
51 | 44 |
52 protected: | 45 protected: |
53 virtual ~Consumer(); | 46 virtual ~Consumer(); |
pneubeck (no reviews)
2015/02/04 10:02:14
nitty: + DISALLOW_ASSIGN (which will require a c't
bartfab (slow)
2015/02/04 12:34:51
Done.
| |
54 }; | 47 }; |
55 | 48 |
56 AffiliatedInvalidationServiceProvider(); | 49 AffiliatedInvalidationServiceProvider(); |
57 ~AffiliatedInvalidationServiceProvider() override; | 50 virtual ~AffiliatedInvalidationServiceProvider(); |
58 | |
59 // content::NotificationObserver: | |
60 void Observe(int type, | |
61 const content::NotificationSource& source, | |
62 const content::NotificationDetails& details) override; | |
63 | 51 |
64 // Indicates that |consumer| is interested in using the shared | 52 // Indicates that |consumer| is interested in using the shared |
65 // |InvalidationService|. The consumer's OnInvalidationServiceSet() method | 53 // |InvalidationService|. The consumer's OnInvalidationServiceSet() method |
66 // will be called back when a connected invalidation service becomes | 54 // will be called back when a connected invalidation service becomes |
67 // available. If an invalidation service is available already, the callback | 55 // available. If an invalidation service is available already, the callback |
68 // will occur synchronously. The |consumer| must be unregistered before |this| | 56 // will occur synchronously. The |consumer| must be unregistered before |this| |
69 // is destroyed. | 57 // is destroyed. |
70 void RegisterConsumer(Consumer* consumer); | 58 virtual void RegisterConsumer(Consumer* consumer) = 0; |
71 | 59 |
72 // Indicates that |consumer| is no longer interested in using the | 60 // Indicates that |consumer| is no longer interested in using the |
73 // shared |InvalidationService|. | 61 // shared |InvalidationService|. |
74 void UnregisterConsumer(Consumer* consumer); | 62 virtual void UnregisterConsumer(Consumer* consumer) = 0; |
75 | 63 |
76 // Shuts down the provider. Once the provider is shut down, it no longer makes | 64 // Shuts down the provider. Once the provider is shut down, it no longer makes |
77 // any invalidation service available to consumers, no longer observes any | 65 // any invalidation service available to consumers, no longer observes any |
78 // per-profile invalidation services and no longer maintains a device-global | 66 // per-profile invalidation services and no longer maintains a device-global |
79 // invalidation service. | 67 // invalidation service. |
80 void Shutdown(); | 68 virtual void Shutdown() = 0; |
81 | |
82 invalidation::TiclInvalidationService* | |
83 GetDeviceInvalidationServiceForTest() const; | |
84 | 69 |
85 private: | 70 private: |
86 // Helper that monitors the status of a single |InvalidationService|. | |
87 class InvalidationServiceObserver; | |
88 | |
89 // Status updates received from |InvalidationServiceObserver|s. | |
90 void OnInvalidationServiceConnected( | |
91 invalidation::InvalidationService* invalidation_service); | |
92 void OnInvalidationServiceDisconnected( | |
93 invalidation::InvalidationService* invalidation_service); | |
94 | |
95 // Checks whether a connected |InvalidationService| affiliated with the | |
96 // device's enrollment domain is available. If so, notifies the consumers. | |
97 // Otherwise, consumers will be notified once such an invalidation service | |
98 // becomes available. | |
99 // Further ensures that a device-global invalidation service is running iff | |
100 // there is no other connected service available for use and there is at least | |
101 // one registered consumer. | |
102 void FindConnectedInvalidationService(); | |
103 | |
104 // Choose |invalidation_service| as the shared invalidation service and notify | |
105 // consumers. | |
106 void SetInvalidationService( | |
107 invalidation::InvalidationService* invalidation_service); | |
108 | |
109 // Destroy the device-global invalidation service, if any. | |
110 void DestroyDeviceInvalidationService(); | |
111 | |
112 content::NotificationRegistrar registrar_; | |
113 | |
114 // Device-global invalidation service. | |
115 scoped_ptr<invalidation::TiclInvalidationService> | |
116 device_invalidation_service_; | |
117 | |
118 // State observer for the device-global invalidation service. | |
119 scoped_ptr<InvalidationServiceObserver> device_invalidation_service_observer_; | |
120 | |
121 // State observers for logged-in users' invalidation services. | |
122 ScopedVector<InvalidationServiceObserver> | |
123 profile_invalidation_service_observers_; | |
124 | |
125 // The invalidation service currently used by consumers. nullptr if there are | |
126 // no registered consumers or no connected invalidation service is available | |
127 // for use. | |
128 invalidation::InvalidationService* invalidation_service_; | |
129 | |
130 ObserverList<Consumer, true> consumers_; | |
131 int consumer_count_; | |
132 | |
133 bool is_shut_down_; | |
134 | |
135 DISALLOW_COPY_AND_ASSIGN(AffiliatedInvalidationServiceProvider); | 71 DISALLOW_COPY_AND_ASSIGN(AffiliatedInvalidationServiceProvider); |
pneubeck (no reviews)
2015/02/04 10:02:14
nit: DISALLOW_ASSIGN is sufficient as this class i
bartfab (slow)
2015/02/04 12:34:51
Done.
| |
136 }; | 72 }; |
137 | 73 |
138 } // namespace policy | 74 } // namespace policy |
139 | 75 |
140 #endif // CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_INVALIDATION_SERVICE_PROVID ER_H_ | 76 #endif // CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_INVALIDATION_SERVICE_PROVID ER_H_ |
OLD | NEW |