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

Side by Side Diff: components/copresence/rpc/rpc_handler.cc

Issue 685983007: RpcHandlerTest cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updating TODO Created 6 years, 1 month 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 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 signals->set_medium(token.audible ? AUDIO_AUDIBLE_DTMF 146 signals->set_medium(token.audible ? AUDIO_AUDIBLE_DTMF
147 : AUDIO_ULTRASOUND_PASSBAND); 147 : AUDIO_ULTRASOUND_PASSBAND);
148 signals->set_observed_time_millis(base::Time::Now().ToJsTime()); 148 signals->set_observed_time_millis(base::Time::Now().ToJsTime());
149 } 149 }
150 150
151 } // namespace 151 } // namespace
152 152
153 // Public methods 153 // Public methods
154 154
155 RpcHandler::RpcHandler(CopresenceDelegate* delegate, 155 RpcHandler::RpcHandler(CopresenceDelegate* delegate,
156 DirectiveHandler* directive_handler) 156 DirectiveHandler* directive_handler,
157 const PostCallback& server_post_callback)
157 : delegate_(delegate), 158 : delegate_(delegate),
158 directive_handler_(directive_handler), 159 directive_handler_(directive_handler),
159 invalid_audio_token_cache_( 160 invalid_audio_token_cache_(
160 base::TimeDelta::FromMilliseconds(kInvalidTokenExpiryTimeMs), 161 base::TimeDelta::FromMilliseconds(kInvalidTokenExpiryTimeMs),
161 kMaxInvalidTokens), 162 kMaxInvalidTokens),
162 server_post_callback_(base::Bind(&RpcHandler::SendHttpPost, 163 server_post_callback_(server_post_callback) {
163 base::Unretained(this))) {
164 DCHECK(delegate_); 164 DCHECK(delegate_);
165 DCHECK(directive_handler_); 165 DCHECK(directive_handler_);
166
167 if (server_post_callback_.is_null()) {
168 server_post_callback_ =
169 base::Bind(&RpcHandler::SendHttpPost, base::Unretained(this));
170 }
166 } 171 }
167 172
168 RpcHandler::~RpcHandler() { 173 RpcHandler::~RpcHandler() {
169 for (HttpPost* post : pending_posts_) { 174 for (HttpPost* post : pending_posts_) {
170 delete post; 175 delete post;
171 } 176 }
172 177
173 if (delegate_->GetWhispernetClient()) { 178 // TODO(ckehoe): Register and cancel these callbacks in the same class.
174 // TODO(ckehoe): Use CancelableCallbacks instead. 179 delegate_->GetWhispernetClient()->RegisterTokensCallback(
175 delegate_->GetWhispernetClient()->RegisterTokensCallback( 180 WhispernetClient::TokensCallback());
176 WhispernetClient::TokensCallback()); 181 delegate_->GetWhispernetClient()->RegisterSamplesCallback(
177 delegate_->GetWhispernetClient()->RegisterSamplesCallback( 182 WhispernetClient::SamplesCallback());
178 WhispernetClient::SamplesCallback());
179 }
180 } 183 }
181 184
182 void RpcHandler::RegisterForToken(const std::string& auth_token, 185 void RpcHandler::RegisterForToken(const std::string& auth_token,
183 const SuccessCallback& init_done_callback) { 186 const SuccessCallback& init_done_callback) {
184 if (IsRegisteredForToken(auth_token)) { 187 if (IsRegisteredForToken(auth_token)) {
185 LOG(WARNING) << "Attempted re-registration for the same auth token."; 188 LOG(WARNING) << "Attempted re-registration for the same auth token.";
186 init_done_callback.Run(true); 189 init_done_callback.Run(true);
187 return; 190 return;
188 } 191 }
189 scoped_ptr<RegisterDeviceRequest> request(new RegisterDeviceRequest); 192 scoped_ptr<RegisterDeviceRequest> request(new RegisterDeviceRequest);
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 api_key, 517 api_key,
515 auth_token, 518 auth_token,
516 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken), 519 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken),
517 *request_proto); 520 *request_proto);
518 521
519 http_post->Start(base::Bind(callback, http_post)); 522 http_post->Start(base::Bind(callback, http_post));
520 pending_posts_.insert(http_post); 523 pending_posts_.insert(http_post);
521 } 524 }
522 525
523 } // namespace copresence 526 } // namespace copresence
OLDNEW
« no previous file with comments | « components/copresence/rpc/rpc_handler.h ('k') | components/copresence/rpc/rpc_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698