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

Side by Side Diff: chrome/browser/policy/cloud/remote_commands_invalidator.h

Issue 1094493003: Initial RemoteCommandsInvalidator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: rename / move files 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 unified diff | Download patch
OLDNEW
(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"
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
bartfab (slow) 2015/05/15 15:55:08 Nit: Update the comment: 1) The class was renamed.
binjin 2015/05/15 16:12:40 Done.
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 // |task_runner| will be used to post DoRemoteCommandsFetch() tasks.
33 explicit RemoteCommandsInvalidator(
34 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
35 ~RemoteCommandsInvalidator() 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.
43 void Shutdown();
44
45 // Starts to process the invalidations.
46 void Start();
47
48 // Stops to process the invalidation. Must be called after Start().
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
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
72 // commands fetch. A callback to this function will be posted to
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<RemoteCommandsInvalidator> weak_factory_;
124
125 DISALLOW_COPY_AND_ASSIGN(RemoteCommandsInvalidator);
126 };
127
128 } // namespace policy
129
130 #endif // CHROME_BROWSER_POLICY_CLOUD_REMOTE_COMMANDS_INVALIDATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698