[Android] Allow multiple --install in bb_device_steps.py.
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / device_cloud_policy_invalidator.h
blobf1802251f6a55f6675fe6267fa1621cbc3a0cd68
1 // Copyright 2014 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_DEVICE_CLOUD_POLICY_INVALIDATOR_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_INVALIDATOR_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.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 CloudPolicyInvalidator;
25 // This class provides invalidations for device policy via a
26 // |CloudPolicyInvalidator| backed by an |InvalidationService|. If an affiliated
27 // user with a connected invalidation service is logged in, that service is used
28 // to conserve server resources. If there are no logged-in users matching these
29 // criteria, a device-global |TiclInvalidationService| is spun up.
30 // The class monitors the status of the invalidation services and switches
31 // between them whenever the service currently in use disconnects or the
32 // device-global invalidation service can be replaced with another service that
33 // just connected.
34 class DeviceCloudPolicyInvalidator : public content::NotificationObserver {
35 public:
36 DeviceCloudPolicyInvalidator();
37 virtual ~DeviceCloudPolicyInvalidator();
39 // content::NotificationObserver:
40 virtual void Observe(int type,
41 const content::NotificationSource& source,
42 const content::NotificationDetails& details) override;
44 private:
45 friend class DeviceCloudPolicyInvalidatorTest;
47 // Helper that monitors the status of a single |InvalidationService|.
48 class InvalidationServiceObserver;
50 // Status updates received from |InvalidationServiceObserver|s.
51 void OnInvalidationServiceConnected(
52 invalidation::InvalidationService* invalidation_service);
53 void OnInvalidationServiceDisconnected(
54 invalidation::InvalidationService* invalidation_service);
56 // Attempt to create a |CloudPolicyInvalidator| backed by a connected
57 // invalidation service. If no connected invalidation service is available for
58 // use, a |CloudPolicyInvalidator| will be created later when a connected
59 // service becomes available.
60 // Further ensures that a device-global invalidation service is running iff
61 // there is no other connected service available for use.
62 void TryToCreateInvalidator();
64 // Create a |CloudPolicyInvalidator| backed by the |invalidation_service|.
65 void CreateInvalidator(
66 invalidation::InvalidationService* invalidation_service);
68 // Destroy the current |CloudPolicyInvalidator|, if any.
69 void DestroyInvalidator();
71 // Destroy the device-global invalidation service, if any.
72 void DestroyDeviceInvalidationService();
74 content::NotificationRegistrar registrar_;
76 // Device-global invalidation service.
77 scoped_ptr<invalidation::TiclInvalidationService>
78 device_invalidation_service_;
80 // State observer for the device-global invalidation service.
81 scoped_ptr<InvalidationServiceObserver> device_invalidation_service_observer_;
83 // State observers for logged-in users' invalidation services.
84 ScopedVector<InvalidationServiceObserver>
85 profile_invalidation_service_observers_;
87 // The invalidation service backing the current |CloudPolicyInvalidator|. NULL
88 // if no |CloudPolicyInvalidator| exists.
89 invalidation::InvalidationService* invalidation_service_;
91 // The highest invalidation version that was handled already.
92 int64 highest_handled_invalidation_version_;
94 // The current |CloudPolicyInvalidator|. NULL if no connected invalidation
95 // service is available.
96 scoped_ptr<CloudPolicyInvalidator> invalidator_;
98 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyInvalidator);
101 } // namespace policy
103 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_CLOUD_POLICY_INVALIDATOR_H_