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 #ifndef CHROME_BROWSER_POLICY_CLOUD_REMOTE_COMMANDS_INVALIDATOR_H_ |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_REMOTE_COMMANDS_INVALIDATOR_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/threading/thread_checker.h" |
| 10 #include "components/invalidation/invalidation_handler.h" |
| 11 #include "google/cacheinvalidation/include/types.h" |
| 12 #include "policy/proto/device_management_backend.pb.h" |
| 13 |
| 14 namespace invalidation { |
| 15 class InvalidationService; |
| 16 } // namespace invalidation |
| 17 |
| 18 namespace policy { |
| 19 |
| 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 { |
| 25 public: |
| 26 RemoteCommandsInvalidator(); |
| 27 ~RemoteCommandsInvalidator() override; |
| 28 |
| 29 // Initialize this invalidator to pair with |invalidation_service|. Must be |
| 30 // called before Start(). |
| 31 void Initialize(invalidation::InvalidationService* invalidation_service); |
| 32 |
| 33 // Shutdown this invalidator. Will stop the invalidator first, and after |
| 34 // shutting down, the invalidator can't be started anymore unless it's |
| 35 // initialized again. |
| 36 void Shutdown(); |
| 37 |
| 38 // Starts to process invalidations. |
| 39 void Start(); |
| 40 |
| 41 // Stops to process invalidation. May only be called after Start() has been |
| 42 // called. |
| 43 void Stop(); |
| 44 |
| 45 // Helpful accessors. |
| 46 invalidation::InvalidationService* invalidation_service() { |
| 47 return invalidation_service_; |
| 48 } |
| 49 bool invalidations_enabled() { return invalidations_enabled_; } |
| 50 |
| 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; |
| 56 |
| 57 protected: |
| 58 virtual void OnInitialize() = 0; |
| 59 virtual void OnShutdown() = 0; |
| 60 virtual void OnStart() = 0; |
| 61 virtual void OnStop() = 0; |
| 62 |
| 63 // Subclasses must override this method to implement the actual remote |
| 64 // commands fetch. |
| 65 virtual void DoRemoteCommandsFetch() = 0; |
| 66 |
| 67 // Subclasses must call this function to set the object id for remote command |
| 68 // invalidations. |
| 69 void ReloadPolicyData(const enterprise_management::PolicyData* policy); |
| 70 |
| 71 private: |
| 72 // Registers the given object with the invalidation service. |
| 73 void Register(const invalidation::ObjectId& object_id); |
| 74 |
| 75 // Unregisters the current object with the invalidation service. |
| 76 void Unregister(); |
| 77 |
| 78 // Updates invalidations_enabled_. |
| 79 void UpdateInvalidationsEnabled(); |
| 80 |
| 81 // The state of the object. |
| 82 enum State { |
| 83 SHUT_DOWN, |
| 84 STOPPED, |
| 85 STARTED, |
| 86 }; |
| 87 State state_ = SHUT_DOWN; |
| 88 |
| 89 // The invalidation service. |
| 90 invalidation::InvalidationService* invalidation_service_ = nullptr; |
| 91 |
| 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; |
| 96 |
| 97 // Whether the invalidation service is currently enabled. |
| 98 bool invalidation_service_enabled_ = false; |
| 99 |
| 100 // Whether this object has registered for remote commands invalidations. |
| 101 bool is_registered_ = false; |
| 102 |
| 103 // The object id representing the remote commands in the invalidation service. |
| 104 invalidation::ObjectId object_id_; |
| 105 |
| 106 // A thread checker to make sure that callbacks are invoked on the correct |
| 107 // thread. |
| 108 base::ThreadChecker thread_checker_; |
| 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(RemoteCommandsInvalidator); |
| 111 }; |
| 112 |
| 113 } // namespace policy |
| 114 |
| 115 #endif // CHROME_BROWSER_POLICY_CLOUD_REMOTE_COMMANDS_INVALIDATOR_H_ |
OLD | NEW |