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: components/copresence/rpc/rpc_handler.cc

Issue 704923002: Add polling and audio check to copresence. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 14
15 // TODO(ckehoe): time.h includes windows.h, which #defines DeviceCapabilities 15 // TODO(ckehoe): time.h includes windows.h, which #defines DeviceCapabilities
16 // to DeviceCapabilitiesW. This breaks the pb.h headers below. For now, 16 // to DeviceCapabilitiesW. This breaks the pb.h headers below. For now,
17 // we fix this with an #undef. 17 // we fix this with an #undef.
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #if defined(OS_WIN) 19 #if defined(OS_WIN)
20 #undef DeviceCapabilities 20 #undef DeviceCapabilities
21 #endif 21 #endif
22 22
23 #include "components/copresence/copresence_switches.h" 23 #include "components/copresence/copresence_switches.h"
24 #include "components/copresence/handlers/directive_handler.h" 24 #include "components/copresence/handlers/directive_handler.h"
25 #include "components/copresence/proto/codes.pb.h" 25 #include "components/copresence/proto/codes.pb.h"
26 #include "components/copresence/proto/data.pb.h" 26 #include "components/copresence/proto/data.pb.h"
27 #include "components/copresence/proto/rpcs.pb.h" 27 #include "components/copresence/proto/rpcs.pb.h"
28 #include "components/copresence/public/copresence_constants.h" 28 #include "components/copresence/public/copresence_constants.h"
29 #include "components/copresence/public/copresence_delegate.h" 29 #include "components/copresence/public/copresence_delegate.h"
30 #include "components/copresence/public/whispernet_client.h"
31 #include "components/copresence/rpc/http_post.h" 30 #include "components/copresence/rpc/http_post.h"
32 #include "net/http/http_status_code.h" 31 #include "net/http/http_status_code.h"
33 32
34 // TODO(ckehoe): Return error messages for bad requests. 33 // TODO(ckehoe): Return error messages for bad requests.
35 34
36 namespace copresence { 35 namespace copresence {
37 36
38 using google::protobuf::MessageLite; 37 using google::protobuf::MessageLite;
39 using google::protobuf::RepeatedPtrField; 38 using google::protobuf::RepeatedPtrField;
40 39
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 DCHECK(delegate_); 163 DCHECK(delegate_);
165 DCHECK(directive_handler_); 164 DCHECK(directive_handler_);
166 165
167 if (server_post_callback_.is_null()) { 166 if (server_post_callback_.is_null()) {
168 server_post_callback_ = 167 server_post_callback_ =
169 base::Bind(&RpcHandler::SendHttpPost, base::Unretained(this)); 168 base::Bind(&RpcHandler::SendHttpPost, base::Unretained(this));
170 } 169 }
171 } 170 }
172 171
173 RpcHandler::~RpcHandler() { 172 RpcHandler::~RpcHandler() {
174 for (HttpPost* post : pending_posts_) { 173 for (HttpPost* post : pending_posts_)
175 delete post; 174 delete post;
176 }
177
178 // TODO(ckehoe): Register and cancel these callbacks in the same class.
179 delegate_->GetWhispernetClient()->RegisterTokensCallback(
180 WhispernetClient::TokensCallback());
181 delegate_->GetWhispernetClient()->RegisterSamplesCallback(
182 WhispernetClient::SamplesCallback());
183 } 175 }
184 176
185 void RpcHandler::RegisterForToken(const std::string& auth_token, 177 void RpcHandler::RegisterForToken(const std::string& auth_token,
186 const SuccessCallback& init_done_callback) { 178 const SuccessCallback& init_done_callback) {
187 if (IsRegisteredForToken(auth_token)) { 179 if (IsRegisteredForToken(auth_token)) {
188 LOG(WARNING) << "Attempted re-registration for the same auth token."; 180 LOG(WARNING) << "Attempted re-registration for the same auth token.";
189 init_done_callback.Run(true); 181 init_done_callback.Run(true);
190 return; 182 return;
191 } 183 }
192 scoped_ptr<RegisterDeviceRequest> request(new RegisterDeviceRequest); 184 scoped_ptr<RegisterDeviceRequest> request(new RegisterDeviceRequest);
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 api_key, 509 api_key,
518 auth_token, 510 auth_token,
519 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken), 511 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken),
520 *request_proto); 512 *request_proto);
521 513
522 http_post->Start(base::Bind(callback, http_post)); 514 http_post->Start(base::Bind(callback, http_post));
523 pending_posts_.insert(http_post); 515 pending_posts_.insert(http_post);
524 } 516 }
525 517
526 } // namespace copresence 518 } // namespace copresence
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698