OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/copresence/rpc/rpc_handler.h" | 5 #include "components/copresence/rpc/rpc_handler.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 GetBroadcastScanConfig(messages.Get(i)); | 112 GetBroadcastScanConfig(messages.Get(i)); |
113 broadcast_only = broadcast_only || config == BROADCAST_ONLY; | 113 broadcast_only = broadcast_only || config == BROADCAST_ONLY; |
114 scan_only = scan_only || config == SCAN_ONLY; | 114 scan_only = scan_only || config == SCAN_ONLY; |
115 if (config == BROADCAST_AND_SCAN || (broadcast_only && scan_only)) | 115 if (config == BROADCAST_AND_SCAN || (broadcast_only && scan_only)) |
116 return BROADCAST_AND_SCAN; | 116 return BROADCAST_AND_SCAN; |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 // Strategies for subscriptions. | 120 // Strategies for subscriptions. |
121 if (request.has_manage_subscriptions_request()) { | 121 if (request.has_manage_subscriptions_request()) { |
122 const RepeatedPtrField<Subscription> messages = | 122 const RepeatedPtrField<Subscription> subscriptions = |
123 request.manage_subscriptions_request().subscription(); | 123 request.manage_subscriptions_request().subscription(); |
124 for (int i = 0; i < messages.size(); ++i) { | 124 for (int i = 0; i < subscriptions.size(); ++i) { |
125 BroadcastScanConfiguration config = | 125 BroadcastScanConfiguration config = |
126 GetBroadcastScanConfig(messages.Get(i)); | 126 GetBroadcastScanConfig(subscriptions.Get(i)); |
127 broadcast_only = broadcast_only || config == BROADCAST_ONLY; | 127 broadcast_only = broadcast_only || config == BROADCAST_ONLY; |
128 scan_only = scan_only || config == SCAN_ONLY; | 128 scan_only = scan_only || config == SCAN_ONLY; |
129 if (config == BROADCAST_AND_SCAN || (broadcast_only && scan_only)) | 129 if (config == BROADCAST_AND_SCAN || (broadcast_only && scan_only)) |
130 return BROADCAST_AND_SCAN; | 130 return BROADCAST_AND_SCAN; |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 if (broadcast_only) | 134 if (broadcast_only) |
135 return BROADCAST_ONLY; | 135 return BROADCAST_ONLY; |
136 if (scan_only) | 136 if (scan_only) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 ClientVersion* CreateVersion(const std::string& client, | 187 ClientVersion* CreateVersion(const std::string& client, |
188 const std::string& version_name) { | 188 const std::string& version_name) { |
189 ClientVersion* version = new ClientVersion; | 189 ClientVersion* version = new ClientVersion; |
190 | 190 |
191 version->set_client(client); | 191 version->set_client(client); |
192 version->set_version_name(version_name); | 192 version->set_version_name(version_name); |
193 | 193 |
194 return version; | 194 return version; |
195 } | 195 } |
196 | 196 |
197 OptInStateFilter* CreateOptedInOrOutFilter() { | |
198 OptInStateFilter* filter = new OptInStateFilter; | |
199 filter->add_allowed_opt_in_state(copresence::OPTED_IN); | |
200 filter->add_allowed_opt_in_state(copresence::OPTED_OUT); | |
201 return filter; | |
202 } | |
203 | |
204 void AllowOptedOutMessages(ReportRequest* request) { | |
rkc
2014/08/12 03:38:19
This anonymous namespace is getting huge. We shoul
Charlie
2014/08/12 04:36:14
Added a TODO. Keep in mind that ExtractTokenExchan
| |
205 RepeatedPtrField<PublishedMessage>* messages = | |
rkc
2014/08/12 03:38:19
This is a pattern that we'll be following 3 places
Charlie
2014/08/12 04:36:14
Another TODO. I think Ben probably doesn't want to
| |
206 request->mutable_manage_messages_request()->mutable_message_to_publish(); | |
207 for (int i = 0; i < messages->size(); ++i) { | |
208 PublishedMessage* message = messages->Mutable(i); | |
209 if (!message->has_opt_in_state_filter()) | |
210 message->set_allocated_opt_in_state_filter(CreateOptedInOrOutFilter()); | |
211 } | |
212 | |
213 RepeatedPtrField<Subscription>* subscriptions = | |
214 request->mutable_manage_subscriptions_request()->mutable_subscription(); | |
215 for (int i = 0; i < subscriptions->size(); ++i) { | |
216 Subscription* subscription = subscriptions->Mutable(i); | |
217 if (!subscription->has_opt_in_state_filter()) { | |
218 subscription->set_allocated_opt_in_state_filter( | |
219 CreateOptedInOrOutFilter()); | |
220 } | |
221 } | |
222 } | |
223 | |
197 } // namespace | 224 } // namespace |
198 | 225 |
199 // Public methods | 226 // Public methods |
200 | 227 |
201 RpcHandler::RpcHandler(CopresenceClientDelegate* delegate) | 228 RpcHandler::RpcHandler(CopresenceClientDelegate* delegate) |
202 : delegate_(delegate), | 229 : delegate_(delegate), |
203 invalid_audio_token_cache_( | 230 invalid_audio_token_cache_( |
204 base::TimeDelta::FromMilliseconds(kInvalidTokenExpiryTimeMs), | 231 base::TimeDelta::FromMilliseconds(kInvalidTokenExpiryTimeMs), |
205 kMaxInvalidTokens), | 232 kMaxInvalidTokens), |
206 server_post_callback_(base::Bind(&RpcHandler::SendHttpPost, | 233 server_post_callback_(base::Bind(&RpcHandler::SendHttpPost, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 const StatusCallback& status_callback) { | 273 const StatusCallback& status_callback) { |
247 DCHECK(request.get()); | 274 DCHECK(request.get()); |
248 DCHECK(!device_id_.empty()) | 275 DCHECK(!device_id_.empty()) |
249 << "RpcHandler::Initialize() must complete successfully " | 276 << "RpcHandler::Initialize() must complete successfully " |
250 << "before other RpcHandler methods are called."; | 277 << "before other RpcHandler methods are called."; |
251 | 278 |
252 DVLOG(3) << "Sending report request to server."; | 279 DVLOG(3) << "Sending report request to server."; |
253 | 280 |
254 request->mutable_update_signals_request()->set_allocated_state( | 281 request->mutable_update_signals_request()->set_allocated_state( |
255 GetDeviceCapabilities(*request).release()); | 282 GetDeviceCapabilities(*request).release()); |
283 AllowOptedOutMessages(request.get()); | |
256 SendServerRequest(kReportRequestRpcName, | 284 SendServerRequest(kReportRequestRpcName, |
257 app_id, | 285 app_id, |
258 request.Pass(), | 286 request.Pass(), |
259 // On destruction, this request will be cancelled. | 287 // On destruction, this request will be cancelled. |
260 base::Bind(&RpcHandler::ReportResponseHandler, | 288 base::Bind(&RpcHandler::ReportResponseHandler, |
261 base::Unretained(this), | 289 base::Unretained(this), |
262 status_callback)); | 290 status_callback)); |
263 } | 291 } |
264 | 292 |
265 void RpcHandler::ReportTokens(const std::vector<FullToken>& tokens) { | 293 void RpcHandler::ReportTokens(const std::vector<FullToken>& tokens) { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 bool audible, | 528 bool audible, |
501 const WhispernetClient::SamplesCallback& samples_callback) { | 529 const WhispernetClient::SamplesCallback& samples_callback) { |
502 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient(); | 530 WhispernetClient* whispernet_client = delegate_->GetWhispernetClient(); |
503 if (whispernet_client) { | 531 if (whispernet_client) { |
504 whispernet_client->RegisterSamplesCallback(samples_callback); | 532 whispernet_client->RegisterSamplesCallback(samples_callback); |
505 whispernet_client->EncodeToken(token, audible); | 533 whispernet_client->EncodeToken(token, audible); |
506 } | 534 } |
507 } | 535 } |
508 | 536 |
509 } // namespace copresence | 537 } // namespace copresence |
OLD | NEW |