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 CHROMEOS_SYSLOG(WARNING) << "Initialize RemoteCommandsInvalidator."; | |
Andrew T Wilson (Slow)
2016/06/29 15:35:35
I think these are all intended to be temporary log
Marton Hunyady
2016/06/30 08:45:54
Done.
| |
30 | 32 |
31 DCHECK(invalidation_service); | 33 DCHECK(invalidation_service); |
32 invalidation_service_ = invalidation_service; | 34 invalidation_service_ = invalidation_service; |
33 | 35 |
34 state_ = STOPPED; | 36 state_ = STOPPED; |
35 OnInitialize(); | 37 OnInitialize(); |
36 } | 38 } |
37 | 39 |
38 void RemoteCommandsInvalidator::Shutdown() { | 40 void RemoteCommandsInvalidator::Shutdown() { |
39 DCHECK_NE(SHUT_DOWN, state_); | 41 DCHECK_NE(SHUT_DOWN, state_); |
40 DCHECK(thread_checker_.CalledOnValidThread()); | 42 DCHECK(thread_checker_.CalledOnValidThread()); |
43 CHROMEOS_SYSLOG(WARNING) << "Shutdown RemoteCommandsInvalidator."; | |
41 | 44 |
42 Stop(); | 45 Stop(); |
43 | 46 |
44 state_ = SHUT_DOWN; | 47 state_ = SHUT_DOWN; |
45 OnShutdown(); | 48 OnShutdown(); |
46 } | 49 } |
47 | 50 |
48 void RemoteCommandsInvalidator::Start() { | 51 void RemoteCommandsInvalidator::Start() { |
49 DCHECK_EQ(STOPPED, state_); | 52 DCHECK_EQ(STOPPED, state_); |
50 DCHECK(thread_checker_.CalledOnValidThread()); | 53 DCHECK(thread_checker_.CalledOnValidThread()); |
54 CHROMEOS_SYSLOG(WARNING) << "Starting RemoteCommandsInvalidator."; | |
55 | |
51 state_ = STARTED; | 56 state_ = STARTED; |
52 | 57 |
53 OnStart(); | 58 OnStart(); |
54 } | 59 } |
55 | 60 |
56 void RemoteCommandsInvalidator::Stop() { | 61 void RemoteCommandsInvalidator::Stop() { |
57 DCHECK_NE(SHUT_DOWN, state_); | 62 DCHECK_NE(SHUT_DOWN, state_); |
58 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
64 CHROMEOS_SYSLOG(WARNING) << "Stopping RemoteCommandsInvalidator."; | |
59 | 65 |
60 if (state_ == STARTED) { | 66 if (state_ == STARTED) { |
61 Unregister(); | 67 Unregister(); |
62 state_ = STOPPED; | 68 state_ = STOPPED; |
63 | 69 |
64 OnStop(); | 70 OnStop(); |
65 } | 71 } |
66 } | 72 } |
67 | 73 |
68 void RemoteCommandsInvalidator::OnInvalidatorStateChange( | 74 void RemoteCommandsInvalidator::OnInvalidatorStateChange( |
69 syncer::InvalidatorState state) { | 75 syncer::InvalidatorState state) { |
70 DCHECK_EQ(STARTED, state_); | 76 DCHECK_EQ(STARTED, state_); |
71 DCHECK(thread_checker_.CalledOnValidThread()); | 77 DCHECK(thread_checker_.CalledOnValidThread()); |
78 CHROMEOS_SYSLOG(WARNING) << "RemoteCommandsInvalidator state changed: " | |
79 << state; | |
72 | 80 |
73 invalidation_service_enabled_ = state == syncer::INVALIDATIONS_ENABLED; | 81 invalidation_service_enabled_ = state == syncer::INVALIDATIONS_ENABLED; |
74 UpdateInvalidationsEnabled(); | 82 UpdateInvalidationsEnabled(); |
75 } | 83 } |
76 | 84 |
77 void RemoteCommandsInvalidator::OnIncomingInvalidation( | 85 void RemoteCommandsInvalidator::OnIncomingInvalidation( |
78 const syncer::ObjectIdInvalidationMap& invalidation_map) { | 86 const syncer::ObjectIdInvalidationMap& invalidation_map) { |
79 DCHECK_EQ(STARTED, state_); | 87 DCHECK_EQ(STARTED, state_); |
80 DCHECK(thread_checker_.CalledOnValidThread()); | 88 DCHECK(thread_checker_.CalledOnValidThread()); |
89 CHROMEOS_SYSLOG(WARNING) | |
90 << "RemoteCommandsInvalidator received invalidation."; | |
81 | 91 |
82 if (!invalidation_service_enabled_) | 92 if (!invalidation_service_enabled_) |
83 LOG(WARNING) << "Unexpected invalidation received."; | 93 LOG(WARNING) << "Unexpected invalidation received."; |
84 | 94 |
85 const syncer::SingleObjectInvalidationSet& list = | 95 const syncer::SingleObjectInvalidationSet& list = |
86 invalidation_map.ForObject(object_id_); | 96 invalidation_map.ForObject(object_id_); |
87 if (list.IsEmpty()) { | 97 if (list.IsEmpty()) { |
88 NOTREACHED(); | 98 NOTREACHED(); |
89 return; | 99 return; |
90 } | 100 } |
91 | 101 |
92 // Acknowledge all invalidations. | 102 // Acknowledge all invalidations. |
93 for (const auto& it : list) | 103 for (const auto& it : list) |
94 it.Acknowledge(); | 104 it.Acknowledge(); |
jinzhang1
2016/06/29 16:47:56
Can we add a log statement here to make sure "DoRe
Marton Hunyady
2016/06/30 08:45:54
Done.
| |
95 | 105 |
96 DoRemoteCommandsFetch(); | 106 DoRemoteCommandsFetch(); |
97 } | 107 } |
98 | 108 |
99 std::string RemoteCommandsInvalidator::GetOwnerName() const { | 109 std::string RemoteCommandsInvalidator::GetOwnerName() const { |
100 return "RemoteCommands"; | 110 return "RemoteCommands"; |
101 } | 111 } |
102 | 112 |
103 void RemoteCommandsInvalidator::ReloadPolicyData( | 113 void RemoteCommandsInvalidator::ReloadPolicyData( |
104 const enterprise_management::PolicyData* policy) { | 114 const enterprise_management::PolicyData* policy) { |
105 DCHECK(thread_checker_.CalledOnValidThread()); | 115 DCHECK(thread_checker_.CalledOnValidThread()); |
116 CHROMEOS_SYSLOG(WARNING) << "RemoteCommandsInvalidator ReloadPolicyData."; | |
106 | 117 |
107 if (state_ != STARTED) | 118 if (state_ != STARTED) |
108 return; | 119 return; |
109 | 120 |
110 // Create the ObjectId based on the policy data. | 121 // Create the ObjectId based on the policy data. |
111 // If the policy does not specify an the ObjectId, then unregister. | 122 // If the policy does not specify an the ObjectId, then unregister. |
112 if (!policy || !policy->has_command_invalidation_source() || | 123 if (!policy || !policy->has_command_invalidation_source() || |
113 !policy->has_command_invalidation_name()) { | 124 !policy->has_command_invalidation_name()) { |
114 Unregister(); | 125 Unregister(); |
115 return; | 126 return; |
116 } | 127 } |
117 const invalidation::ObjectId object_id(policy->command_invalidation_source(), | 128 const invalidation::ObjectId object_id(policy->command_invalidation_source(), |
118 policy->command_invalidation_name()); | 129 policy->command_invalidation_name()); |
119 | 130 |
120 // If the policy object id in the policy data is different from the currently | 131 // If the policy object id in the policy data is different from the currently |
121 // registered object id, update the object registration. | 132 // registered object id, update the object registration. |
122 if (!is_registered_ || !(object_id == object_id_)) | 133 if (!is_registered_ || !(object_id == object_id_)) |
123 Register(object_id); | 134 Register(object_id); |
124 } | 135 } |
125 | 136 |
126 void RemoteCommandsInvalidator::Register( | 137 void RemoteCommandsInvalidator::Register( |
127 const invalidation::ObjectId& object_id) { | 138 const invalidation::ObjectId& object_id) { |
139 CHROMEOS_SYSLOG(WARNING) << "Register RemoteCommandsInvalidator."; | |
140 | |
128 // Register this handler with the invalidation service if needed. | 141 // Register this handler with the invalidation service if needed. |
129 if (!is_registered_) { | 142 if (!is_registered_) { |
130 OnInvalidatorStateChange(invalidation_service_->GetInvalidatorState()); | 143 OnInvalidatorStateChange(invalidation_service_->GetInvalidatorState()); |
131 invalidation_service_->RegisterInvalidationHandler(this); | 144 invalidation_service_->RegisterInvalidationHandler(this); |
132 is_registered_ = true; | 145 is_registered_ = true; |
133 } | 146 } |
134 | 147 |
135 object_id_ = object_id; | 148 object_id_ = object_id; |
136 UpdateInvalidationsEnabled(); | 149 UpdateInvalidationsEnabled(); |
137 | 150 |
138 // Update registration with the invalidation service. | 151 // Update registration with the invalidation service. |
139 syncer::ObjectIdSet ids; | 152 syncer::ObjectIdSet ids; |
140 ids.insert(object_id); | 153 ids.insert(object_id); |
141 CHECK(invalidation_service_->UpdateRegisteredInvalidationIds(this, ids)); | 154 CHECK(invalidation_service_->UpdateRegisteredInvalidationIds(this, ids)); |
142 } | 155 } |
143 | 156 |
144 void RemoteCommandsInvalidator::Unregister() { | 157 void RemoteCommandsInvalidator::Unregister() { |
158 CHROMEOS_SYSLOG(WARNING) << "Unregister RemoteCommandsInvalidator."; | |
145 if (is_registered_) { | 159 if (is_registered_) { |
146 CHECK(invalidation_service_->UpdateRegisteredInvalidationIds( | 160 CHECK(invalidation_service_->UpdateRegisteredInvalidationIds( |
147 this, syncer::ObjectIdSet())); | 161 this, syncer::ObjectIdSet())); |
148 invalidation_service_->UnregisterInvalidationHandler(this); | 162 invalidation_service_->UnregisterInvalidationHandler(this); |
149 is_registered_ = false; | 163 is_registered_ = false; |
150 UpdateInvalidationsEnabled(); | 164 UpdateInvalidationsEnabled(); |
151 } | 165 } |
152 } | 166 } |
153 | 167 |
154 void RemoteCommandsInvalidator::UpdateInvalidationsEnabled() { | 168 void RemoteCommandsInvalidator::UpdateInvalidationsEnabled() { |
155 invalidations_enabled_ = invalidation_service_enabled_ && is_registered_; | 169 invalidations_enabled_ = invalidation_service_enabled_ && is_registered_; |
156 } | 170 } |
157 | 171 |
158 } // namespace policy | 172 } // namespace policy |
OLD | NEW |