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

Side by Side Diff: chrome/browser/chromeos/policy/affiliated_invalidation_service_provider.h

Issue 828953004: Add AffiliatedInvalidationServiceProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplified tests. Made code reentrant. Created 5 years, 11 months 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_INVALIDATION_SERVICE_PROVIDER_ H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_INVALIDATION_SERVICE_PROVIDER_ H_
7
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
15 namespace invalidation {
16 class InvalidationService;
17 class TiclInvalidationService;
18 }
19
20 namespace policy {
21
22 // 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.
24 // policy pushing and remote commands for:
25 // * the device itself
26 // * device-local accounts
27 // * other users affiliated with the enrollment domain
28 //
29 // 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
31 // are no logged-in users matching these criteria, a device-global
32 // |TiclInvalidationService| is spun up.
33 // The class monitors the status of the invalidation services and switches
34 // between them whenever the service currently in use disconnects or the
35 // device-global invalidation service can be replaced with another service that
36 // just connected.
37 class AffiliatedInvalidationServiceProvider
38 : public content::NotificationObserver {
39 public:
40 class Consumer {
41 public:
42 // This method is called when the invalidation service that the consumer
43 // should use changes:
44 // * If |invalidation_service| is a nullptr, no invalidation service is
45 // currently available for use.
46 // * Otherwise, |invalidation_service| is the invalidation service that the
47 // consumer should use. It is guaranteed to be connected. Any previously
48 // provided invalidation services must no longer be used.
49 virtual void OnInvalidationServiceSet(
50 invalidation::InvalidationService* invalidation_service) = 0;
51
52 protected:
53 virtual ~Consumer();
54 };
55
56 AffiliatedInvalidationServiceProvider();
57 virtual ~AffiliatedInvalidationServiceProvider();
58
59 // content::NotificationObserver:
60 virtual void Observe(int type,
61 const content::NotificationSource& source,
62 const content::NotificationDetails& details) override;
63
64 // Indicates that |consumer| is interested in using the shared
65 // |InvalidationService|. The consumer's OnInvalidationServiceSet() method
66 // will be called back when a connected invalidation service becomes
67 // available. If an invalidation service is available already, the callback
68 // will occur synchronously. The |consumer| must be unregistered before |this|
69 // is destroyed.
70 void RegisterConsumer(Consumer* consumer);
71
72 // Indicates that |consumer| is no longer interested in using the
73 // shared |InvalidationService|.
74 void UnregisterConsumer(Consumer* consumer);
75
76 invalidation::TiclInvalidationService*
77 GetDeviceInvalidationServiceForTest() const;
78
79 private:
80 // Helper that monitors the status of a single |InvalidationService|.
81 class InvalidationServiceObserver;
82
83 // Status updates received from |InvalidationServiceObserver|s.
84 void OnInvalidationServiceConnected(
85 invalidation::InvalidationService* invalidation_service);
86 void OnInvalidationServiceDisconnected(
87 invalidation::InvalidationService* invalidation_service);
88
89 // Checks whether a connected |InvalidationService| affiliated with the
90 // device's enrollment domain is available. If so, notifies the consumers.
91 // Otherwise, consumers will be notified once such an invalidation service
92 // becomes available.
93 // Further ensures that a device-global invalidation service is running iff
94 // there is no other connected service available for use and there is at least
95 // one registered consumer.
96 void FindConnectedInvalidationService();
97
98 // Choose |invalidation_service| as the shared invalidation service and notify
99 // consumers.
100 void SetInvalidationService(
101 invalidation::InvalidationService* invalidation_service);
102
103 // Destroy the device-global invalidation service, if any.
104 void DestroyDeviceInvalidationService();
105
106 content::NotificationRegistrar registrar_;
107
108 // Device-global invalidation service.
109 scoped_ptr<invalidation::TiclInvalidationService>
110 device_invalidation_service_;
111
112 // State observer for the device-global invalidation service.
113 scoped_ptr<InvalidationServiceObserver> device_invalidation_service_observer_;
114
115 // State observers for logged-in users' invalidation services.
116 ScopedVector<InvalidationServiceObserver>
117 profile_invalidation_service_observers_;
118
119 // The invalidation service currently used by consumers. nullptr if there are
120 // no registered consumers or no connected invalidation service is available
121 // for use.
122 invalidation::InvalidationService* invalidation_service_;
123
124 ObserverList<Consumer, true> consumers_;
125 int consumer_count_;
126
127 DISALLOW_COPY_AND_ASSIGN(AffiliatedInvalidationServiceProvider);
128 };
129
130 } // namespace policy
131
132 #endif // CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_INVALIDATION_SERVICE_PROVID ER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698