Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / affiliated_cloud_policy_invalidator.cc
blob952cab4c1e8de972429db4c4318acc9c79f95a77
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"
13 namespace policy {
15 AffiliatedCloudPolicyInvalidator::AffiliatedCloudPolicyInvalidator(
16 enterprise_management::DeviceRegisterRequest::Type type,
17 CloudPolicyCore* core,
18 AffiliatedInvalidationServiceProvider* invalidation_service_provider)
19 : type_(type),
20 core_(core),
21 invalidation_service_provider_(invalidation_service_provider),
22 highest_handled_invalidation_version_(0) {
23 invalidation_service_provider_->RegisterConsumer(this);
26 AffiliatedCloudPolicyInvalidator::~AffiliatedCloudPolicyInvalidator() {
27 DestroyInvalidator();
28 invalidation_service_provider_->UnregisterConsumer(this);
31 void AffiliatedCloudPolicyInvalidator::OnInvalidationServiceSet(
32 invalidation::InvalidationService* invalidation_service) {
33 DestroyInvalidator();
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(
47 type_,
48 core_,
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() {
56 if (!invalidator_)
57 return;
59 highest_handled_invalidation_version_ =
60 invalidator_->highest_handled_invalidation_version();
61 invalidator_->Shutdown();
62 invalidator_.reset();
65 } // namespace policy