| Index: components/copresence/rpc/rpc_handler.cc
|
| diff --git a/components/copresence/rpc/rpc_handler.cc b/components/copresence/rpc/rpc_handler.cc
|
| index 5b59a6431860d96a799a6721678cb7802e263a28..7c4d121f77444164bb3109dac558a1036747259b 100644
|
| --- a/components/copresence/rpc/rpc_handler.cc
|
| +++ b/components/copresence/rpc/rpc_handler.cc
|
| @@ -159,9 +159,8 @@ RpcHandler::RpcHandler(CopresenceDelegate* delegate)
|
| base::Unretained(this))) {}
|
|
|
| RpcHandler::~RpcHandler() {
|
| - for (std::set<HttpPost*>::iterator post = pending_posts_.begin();
|
| - post != pending_posts_.end(); ++post) {
|
| - delete *post;
|
| + for (HttpPost* post : pending_posts_) {
|
| + delete post;
|
| }
|
|
|
| if (delegate_ && delegate_->GetWhispernetClient()) {
|
| @@ -225,11 +224,11 @@ void RpcHandler::ReportTokens(const std::vector<AudioToken>& tokens) {
|
| DCHECK(!tokens.empty());
|
|
|
| scoped_ptr<ReportRequest> request(new ReportRequest);
|
| - for (size_t i = 0; i < tokens.size(); ++i) {
|
| - if (invalid_audio_token_cache_.HasKey(ToUrlSafe(tokens[i].token)))
|
| + for (const AudioToken& token : tokens) {
|
| + if (invalid_audio_token_cache_.HasKey(ToUrlSafe(token.token)))
|
| continue;
|
| - DVLOG(3) << "Sending token " << tokens[i].token << " to server.";
|
| - AddTokenToRequest(request.get(), tokens[i]);
|
| + DVLOG(3) << "Sending token " << token.token << " to server.";
|
| + AddTokenToRequest(request.get(), token);
|
| }
|
| SendReportRequest(request.Pass());
|
| }
|
| @@ -315,18 +314,14 @@ void RpcHandler::ReportResponseHandler(const StatusCallback& status_callback,
|
| return;
|
| }
|
|
|
| - const RepeatedPtrField<MessageResult>& message_results =
|
| - response.manage_messages_response().published_message_result();
|
| - for (int i = 0; i < message_results.size(); ++i) {
|
| - DVLOG(2) << "Published message with id "
|
| - << message_results.Get(i).published_message_id();
|
| + for (const MessageResult& result :
|
| + response.manage_messages_response().published_message_result()) {
|
| + DVLOG(2) << "Published message with id " << result.published_message_id();
|
| }
|
|
|
| - const RepeatedPtrField<SubscriptionResult>& subscription_results =
|
| - response.manage_subscriptions_response().subscription_result();
|
| - for (int i = 0; i < subscription_results.size(); ++i) {
|
| - DVLOG(2) << "Created subscription with id "
|
| - << subscription_results.Get(i).subscription_id();
|
| + for (const SubscriptionResult& result :
|
| + response.manage_subscriptions_response().subscription_result()) {
|
| + DVLOG(2) << "Created subscription with id " << result.subscription_id();
|
| }
|
|
|
| if (response.has_update_signals_response()) {
|
| @@ -335,28 +330,27 @@ void RpcHandler::ReportResponseHandler(const StatusCallback& status_callback,
|
| DispatchMessages(update_response.message());
|
|
|
| if (directive_handler_.get()) {
|
| - for (int i = 0; i < update_response.directive_size(); ++i)
|
| - directive_handler_->AddDirective(update_response.directive(i));
|
| + for (const Directive& directive : update_response.directive())
|
| + directive_handler_->AddDirective(directive);
|
| } else {
|
| DVLOG(1) << "No directive handler.";
|
| }
|
|
|
| - const RepeatedPtrField<Token>& tokens = update_response.token();
|
| - for (int i = 0; i < tokens.size(); ++i) {
|
| - switch (tokens.Get(i).status()) {
|
| + for (const Token& token : update_response.token()) {
|
| + switch (token.status()) {
|
| case VALID:
|
| // TODO(rkc/ckehoe): Store the token in a |valid_token_cache_| with a
|
| // short TTL (like 10s) and send it up with every report request.
|
| // Then we'll still get messages while we're waiting to hear it again.
|
| - VLOG(1) << "Got valid token " << tokens.Get(i).id();
|
| + VLOG(1) << "Got valid token " << token.id();
|
| break;
|
| case INVALID:
|
| - DVLOG(3) << "Discarding invalid token " << tokens.Get(i).id();
|
| - invalid_audio_token_cache_.Add(tokens.Get(i).id(), true);
|
| + DVLOG(3) << "Discarding invalid token " << token.id();
|
| + invalid_audio_token_cache_.Add(token.id(), true);
|
| break;
|
| default:
|
| - DVLOG(2) << "Token " << tokens.Get(i).id() << " has status code "
|
| - << tokens.Get(i).status();
|
| + DVLOG(2) << "Token " << token.id() << " has status code "
|
| + << token.status();
|
| }
|
| }
|
| }
|
| @@ -369,18 +363,18 @@ void RpcHandler::ReportResponseHandler(const StatusCallback& status_callback,
|
| void RpcHandler::ProcessRemovedOperations(const ReportRequest& request) {
|
| // Remove unpublishes.
|
| if (request.has_manage_messages_request()) {
|
| - const RepeatedPtrField<std::string>& unpublishes =
|
| - request.manage_messages_request().id_to_unpublish();
|
| - for (int i = 0; i < unpublishes.size(); ++i)
|
| - directive_handler_->RemoveDirectives(unpublishes.Get(i));
|
| + for (const std::string& unpublish :
|
| + request.manage_messages_request().id_to_unpublish()) {
|
| + directive_handler_->RemoveDirectives(unpublish);
|
| + }
|
| }
|
|
|
| // Remove unsubscribes.
|
| if (request.has_manage_subscriptions_request()) {
|
| - const RepeatedPtrField<std::string>& unsubscribes =
|
| - request.manage_subscriptions_request().id_to_unsubscribe();
|
| - for (int i = 0; i < unsubscribes.size(); ++i)
|
| - directive_handler_->RemoveDirectives(unsubscribes.Get(i));
|
| + for (const std::string& unsubscribe :
|
| + request.manage_subscriptions_request().id_to_unsubscribe()) {
|
| + directive_handler_->RemoveDirectives(unsubscribe);
|
| + }
|
| }
|
| }
|
|
|
| @@ -406,23 +400,20 @@ void RpcHandler::DispatchMessages(
|
| // Index the messages by subscription id.
|
| std::map<std::string, std::vector<Message>> messages_by_subscription;
|
| DVLOG(3) << "Dispatching " << messages.size() << " messages";
|
| - for (int m = 0; m < messages.size(); ++m) {
|
| - const RepeatedPtrField<std::string>& subscription_ids =
|
| - messages.Get(m).subscription_id();
|
| - for (int s = 0; s < subscription_ids.size(); ++s) {
|
| - messages_by_subscription[subscription_ids.Get(s)].push_back(
|
| - messages.Get(m).published_message());
|
| + for (const SubscribedMessage& message : messages) {
|
| + for (const std::string& subscription_id : message.subscription_id()) {
|
| + messages_by_subscription[subscription_id].push_back(
|
| + message.published_message());
|
| }
|
| }
|
|
|
| // Send the messages for each subscription.
|
| - for (std::map<std::string, std::vector<Message>>::const_iterator
|
| - subscription = messages_by_subscription.begin();
|
| - subscription != messages_by_subscription.end();
|
| - ++subscription) {
|
| + for (const auto& map_entry : messages_by_subscription) {
|
| // TODO(ckehoe): Once we have the app ID from the server, we need to pass
|
| // it in here and get rid of the app id registry from the main API class.
|
| - delegate_->HandleMessages("", subscription->first, subscription->second);
|
| + const std::string& subscription = map_entry.first;
|
| + const std::vector<Message>& messages = map_entry.second;
|
| + delegate_->HandleMessages("", subscription, messages);
|
| }
|
| }
|
|
|
|
|