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

Unified Diff: components/copresence/rpc/rpc_handler.cc

Issue 459903006: Setting OptInStateFilter for publishes and subscribes (b/16324352) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mem
Patch Set: Merging to head Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/copresence/rpc/rpc_handler_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/copresence/rpc/rpc_handler.cc
diff --git a/components/copresence/rpc/rpc_handler.cc b/components/copresence/rpc/rpc_handler.cc
index 7d89e9d310d0edbd608cffab68356d3093bafda1..c2e45bac0cd2fa618619b55ce8653f4d5600a2c2 100644
--- a/components/copresence/rpc/rpc_handler.cc
+++ b/components/copresence/rpc/rpc_handler.cc
@@ -84,6 +84,7 @@ bool ReportErrorLogged(const ReportResponse& response) {
}
// Request construction
+// TODO(ckehoe): Move these into a separate file?
template <typename T>
BroadcastScanConfiguration GetBroadcastScanConfig(const T& msg) {
@@ -119,11 +120,11 @@ BroadcastScanConfiguration ExtractTokenExchangeStrategy(
// Strategies for subscriptions.
if (request.has_manage_subscriptions_request()) {
- const RepeatedPtrField<Subscription>& messages =
+ const RepeatedPtrField<Subscription> subscriptions =
request.manage_subscriptions_request().subscription();
- for (int i = 0; i < messages.size(); ++i) {
+ for (int i = 0; i < subscriptions.size(); ++i) {
BroadcastScanConfiguration config =
- GetBroadcastScanConfig(messages.Get(i));
+ GetBroadcastScanConfig(subscriptions.Get(i));
broadcast_only = broadcast_only || config == BROADCAST_ONLY;
scan_only = scan_only || config == SCAN_ONLY;
if (config == BROADCAST_AND_SCAN || (broadcast_only && scan_only))
@@ -205,6 +206,36 @@ void AddTokenToRequest(ReportRequest* request, const AudioToken& token) {
signals->set_observed_time_millis(base::Time::Now().ToJsTime());
}
+OptInStateFilter* CreateOptedInOrOutFilter() {
+ OptInStateFilter* filter = new OptInStateFilter;
+ filter->add_allowed_opt_in_state(copresence::OPTED_IN);
+ filter->add_allowed_opt_in_state(copresence::OPTED_OUT);
+ return filter;
+}
+
+void AllowOptedOutMessages(ReportRequest* request) {
+ // TODO(ckehoe): Collapse this pattern into ProcessPublish()
+ // and ProcessSubscribe() methods.
+
+ RepeatedPtrField<PublishedMessage>* messages =
+ request->mutable_manage_messages_request()->mutable_message_to_publish();
+ for (int i = 0; i < messages->size(); ++i) {
+ PublishedMessage* message = messages->Mutable(i);
+ if (!message->has_opt_in_state_filter())
+ message->set_allocated_opt_in_state_filter(CreateOptedInOrOutFilter());
+ }
+
+ RepeatedPtrField<Subscription>* subscriptions =
+ request->mutable_manage_subscriptions_request()->mutable_subscription();
+ for (int i = 0; i < subscriptions->size(); ++i) {
+ Subscription* subscription = subscriptions->Mutable(i);
+ if (!subscription->has_opt_in_state_filter()) {
+ subscription->set_allocated_opt_in_state_filter(
+ CreateOptedInOrOutFilter());
+ }
+ }
+}
+
} // namespace
// Public methods
@@ -271,6 +302,7 @@ void RpcHandler::SendReportRequest(scoped_ptr<ReportRequest> request,
AddPlayingTokens(request.get());
+ AllowOptedOutMessages(request.get());
SendServerRequest(kReportRequestRpcName,
app_id,
request.Pass(),
« no previous file with comments | « no previous file | components/copresence/rpc/rpc_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698