Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / affiliated_cloud_policy_invalidator.h
blob162f39b14e6d55a78efbe4fe0a1b5b15bd221139
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_AFFILIATED_CLOUD_POLICY_INVALIDATOR_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_CLOUD_POLICY_INVALIDATOR_H_
8 #include "base/basictypes.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/chromeos/policy/affiliated_invalidation_service_provider.h"
12 #include "policy/proto/device_management_backend.pb.h"
14 namespace invalidation {
15 class InvalidationService;
18 namespace policy {
20 class CloudPolicyCore;
21 class CloudPolicyInvalidator;
23 // This class provides policy invalidations for a |CloudPolicyCore| that wishes
24 // to use a shared |InvalidationService| affiliated with the device's enrollment
25 // domain. This is the case e.g. for device policy and device-local account
26 // policy.
27 // It relies on an |AffiliatedInvalidationServiceProvider| to provide it with
28 // access to a shared |InvalidationService| to back the
29 // |CloudPolicyInvalidator|. Whenever the shared |InvalidationService| changes,
30 // the |CloudPolicyInvalidator| is destroyed and re-created.
31 class AffiliatedCloudPolicyInvalidator
32 : public AffiliatedInvalidationServiceProvider::Consumer {
33 public:
34 AffiliatedCloudPolicyInvalidator(
35 enterprise_management::DeviceRegisterRequest::Type type,
36 CloudPolicyCore* core,
37 AffiliatedInvalidationServiceProvider* invalidation_service_provider);
38 ~AffiliatedCloudPolicyInvalidator() override;
40 // AffiliatedInvalidationServiceProvider::Consumer:
41 void OnInvalidationServiceSet(
42 invalidation::InvalidationService* invalidation_service) override;
44 CloudPolicyInvalidator* GetInvalidatorForTest() const;
46 private:
47 // Create a |CloudPolicyInvalidator| backed by the |invalidation_service|.
48 void CreateInvalidator(
49 invalidation::InvalidationService* invalidation_service);
51 // Destroy the current |CloudPolicyInvalidator|, if any.
52 void DestroyInvalidator();
54 const enterprise_management::DeviceRegisterRequest::Type type_;
55 CloudPolicyCore* const core_;
57 AffiliatedInvalidationServiceProvider* const invalidation_service_provider_;
59 // The highest invalidation version that was handled already.
60 int64 highest_handled_invalidation_version_;
62 // The current |CloudPolicyInvalidator|. nullptr if no connected invalidation
63 // service is available.
64 scoped_ptr<CloudPolicyInvalidator> invalidator_;
66 DISALLOW_COPY_AND_ASSIGN(AffiliatedCloudPolicyInvalidator);
69 } // namespace policy
71 #endif // CHROME_BROWSER_CHROMEOS_POLICY_AFFILIATED_CLOUD_POLICY_INVALIDATOR_H_