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/memory/ref_counted.h" | |
bartfab (slow)
2015/05/15 16:00:30
Nit: Not used.
binjin
2015/05/15 16:12:41
Done.
| |
10 #include "base/memory/weak_ptr.h" | |
bartfab (slow)
2015/05/15 16:00:30
Nit: Not used.
binjin
2015/05/15 16:12:41
Done.
| |
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; | |
bartfab (slow)
2015/05/15 16:00:30
Nit: Not used.
binjin
2015/05/15 16:12:41
Done.
| |
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 RemoteCommandsInvalidator : public syncer::InvalidationHandler { | |
31 public: | |
32 RemoteCommandsInvalidator(); | |
33 ~RemoteCommandsInvalidator() override; | |
34 | |
35 // Initialize this invalidator to pair with |invalidation_service|. Must be | |
36 // called before Start(). | |
37 void Initialize(invalidation::InvalidationService* invalidation_service); | |
38 | |
39 // Shutdown this invalidator. Will stop the invalidator first, and after | |
40 // shutting down, the invalidator can't be started anymore unless it's | |
41 // initialized again. | |
42 void Shutdown(); | |
43 | |
44 // Starts to process invalidations. | |
45 void Start(); | |
46 | |
47 // Stops to process invalidation. May only be called after Start() has been | |
48 // called. | |
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 virtual void OnInitialize() = 0; | |
65 virtual void OnShutdown() = 0; | |
66 virtual void OnStart() = 0; | |
67 virtual void OnStop() = 0; | |
68 | |
69 // Subclasses must override this method to implement the actual remote | |
70 // commands fetch. | |
71 virtual void DoRemoteCommandsFetch() = 0; | |
72 | |
73 // Subclasses must call this function to set the object id for remote command | |
74 // invalidations. | |
75 void ReloadPolicyData(const enterprise_management::PolicyData* policy); | |
76 | |
77 private: | |
78 // Registers the given object with the invalidation service. | |
79 void Register(const invalidation::ObjectId& object_id); | |
80 | |
81 // Unregisters the current object with the invalidation service. | |
82 void Unregister(); | |
83 | |
84 // Updates invalidations_enabled_. | |
85 void UpdateInvalidationsEnabled(); | |
86 | |
87 // The state of the object. | |
88 enum State { | |
89 SHUT_DOWN, | |
90 STOPPED, | |
91 STARTED, | |
92 }; | |
93 State state_ = SHUT_DOWN; | |
94 | |
95 // The invalidation service. | |
96 invalidation::InvalidationService* invalidation_service_ = nullptr; | |
97 | |
98 // Whether the invalidator currently has the ability to receive invalidations. | |
99 // This is true if the invalidation service is enabled and the invalidator | |
100 // has registered for a remote commands object. | |
101 bool invalidations_enabled_ = false; | |
102 | |
103 // Whether the invalidation service is currently enabled. | |
104 bool invalidation_service_enabled_ = false; | |
105 | |
106 // Whether this object has registered for remote commands invalidations. | |
107 bool is_registered_ = false; | |
108 | |
109 // The object id representing the remote commands in the invalidation service. | |
110 invalidation::ObjectId object_id_; | |
111 | |
112 // A thread checker to make sure that callbacks are invoked on the correct | |
113 // thread. | |
114 base::ThreadChecker thread_checker_; | |
115 | |
116 DISALLOW_COPY_AND_ASSIGN(RemoteCommandsInvalidator); | |
117 }; | |
118 | |
119 } // namespace policy | |
120 | |
121 #endif // CHROME_BROWSER_POLICY_CLOUD_REMOTE_COMMANDS_INVALIDATOR_H_ | |
OLD | NEW |