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

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: Style fixes. Created 5 years, 10 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/policy/affiliated_invalidation_service_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ~AffiliatedInvalidationServiceProvider() override;
58
59 // content::NotificationObserver:
60 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 // 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
78 // per-profile invalidation services and no longer maintains a device-global
79 // invalidation service.
80 void Shutdown();
81
82 invalidation::TiclInvalidationService*
83 GetDeviceInvalidationServiceForTest() const;
84
85 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);
136 };
137
138 } // namespace policy
139
140 #endif // CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_INVALIDATION_SERVICE_PROVID ER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/policy/affiliated_invalidation_service_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698