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 #include "chrome/browser/chromeos/policy/affiliated_cloud_policy_invalidator.h"
7 #include "base/logging.h"
8 #include "base/thread_task_runner_handle.h"
9 #include "base/time/clock.h"
10 #include "base/time/default_clock.h"
11 #include "chrome/browser/policy/cloud/cloud_policy_invalidator.h"
15 AffiliatedCloudPolicyInvalidator::AffiliatedCloudPolicyInvalidator(
16 enterprise_management::DeviceRegisterRequest::Type type
,
17 CloudPolicyCore
* core
,
18 AffiliatedInvalidationServiceProvider
* invalidation_service_provider
)
21 invalidation_service_provider_(invalidation_service_provider
),
22 highest_handled_invalidation_version_(0) {
23 invalidation_service_provider_
->RegisterConsumer(this);
26 AffiliatedCloudPolicyInvalidator::~AffiliatedCloudPolicyInvalidator() {
28 invalidation_service_provider_
->UnregisterConsumer(this);
31 void AffiliatedCloudPolicyInvalidator::OnInvalidationServiceSet(
32 invalidation::InvalidationService
* invalidation_service
) {
34 if (invalidation_service
)
35 CreateInvalidator(invalidation_service
);
38 CloudPolicyInvalidator
*
39 AffiliatedCloudPolicyInvalidator::GetInvalidatorForTest() const {
40 return invalidator_
.get();
43 void AffiliatedCloudPolicyInvalidator::CreateInvalidator(
44 invalidation::InvalidationService
* invalidation_service
) {
45 DCHECK(!invalidator_
);
46 invalidator_
.reset(new CloudPolicyInvalidator(
49 base::ThreadTaskRunnerHandle::Get(),
50 scoped_ptr
<base::Clock
>(new base::DefaultClock()),
51 highest_handled_invalidation_version_
));
52 invalidator_
->Initialize(invalidation_service
);
55 void AffiliatedCloudPolicyInvalidator::DestroyInvalidator() {
59 highest_handled_invalidation_version_
=
60 invalidator_
->highest_handled_invalidation_version();
61 invalidator_
->Shutdown();