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

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: Added test accessors; made unit test no longer be a friend 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 2014 The Chromium Authors. All rights reserved.
Mattias Nissler (ping if slow) 2015/01/13 09:50:15 2015 :)
bartfab (slow) 2015/01/13 17:45:23 This is what happens when you write code just befo
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 // When this method is called, the consumer may start using the provided
43 // |invalidation_service|. The invalidation service is guaranteed to be
44 // connected.
45 virtual void OnInvalidationServiceSet(
46 invalidation::InvalidationService* invalidation_service) = 0;
47
48 // When this method is called, the consumer must stop using the previously
49 // provided invalidation service.
50 virtual void OnInvalidationServiceReset() = 0;
Mattias Nissler (ping if slow) 2015/01/13 09:50:15 Could as well just call OnInvalidationSeviceSet(nu
bartfab (slow) 2015/01/13 17:45:23 It shortens the unit test file a bit. Done.
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 bool HasDeviceInvalidationServiceObserverForTest() const;
79 int GetProfileInvalidationServiceObserverCountForTest() const;
80 invalidation::InvalidationService* GetInvalidationServiceForTest() const;
81
82 private:
83 // Helper that monitors the status of a single |InvalidationService|.
84 class InvalidationServiceObserver;
85
86 // Status updates received from |InvalidationServiceObserver|s.
87 void OnInvalidationServiceConnected(
88 invalidation::InvalidationService* invalidation_service);
89 void OnInvalidationServiceDisconnected(
90 invalidation::InvalidationService* invalidation_service);
91
92 // Checks whether a connected |InvalidationService| affiliated with the
93 // device's enrollment domain is available. If so, notifies the consumers.
94 // Otherwise, consumers will be notified once such an invalidation service
95 // becomes available.
96 // Further ensures that a device-global invalidation service is running iff
97 // there is no other connected service available for use and there is at least
98 // one registered consumer.
99 void FindConnectedInvalidationService();
100
101 // Choose |invalidation_service| as the shared invalidation service and notify
102 // consumers.
103 void SetInvalidationService(
104 invalidation::InvalidationService* invalidation_service);
105
106 // Clear the shared invalidation service and notify consumers.
107 void ResetInvalidationService();
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 DISALLOW_COPY_AND_ASSIGN(AffiliatedInvalidationServiceProvider);
134 };
135
136 } // namespace policy
137
138 #endif // CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_INVALIDATION_SERVICE_PROVID ER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698