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

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

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

Powered by Google App Engine
This is Rietveld 408576698