Chromium Code Reviews| 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_BASE_H_ | |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_REMOTE_COMMANDS_INVALIDATOR_BASE_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "base/threading/thread_checker.h" | |
| 12 #include "components/invalidation/invalidation_handler.h" | |
| 13 #include "google/cacheinvalidation/include/types.h" | |
| 14 #include "policy/proto/device_management_backend.pb.h" | |
| 15 | |
| 16 namespace base { | |
| 17 class SequencedTaskRunner; | |
| 18 } // namespace base | |
| 19 | |
| 20 namespace invalidation { | |
| 21 class InvalidationService; | |
| 22 } // namespace invalidation | |
| 23 | |
| 24 namespace policy { | |
| 25 | |
| 26 // Base class for RemoteCommandsInvalidator, this class doesn't interact with | |
| 27 // CloudPolicyStore and CloudPolicyCore directly. Instead, several interface | |
| 28 // functions are provided, to allow subclasses to integrate with cloud policy | |
| 29 // infrastructure. | |
| 30 class RemoteCommandsInvalidatorBase : public syncer::InvalidationHandler { | |
| 31 public: | |
| 32 // |task_runner| will be used to post DoRemoteCommandsFetch() tasks. | |
|
bartfab (slow)
2015/05/15 15:37:12
1: Nit: Document that this needs to be the current
binjin
2015/05/15 15:46:46
Acknowledged. task_runner was removed.
| |
| 33 explicit RemoteCommandsInvalidatorBase( | |
| 34 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | |
| 35 ~RemoteCommandsInvalidatorBase() override; | |
| 36 | |
| 37 // Initialize this invalidator to pair with |invalidation_service|. Must be | |
| 38 // called before Start(). | |
| 39 void Initialize(invalidation::InvalidationService* invalidation_service); | |
| 40 | |
| 41 // Shutdown this invalidator. Will stop the invalidator first, and after | |
| 42 // shutting down, the invalidator can't be started anymore. | |
|
bartfab (slow)
2015/05/15 15:37:12
Well, it can be started by calling Initialize() ag
binjin
2015/05/15 15:46:46
Done.
| |
| 43 void Shutdown(); | |
| 44 | |
| 45 // Starts to process the invalidations. | |
|
bartfab (slow)
2015/05/15 15:37:12
Nit: s/the //
binjin
2015/05/15 15:46:46
Done.
| |
| 46 void Start(); | |
| 47 | |
| 48 // Stops to process the invalidation. Must be called after Start(). | |
|
bartfab (slow)
2015/05/15 15:37:12
Nit 1: s/the invalidation/invalidations/
Nit 2: "M
binjin
2015/05/15 15:46:46
Done.
| |
| 49 void Stop(); | |
| 50 | |
| 51 // Helpful accessors. | |
| 52 invalidation::InvalidationService* invalidation_service() { | |
| 53 return invalidation_service_; | |
| 54 } | |
| 55 bool invalidations_enabled() { return invalidations_enabled_; } | |
| 56 | |
| 57 // syncer::InvalidationHandler: | |
| 58 void OnInvalidatorStateChange(syncer::InvalidatorState state) override; | |
| 59 void OnIncomingInvalidation( | |
| 60 const syncer::ObjectIdInvalidationMap& invalidation_map) override; | |
| 61 std::string GetOwnerName() const override; | |
| 62 | |
| 63 protected: | |
| 64 // Subclasses should override the following functions, if they want to get | |
|
bartfab (slow)
2015/05/15 15:37:12
Subclasses actually *must* override these methods,
binjin
2015/05/15 15:46:46
Done.
| |
| 65 // notified on corresponding events. | |
| 66 virtual void OnInitialize() = 0; | |
| 67 virtual void OnShutdown() = 0; | |
| 68 virtual void OnStart() = 0; | |
| 69 virtual void OnStop() = 0; | |
| 70 | |
| 71 // Subclasses must override this method to implements the actual remote | |
|
bartfab (slow)
2015/05/15 15:37:12
Nit: s/implements/implement/
binjin
2015/05/15 15:46:46
Done.
| |
| 72 // commands fetch. A callback to this function will be posted to | |
|
bartfab (slow)
2015/05/15 15:37:12
Nit: s/callback/call/
binjin
2015/05/15 15:46:46
Done.
| |
| 73 // |task_runner_|. | |
| 74 virtual void DoRemoteCommandsFetch() = 0; | |
| 75 | |
| 76 // Subclasses must call this function to set the object id for remote command | |
| 77 // invalidations. | |
| 78 void ReloadPolicyData(const enterprise_management::PolicyData* policy); | |
| 79 | |
| 80 private: | |
| 81 // Registers the given object with the invalidation service. | |
| 82 void Register(const invalidation::ObjectId& object_id); | |
| 83 | |
| 84 // Unregisters the current object with the invalidation service. | |
| 85 void Unregister(); | |
| 86 | |
| 87 // Updates invalidations_enabled_. | |
| 88 void UpdateInvalidationsEnabled(); | |
| 89 | |
| 90 // The state of the object. | |
| 91 enum State { | |
| 92 SHUT_DOWN, | |
| 93 STOPPED, | |
| 94 STARTED, | |
| 95 }; | |
| 96 State state_ = SHUT_DOWN; | |
| 97 | |
| 98 // Schedules delayed tasks. | |
| 99 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
| 100 | |
| 101 // The invalidation service. | |
| 102 invalidation::InvalidationService* invalidation_service_ = nullptr; | |
| 103 | |
| 104 // Whether the invalidator currently has the ability to receive invalidations. | |
| 105 // This is true if the invalidation service is enabled and the invalidator | |
| 106 // has registered for a remote commands object. | |
| 107 bool invalidations_enabled_ = false; | |
| 108 | |
| 109 // Whether the invalidation service is currently enabled. | |
| 110 bool invalidation_service_enabled_ = false; | |
| 111 | |
| 112 // Whether this object has registered for remote commands invalidations. | |
| 113 bool is_registered_ = false; | |
| 114 | |
| 115 // The object id representing the remote commands in the invalidation service. | |
| 116 invalidation::ObjectId object_id_; | |
| 117 | |
| 118 // A thread checker to make sure that callbacks are invoked on the correct | |
| 119 // thread. | |
| 120 base::ThreadChecker thread_checker_; | |
| 121 | |
| 122 // WeakPtrFactory used to create callbacks to this object. | |
| 123 base::WeakPtrFactory<RemoteCommandsInvalidatorBase> weak_factory_; | |
| 124 | |
| 125 DISALLOW_COPY_AND_ASSIGN(RemoteCommandsInvalidatorBase); | |
| 126 }; | |
| 127 | |
| 128 } // namespace policy | |
| 129 | |
| 130 #endif // CHROME_BROWSER_POLICY_CLOUD_REMOTE_COMMANDS_INVALIDATOR_BASE_H_ | |
| OLD | NEW |