OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/policy/cloud/remote_commands_invalidator.h" | 5 #include "chrome/browser/policy/cloud/remote_commands_invalidator.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
| 9 #include "base/chromeos/logging.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "components/invalidation/public/invalidation.h" | 11 #include "components/invalidation/public/invalidation.h" |
11 #include "components/invalidation/public/invalidation_service.h" | 12 #include "components/invalidation/public/invalidation_service.h" |
12 #include "components/invalidation/public/invalidation_util.h" | 13 #include "components/invalidation/public/invalidation_util.h" |
13 #include "components/invalidation/public/invalidator_state.h" | 14 #include "components/invalidation/public/invalidator_state.h" |
14 #include "components/invalidation/public/object_id_invalidation_map.h" | 15 #include "components/invalidation/public/object_id_invalidation_map.h" |
15 #include "components/invalidation/public/single_object_invalidation_set.h" | 16 #include "components/invalidation/public/single_object_invalidation_set.h" |
16 | 17 |
17 namespace policy { | 18 namespace policy { |
18 | 19 |
19 RemoteCommandsInvalidator::RemoteCommandsInvalidator() { | 20 RemoteCommandsInvalidator::RemoteCommandsInvalidator() { |
20 } | 21 } |
21 | 22 |
22 RemoteCommandsInvalidator::~RemoteCommandsInvalidator() { | 23 RemoteCommandsInvalidator::~RemoteCommandsInvalidator() { |
23 DCHECK_EQ(SHUT_DOWN, state_); | 24 DCHECK_EQ(SHUT_DOWN, state_); |
24 } | 25 } |
25 | 26 |
26 void RemoteCommandsInvalidator::Initialize( | 27 void RemoteCommandsInvalidator::Initialize( |
27 invalidation::InvalidationService* invalidation_service) { | 28 invalidation::InvalidationService* invalidation_service) { |
28 DCHECK_EQ(SHUT_DOWN, state_); | 29 DCHECK_EQ(SHUT_DOWN, state_); |
29 DCHECK(thread_checker_.CalledOnValidThread()); | 30 DCHECK(thread_checker_.CalledOnValidThread()); |
| 31 // TODO(hunyadym): Remove after crbug.com/582506 is fixed. |
| 32 CHROMEOS_SYSLOG(WARNING) << "Initialize RemoteCommandsInvalidator."; |
30 | 33 |
31 DCHECK(invalidation_service); | 34 DCHECK(invalidation_service); |
32 invalidation_service_ = invalidation_service; | 35 invalidation_service_ = invalidation_service; |
33 | 36 |
34 state_ = STOPPED; | 37 state_ = STOPPED; |
35 OnInitialize(); | 38 OnInitialize(); |
36 } | 39 } |
37 | 40 |
38 void RemoteCommandsInvalidator::Shutdown() { | 41 void RemoteCommandsInvalidator::Shutdown() { |
39 DCHECK_NE(SHUT_DOWN, state_); | 42 DCHECK_NE(SHUT_DOWN, state_); |
40 DCHECK(thread_checker_.CalledOnValidThread()); | 43 DCHECK(thread_checker_.CalledOnValidThread()); |
| 44 // TODO(hunyadym): Remove after crbug.com/582506 is fixed. |
| 45 CHROMEOS_SYSLOG(WARNING) << "Shutdown RemoteCommandsInvalidator."; |
41 | 46 |
42 Stop(); | 47 Stop(); |
43 | 48 |
44 state_ = SHUT_DOWN; | 49 state_ = SHUT_DOWN; |
45 OnShutdown(); | 50 OnShutdown(); |
46 } | 51 } |
47 | 52 |
48 void RemoteCommandsInvalidator::Start() { | 53 void RemoteCommandsInvalidator::Start() { |
49 DCHECK_EQ(STOPPED, state_); | 54 DCHECK_EQ(STOPPED, state_); |
50 DCHECK(thread_checker_.CalledOnValidThread()); | 55 DCHECK(thread_checker_.CalledOnValidThread()); |
| 56 // TODO(hunyadym): Remove after crbug.com/582506 is fixed. |
| 57 CHROMEOS_SYSLOG(WARNING) << "Starting RemoteCommandsInvalidator."; |
| 58 |
51 state_ = STARTED; | 59 state_ = STARTED; |
52 | 60 |
53 OnStart(); | 61 OnStart(); |
54 } | 62 } |
55 | 63 |
56 void RemoteCommandsInvalidator::Stop() { | 64 void RemoteCommandsInvalidator::Stop() { |
57 DCHECK_NE(SHUT_DOWN, state_); | 65 DCHECK_NE(SHUT_DOWN, state_); |
58 DCHECK(thread_checker_.CalledOnValidThread()); | 66 DCHECK(thread_checker_.CalledOnValidThread()); |
| 67 // TODO(hunyadym): Remove after crbug.com/582506 is fixed. |
| 68 CHROMEOS_SYSLOG(WARNING) << "Stopping RemoteCommandsInvalidator."; |
59 | 69 |
60 if (state_ == STARTED) { | 70 if (state_ == STARTED) { |
61 Unregister(); | 71 Unregister(); |
62 state_ = STOPPED; | 72 state_ = STOPPED; |
63 | 73 |
64 OnStop(); | 74 OnStop(); |
65 } | 75 } |
66 } | 76 } |
67 | 77 |
68 void RemoteCommandsInvalidator::OnInvalidatorStateChange( | 78 void RemoteCommandsInvalidator::OnInvalidatorStateChange( |
69 syncer::InvalidatorState state) { | 79 syncer::InvalidatorState state) { |
70 DCHECK_EQ(STARTED, state_); | 80 DCHECK_EQ(STARTED, state_); |
71 DCHECK(thread_checker_.CalledOnValidThread()); | 81 DCHECK(thread_checker_.CalledOnValidThread()); |
| 82 // TODO(hunyadym): Remove after crbug.com/582506 is fixed. |
| 83 CHROMEOS_SYSLOG(WARNING) << "RemoteCommandsInvalidator state changed: " |
| 84 << state; |
72 | 85 |
73 invalidation_service_enabled_ = state == syncer::INVALIDATIONS_ENABLED; | 86 invalidation_service_enabled_ = state == syncer::INVALIDATIONS_ENABLED; |
74 UpdateInvalidationsEnabled(); | 87 UpdateInvalidationsEnabled(); |
75 } | 88 } |
76 | 89 |
77 void RemoteCommandsInvalidator::OnIncomingInvalidation( | 90 void RemoteCommandsInvalidator::OnIncomingInvalidation( |
78 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 91 const syncer::ObjectIdInvalidationMap& invalidation_map) { |
79 DCHECK_EQ(STARTED, state_); | 92 DCHECK_EQ(STARTED, state_); |
80 DCHECK(thread_checker_.CalledOnValidThread()); | 93 DCHECK(thread_checker_.CalledOnValidThread()); |
| 94 // TODO(hunyadym): Remove after crbug.com/582506 is fixed. |
| 95 CHROMEOS_SYSLOG(WARNING) |
| 96 << "RemoteCommandsInvalidator received invalidation."; |
81 | 97 |
82 if (!invalidation_service_enabled_) | 98 if (!invalidation_service_enabled_) |
83 LOG(WARNING) << "Unexpected invalidation received."; | 99 LOG(WARNING) << "Unexpected invalidation received."; |
84 | 100 |
85 const syncer::SingleObjectInvalidationSet& list = | 101 const syncer::SingleObjectInvalidationSet& list = |
86 invalidation_map.ForObject(object_id_); | 102 invalidation_map.ForObject(object_id_); |
87 if (list.IsEmpty()) { | 103 if (list.IsEmpty()) { |
88 NOTREACHED(); | 104 NOTREACHED(); |
89 return; | 105 return; |
90 } | 106 } |
91 | 107 |
92 // Acknowledge all invalidations. | 108 // Acknowledge all invalidations. |
93 for (const auto& it : list) | 109 for (const auto& it : list) |
94 it.Acknowledge(); | 110 it.Acknowledge(); |
| 111 // TODO(hunyadym): Remove after crbug.com/582506 is fixed. |
| 112 CHROMEOS_SYSLOG(WARNING) << "Invalidations acknowledged."; |
95 | 113 |
96 DoRemoteCommandsFetch(); | 114 DoRemoteCommandsFetch(); |
97 } | 115 } |
98 | 116 |
99 std::string RemoteCommandsInvalidator::GetOwnerName() const { | 117 std::string RemoteCommandsInvalidator::GetOwnerName() const { |
100 return "RemoteCommands"; | 118 return "RemoteCommands"; |
101 } | 119 } |
102 | 120 |
103 void RemoteCommandsInvalidator::ReloadPolicyData( | 121 void RemoteCommandsInvalidator::ReloadPolicyData( |
104 const enterprise_management::PolicyData* policy) { | 122 const enterprise_management::PolicyData* policy) { |
105 DCHECK(thread_checker_.CalledOnValidThread()); | 123 DCHECK(thread_checker_.CalledOnValidThread()); |
| 124 // TODO(hunyadym): Remove after crbug.com/582506 is fixed. |
| 125 CHROMEOS_SYSLOG(WARNING) << "RemoteCommandsInvalidator ReloadPolicyData."; |
106 | 126 |
107 if (state_ != STARTED) | 127 if (state_ != STARTED) |
108 return; | 128 return; |
109 | 129 |
110 // Create the ObjectId based on the policy data. | 130 // Create the ObjectId based on the policy data. |
111 // If the policy does not specify an the ObjectId, then unregister. | 131 // If the policy does not specify an the ObjectId, then unregister. |
112 if (!policy || !policy->has_command_invalidation_source() || | 132 if (!policy || !policy->has_command_invalidation_source() || |
113 !policy->has_command_invalidation_name()) { | 133 !policy->has_command_invalidation_name()) { |
114 Unregister(); | 134 Unregister(); |
115 return; | 135 return; |
116 } | 136 } |
117 const invalidation::ObjectId object_id(policy->command_invalidation_source(), | 137 const invalidation::ObjectId object_id(policy->command_invalidation_source(), |
118 policy->command_invalidation_name()); | 138 policy->command_invalidation_name()); |
119 | 139 |
120 // If the policy object id in the policy data is different from the currently | 140 // If the policy object id in the policy data is different from the currently |
121 // registered object id, update the object registration. | 141 // registered object id, update the object registration. |
122 if (!is_registered_ || !(object_id == object_id_)) | 142 if (!is_registered_ || !(object_id == object_id_)) |
123 Register(object_id); | 143 Register(object_id); |
124 } | 144 } |
125 | 145 |
126 void RemoteCommandsInvalidator::Register( | 146 void RemoteCommandsInvalidator::Register( |
127 const invalidation::ObjectId& object_id) { | 147 const invalidation::ObjectId& object_id) { |
| 148 // TODO(hunyadym): Remove after crbug.com/582506 is fixed. |
| 149 CHROMEOS_SYSLOG(WARNING) << "Register RemoteCommandsInvalidator."; |
| 150 |
128 // Register this handler with the invalidation service if needed. | 151 // Register this handler with the invalidation service if needed. |
129 if (!is_registered_) { | 152 if (!is_registered_) { |
130 OnInvalidatorStateChange(invalidation_service_->GetInvalidatorState()); | 153 OnInvalidatorStateChange(invalidation_service_->GetInvalidatorState()); |
131 invalidation_service_->RegisterInvalidationHandler(this); | 154 invalidation_service_->RegisterInvalidationHandler(this); |
132 is_registered_ = true; | 155 is_registered_ = true; |
133 } | 156 } |
134 | 157 |
135 object_id_ = object_id; | 158 object_id_ = object_id; |
136 UpdateInvalidationsEnabled(); | 159 UpdateInvalidationsEnabled(); |
137 | 160 |
138 // Update registration with the invalidation service. | 161 // Update registration with the invalidation service. |
139 syncer::ObjectIdSet ids; | 162 syncer::ObjectIdSet ids; |
140 ids.insert(object_id); | 163 ids.insert(object_id); |
141 CHECK(invalidation_service_->UpdateRegisteredInvalidationIds(this, ids)); | 164 CHECK(invalidation_service_->UpdateRegisteredInvalidationIds(this, ids)); |
142 } | 165 } |
143 | 166 |
144 void RemoteCommandsInvalidator::Unregister() { | 167 void RemoteCommandsInvalidator::Unregister() { |
| 168 // TODO(hunyadym): Remove after crbug.com/582506 is fixed. |
| 169 CHROMEOS_SYSLOG(WARNING) << "Unregister RemoteCommandsInvalidator."; |
145 if (is_registered_) { | 170 if (is_registered_) { |
146 CHECK(invalidation_service_->UpdateRegisteredInvalidationIds( | 171 CHECK(invalidation_service_->UpdateRegisteredInvalidationIds( |
147 this, syncer::ObjectIdSet())); | 172 this, syncer::ObjectIdSet())); |
148 invalidation_service_->UnregisterInvalidationHandler(this); | 173 invalidation_service_->UnregisterInvalidationHandler(this); |
149 is_registered_ = false; | 174 is_registered_ = false; |
150 UpdateInvalidationsEnabled(); | 175 UpdateInvalidationsEnabled(); |
151 } | 176 } |
152 } | 177 } |
153 | 178 |
154 void RemoteCommandsInvalidator::UpdateInvalidationsEnabled() { | 179 void RemoteCommandsInvalidator::UpdateInvalidationsEnabled() { |
155 invalidations_enabled_ = invalidation_service_enabled_ && is_registered_; | 180 invalidations_enabled_ = invalidation_service_enabled_ && is_registered_; |
156 } | 181 } |
157 | 182 |
158 } // namespace policy | 183 } // namespace policy |
OLD | NEW |