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.
5 #ifndef CHROME_BROWSER_POLICY_CLOUD_REMOTE_COMMANDS_INVALIDATOR_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_REMOTE_COMMANDS_INVALIDATOR_H_
8 #include "base/macros.h"
9 #include "base/threading/thread_checker.h"
10 #include "components/invalidation/public/invalidation_handler.h"
11 #include "google/cacheinvalidation/include/types.h"
12 #include "policy/proto/device_management_backend.pb.h"
14 namespace invalidation
{
15 class InvalidationService
;
16 } // namespace invalidation
20 // This class provides basic intefaces for an invalidator for remote commands
21 // services. It's not interacting with CloudPolicyClient/CloudPolicyCore
22 // directly, instead, it handles the interacting with invalidation service
23 // only and leaves interfaces to integrate with subclasses.
24 class RemoteCommandsInvalidator
: public syncer::InvalidationHandler
{
26 RemoteCommandsInvalidator();
27 ~RemoteCommandsInvalidator() override
;
29 // Initialize this invalidator to pair with |invalidation_service|. Must be
30 // called before Start().
31 void Initialize(invalidation::InvalidationService
* invalidation_service
);
33 // Shutdown this invalidator. Will stop the invalidator first, and after
34 // shutting down, the invalidator can't be started anymore unless it's
38 // Starts to process invalidations.
41 // Stops to process invalidation. May only be called after Start() has been
46 invalidation::InvalidationService
* invalidation_service() {
47 return invalidation_service_
;
49 bool invalidations_enabled() { return invalidations_enabled_
; }
51 // syncer::InvalidationHandler:
52 void OnInvalidatorStateChange(syncer::InvalidatorState state
) override
;
53 void OnIncomingInvalidation(
54 const syncer::ObjectIdInvalidationMap
& invalidation_map
) override
;
55 std::string
GetOwnerName() const override
;
58 virtual void OnInitialize() = 0;
59 virtual void OnShutdown() = 0;
60 virtual void OnStart() = 0;
61 virtual void OnStop() = 0;
63 // Subclasses must override this method to implement the actual remote
65 virtual void DoRemoteCommandsFetch() = 0;
67 // Subclasses must call this function to set the object id for remote command
69 void ReloadPolicyData(const enterprise_management::PolicyData
* policy
);
72 // Registers the given object with the invalidation service.
73 void Register(const invalidation::ObjectId
& object_id
);
75 // Unregisters the current object with the invalidation service.
78 // Updates invalidations_enabled_.
79 void UpdateInvalidationsEnabled();
81 // The state of the object.
87 State state_
= SHUT_DOWN
;
89 // The invalidation service.
90 invalidation::InvalidationService
* invalidation_service_
= nullptr;
92 // Whether the invalidator currently has the ability to receive invalidations.
93 // This is true if the invalidation service is enabled and the invalidator
94 // has registered for a remote commands object.
95 bool invalidations_enabled_
= false;
97 // Whether the invalidation service is currently enabled.
98 bool invalidation_service_enabled_
= false;
100 // Whether this object has registered for remote commands invalidations.
101 bool is_registered_
= false;
103 // The object id representing the remote commands in the invalidation service.
104 invalidation::ObjectId object_id_
;
106 // A thread checker to make sure that callbacks are invoked on the correct
108 base::ThreadChecker thread_checker_
;
110 DISALLOW_COPY_AND_ASSIGN(RemoteCommandsInvalidator
);
113 } // namespace policy
115 #endif // CHROME_BROWSER_POLICY_CLOUD_REMOTE_COMMANDS_INVALIDATOR_H_