OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/chromeos/policy/remote_commands/remote_commands_invalid
ator.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/thread_task_runner_handle.h" |
| 9 #include "components/policy/core/common/remote_commands/remote_commands_service.
h" |
| 10 |
| 11 namespace policy { |
| 12 |
| 13 RemoteCommandsInvalidator::RemoteCommandsInvalidator(CloudPolicyCore* core) |
| 14 : RemoteCommandsInvalidatorBase(base::ThreadTaskRunnerHandle::Get()), |
| 15 core_(core) { |
| 16 DCHECK(core_); |
| 17 } |
| 18 |
| 19 void RemoteCommandsInvalidator::OnInitialize() { |
| 20 core_->AddObserver(this); |
| 21 if (core_->remote_commands_service()) |
| 22 OnRemoteCommandsServiceStarted(core_); |
| 23 } |
| 24 |
| 25 void RemoteCommandsInvalidator::OnShutdown() { |
| 26 core_->RemoveObserver(this); |
| 27 } |
| 28 |
| 29 void RemoteCommandsInvalidator::OnStart() { |
| 30 core_->store()->AddObserver(this); |
| 31 OnStoreLoaded(core_->store()); |
| 32 } |
| 33 |
| 34 void RemoteCommandsInvalidator::OnStop() { |
| 35 core_->store()->RemoveObserver(this); |
| 36 } |
| 37 |
| 38 void RemoteCommandsInvalidator::DoRemoteCommandsFetch() { |
| 39 DCHECK(core_->remote_commands_service()); |
| 40 core_->remote_commands_service()->FetchRemoteCommands(); |
| 41 } |
| 42 |
| 43 void RemoteCommandsInvalidator::OnCoreConnected(CloudPolicyCore* core) { |
| 44 } |
| 45 |
| 46 void RemoteCommandsInvalidator::OnRefreshSchedulerStarted( |
| 47 CloudPolicyCore* core) { |
| 48 } |
| 49 |
| 50 void RemoteCommandsInvalidator::OnCoreDisconnecting(CloudPolicyCore* core) { |
| 51 Stop(); |
| 52 } |
| 53 |
| 54 void RemoteCommandsInvalidator::OnRemoteCommandsServiceStarted( |
| 55 CloudPolicyCore* core) { |
| 56 Start(); |
| 57 } |
| 58 |
| 59 void RemoteCommandsInvalidator::OnStoreLoaded(CloudPolicyStore* core) { |
| 60 ReloadPolicyData(core_->store()->policy()); |
| 61 } |
| 62 |
| 63 void RemoteCommandsInvalidator::OnStoreError(CloudPolicyStore* core) { |
| 64 } |
| 65 |
| 66 AffiliatedRemoteCommandsInvalidator::AffiliatedRemoteCommandsInvalidator( |
| 67 CloudPolicyCore* core, |
| 68 AffiliatedInvalidationServiceProvider* invalidation_service_provider) |
| 69 : core_(core), |
| 70 invalidation_service_provider_(invalidation_service_provider) { |
| 71 invalidation_service_provider_->RegisterConsumer(this); |
| 72 } |
| 73 |
| 74 AffiliatedRemoteCommandsInvalidator::~AffiliatedRemoteCommandsInvalidator() { |
| 75 invalidation_service_provider_->UnregisterConsumer(this); |
| 76 } |
| 77 |
| 78 void AffiliatedRemoteCommandsInvalidator::OnInvalidationServiceSet( |
| 79 invalidation::InvalidationService* invalidation_service) { |
| 80 // Destroy this invalidator if it exists. |
| 81 if (invalidator_) { |
| 82 invalidator_->Shutdown(); |
| 83 invalidator_.reset(); |
| 84 } |
| 85 // Create a new one if required. |
| 86 if (invalidation_service) { |
| 87 invalidator_.reset(new RemoteCommandsInvalidator(core_)); |
| 88 invalidator_->Initialize(invalidation_service); |
| 89 } |
| 90 } |
| 91 |
| 92 } // namespace policy |
OLD | NEW |