Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5882)

Unified Diff: chrome/browser/chromeos/policy/remote_commands/remote_commands_invalidator.cc

Issue 1094493003: Initial RemoteCommandsInvalidator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: all unit tests, fix lints Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/remote_commands/remote_commands_invalidator.cc
diff --git a/chrome/browser/chromeos/policy/remote_commands/remote_commands_invalidator.cc b/chrome/browser/chromeos/policy/remote_commands/remote_commands_invalidator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2e5b11154f28878431f13182be45150676993a96
--- /dev/null
+++ b/chrome/browser/chromeos/policy/remote_commands/remote_commands_invalidator.cc
@@ -0,0 +1,103 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/policy/remote_commands/remote_commands_invalidator.h"
+
+#include "base/logging.h"
+#include "base/thread_task_runner_handle.h"
+#include "components/policy/core/common/cloud/cloud_policy_core.h"
bartfab (slow) 2015/05/15 13:28:07 Nit: Already included by header.
binjin 2015/05/15 14:50:38 Done.
+#include "components/policy/core/common/remote_commands/remote_commands_service.h"
+
+namespace policy {
+
+RemoteCommandsInvalidator::RemoteCommandsInvalidator(CloudPolicyCore* core)
+ : RemoteCommandsInvalidatorBase(base::ThreadTaskRunnerHandle::Get()),
+ core_(core) {
+ DCHECK(core_);
+}
+
+RemoteCommandsInvalidator::~RemoteCommandsInvalidator() {
bartfab (slow) 2015/05/15 13:28:07 Nit: No need to override the destructor if you are
binjin 2015/05/15 14:50:38 Done.
+}
+
+void RemoteCommandsInvalidator::OnInitialize() {
+ core_->AddObserver(this);
+ if (core_->remote_commands_service())
+ OnRemoteCommandsServiceStarted(core_);
+}
+
+void RemoteCommandsInvalidator::OnShutdown() {
+ core_->RemoveObserver(this);
+}
+
+void RemoteCommandsInvalidator::OnStart() {
+ OnStoreLoaded(core_->store());
+ core_->store()->AddObserver(this);
bartfab (slow) 2015/05/15 13:28:07 Nit: Here, you simulate an event one-off and then
binjin 2015/05/15 14:50:38 Done.
+}
+
+void RemoteCommandsInvalidator::OnStop() {
+ core_->store()->RemoveObserver(this);
+}
+
+void RemoteCommandsInvalidator::DoRemoteCommandsFetch() {
+ DCHECK(core_->remote_commands_service());
+ core_->remote_commands_service()->FetchRemoteCommands();
+}
+
+void RemoteCommandsInvalidator::OnCoreConnected(CloudPolicyCore* core) {
+}
+
+void RemoteCommandsInvalidator::OnRefreshSchedulerStarted(
+ CloudPolicyCore* core) {
+}
+
+void RemoteCommandsInvalidator::OnCoreDisconnecting(CloudPolicyCore* core) {
+ Stop();
+}
+
+void RemoteCommandsInvalidator::OnRemoteCommandsServiceStarted(
+ CloudPolicyCore* core) {
+ Start();
+}
+
+void RemoteCommandsInvalidator::OnStoreLoaded(CloudPolicyStore* core) {
+ ReloadPolicyData(core_->store()->policy());
+}
+
+void RemoteCommandsInvalidator::OnStoreError(CloudPolicyStore* core) {
+}
+
+AffiliatedRemoteCommandsInvalidator::AffiliatedRemoteCommandsInvalidator(
+ CloudPolicyCore* core,
+ AffiliatedInvalidationServiceProvider* invalidation_service_provider)
+ : core_(core),
+ invalidation_service_provider_(invalidation_service_provider) {
+ invalidation_service_provider_->RegisterConsumer(this);
+}
+
+AffiliatedRemoteCommandsInvalidator::~AffiliatedRemoteCommandsInvalidator() {
+ invalidation_service_provider_->UnregisterConsumer(this);
+}
+
+void AffiliatedRemoteCommandsInvalidator::OnInvalidationServiceSet(
+ invalidation::InvalidationService* invalidation_service) {
+ DestroyInvalidator();
+ if (invalidation_service)
+ CreateInvalidator(invalidation_service);
+}
+
+void AffiliatedRemoteCommandsInvalidator::CreateInvalidator(
+ invalidation::InvalidationService* invalidation_service) {
+ DCHECK(!invalidator_);
bartfab (slow) 2015/05/15 13:28:07 Nit: You can easily fold this method into OnInvali
binjin 2015/05/15 14:50:38 Done.
+ invalidator_.reset(new RemoteCommandsInvalidator(core_));
+ invalidator_->Initialize(invalidation_service);
+}
+
+void AffiliatedRemoteCommandsInvalidator::DestroyInvalidator() {
+ if (!invalidator_)
+ return;
+ invalidator_->Shutdown();
+ invalidator_.reset();
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698