Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / affiliated_invalidation_service_provider_impl.h
blob1ab8216b85d8d179736175de16be4fc863167dc1
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_INVALIDATION_SERVICE_PROVIDER_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_INVALIDATION_SERVICE_PROVIDER_IMPL_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 "chrome/browser/chromeos/policy/affiliated_invalidation_service_provider.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
16 namespace invalidation {
17 class InvalidationService;
18 class TiclInvalidationService;
21 namespace policy {
23 class AffiliatedInvalidationServiceProviderImpl
24 : public AffiliatedInvalidationServiceProvider,
25 public content::NotificationObserver {
26 public:
27 AffiliatedInvalidationServiceProviderImpl();
28 ~AffiliatedInvalidationServiceProviderImpl() override;
30 // content::NotificationObserver:
31 void Observe(int type,
32 const content::NotificationSource& source,
33 const content::NotificationDetails& details) override;
35 // AffiliatedInvalidationServiceProvider:
36 void RegisterConsumer(Consumer* consumer) override;
37 void UnregisterConsumer(Consumer* consumer) override;
38 void Shutdown() override;
40 invalidation::TiclInvalidationService*
41 GetDeviceInvalidationServiceForTest() const;
43 private:
44 // Helper that monitors the status of a single |InvalidationService|.
45 class InvalidationServiceObserver;
47 // Status updates received from |InvalidationServiceObserver|s.
48 void OnInvalidationServiceConnected(
49 invalidation::InvalidationService* invalidation_service);
50 void OnInvalidationServiceDisconnected(
51 invalidation::InvalidationService* invalidation_service);
53 // Checks whether a connected |InvalidationService| affiliated with the
54 // device's enrollment domain is available. If so, notifies the consumers.
55 // Otherwise, consumers will be notified once such an invalidation service
56 // becomes available.
57 // Further ensures that a device-global invalidation service is running iff
58 // there is no other connected service available for use and there is at least
59 // one registered consumer.
60 void FindConnectedInvalidationService();
62 // Choose |invalidation_service| as the shared invalidation service and notify
63 // consumers.
64 void SetInvalidationService(
65 invalidation::InvalidationService* invalidation_service);
67 // Destroy the device-global invalidation service, if any.
68 void DestroyDeviceInvalidationService();
70 content::NotificationRegistrar registrar_;
72 // Device-global invalidation service.
73 scoped_ptr<invalidation::TiclInvalidationService>
74 device_invalidation_service_;
76 // State observer for the device-global invalidation service.
77 scoped_ptr<InvalidationServiceObserver> device_invalidation_service_observer_;
79 // State observers for logged-in users' invalidation services.
80 ScopedVector<InvalidationServiceObserver>
81 profile_invalidation_service_observers_;
83 // The invalidation service currently used by consumers. nullptr if there are
84 // no registered consumers or no connected invalidation service is available
85 // for use.
86 invalidation::InvalidationService* invalidation_service_;
88 ObserverList<Consumer, true> consumers_;
89 int consumer_count_;
91 bool is_shut_down_;
93 DISALLOW_COPY_AND_ASSIGN(AffiliatedInvalidationServiceProviderImpl);
96 } // namespace policy
98 #endif // CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_INVALIDATION_SERVICE_PROVIDER_IMPL_H_