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

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

Issue 764673003: Adding CopresenceState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 13
14 // TODO(ckehoe): time.h includes windows.h, which #defines DeviceCapabilities 14 // TODO(ckehoe): time.h includes windows.h, which #defines DeviceCapabilities
15 // to DeviceCapabilitiesW. This breaks the pb.h headers below. For now, 15 // to DeviceCapabilitiesW. This breaks the pb.h headers below. For now,
16 // we fix this with an #undef. 16 // we fix this with an #undef.
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #if defined(OS_WIN) 18 #if defined(OS_WIN)
19 #undef DeviceCapabilities 19 #undef DeviceCapabilities
20 #endif 20 #endif
21 21
22 #include "components/copresence/copresence_state_impl.h"
22 #include "components/copresence/copresence_switches.h" 23 #include "components/copresence/copresence_switches.h"
23 #include "components/copresence/handlers/directive_handler.h" 24 #include "components/copresence/handlers/directive_handler.h"
24 #include "components/copresence/handlers/gcm_handler.h" 25 #include "components/copresence/handlers/gcm_handler.h"
25 #include "components/copresence/proto/codes.pb.h" 26 #include "components/copresence/proto/codes.pb.h"
26 #include "components/copresence/proto/data.pb.h" 27 #include "components/copresence/proto/data.pb.h"
27 #include "components/copresence/proto/rpcs.pb.h" 28 #include "components/copresence/proto/rpcs.pb.h"
28 #include "components/copresence/public/copresence_constants.h" 29 #include "components/copresence/public/copresence_constants.h"
29 #include "components/copresence/public/copresence_delegate.h" 30 #include "components/copresence/public/copresence_delegate.h"
30 #include "components/copresence/rpc/http_post.h" 31 #include "components/copresence/rpc/http_post.h"
31 #include "net/http/http_status_code.h" 32 #include "net/http/http_status_code.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 : AUDIO_ULTRASOUND_PASSBAND); 159 : AUDIO_ULTRASOUND_PASSBAND);
159 signals->set_observed_time_millis(base::Time::Now().ToJsTime()); 160 signals->set_observed_time_millis(base::Time::Now().ToJsTime());
160 } 161 }
161 162
162 } // namespace 163 } // namespace
163 164
164 165
165 // Public functions. 166 // Public functions.
166 167
167 RpcHandler::RpcHandler(CopresenceDelegate* delegate, 168 RpcHandler::RpcHandler(CopresenceDelegate* delegate,
169 CopresenceStateImpl* state,
168 DirectiveHandler* directive_handler, 170 DirectiveHandler* directive_handler,
169 GCMHandler* gcm_handler, 171 GCMHandler* gcm_handler,
170 const PostCallback& server_post_callback) 172 const PostCallback& server_post_callback)
171 : delegate_(delegate), 173 : delegate_(delegate),
174 state_(state),
172 directive_handler_(directive_handler), 175 directive_handler_(directive_handler),
173 gcm_handler_(gcm_handler), 176 gcm_handler_(gcm_handler),
174 server_post_callback_(server_post_callback), 177 server_post_callback_(server_post_callback),
175 invalid_audio_token_cache_( 178 invalid_audio_token_cache_(
176 base::TimeDelta::FromMilliseconds(kInvalidTokenExpiryTimeMs), 179 base::TimeDelta::FromMilliseconds(kInvalidTokenExpiryTimeMs),
177 kMaxInvalidTokens) { 180 kMaxInvalidTokens) {
178 DCHECK(delegate_); 181 DCHECK(delegate_);
179 DCHECK(directive_handler_); 182 DCHECK(directive_handler_);
180 // |gcm_handler_| is optional. 183 // |gcm_handler_| is optional.
181 184
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 487
485 if (response.has_update_signals_response()) { 488 if (response.has_update_signals_response()) {
486 const UpdateSignalsResponse& update_response = 489 const UpdateSignalsResponse& update_response =
487 response.update_signals_response(); 490 response.update_signals_response();
488 DispatchMessages(update_response.message()); 491 DispatchMessages(update_response.message());
489 492
490 for (const Directive& directive : update_response.directive()) 493 for (const Directive& directive : update_response.directive())
491 directive_handler_->AddDirective(directive); 494 directive_handler_->AddDirective(directive);
492 495
493 for (const Token& token : update_response.token()) { 496 for (const Token& token : update_response.token()) {
497 state_->UpdateTokenStatus(token.id(), token.status());
494 switch (token.status()) { 498 switch (token.status()) {
495 case VALID: 499 case VALID:
496 // TODO(rkc/ckehoe): Store the token in a |valid_token_cache_| with a 500 // TODO(rkc/ckehoe): Store the token in a |valid_token_cache_| with a
497 // short TTL (like 10s) and send it up with every report request. 501 // short TTL (like 10s) and send it up with every report request.
498 // Then we'll still get messages while we're waiting to hear it again. 502 // Then we'll still get messages while we're waiting to hear it again.
499 VLOG(1) << "Got valid token " << token.id(); 503 VLOG(1) << "Got valid token " << token.id();
500 break; 504 break;
501 case INVALID: 505 case INVALID:
502 DVLOG(3) << "Discarding invalid token " << token.id(); 506 DVLOG(3) << "Discarding invalid token " << token.id();
503 invalid_audio_token_cache_.Add(token.id(), true); 507 invalid_audio_token_cache_.Add(token.id(), true);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 api_key, 636 api_key,
633 auth_token, 637 auth_token,
634 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken), 638 command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken),
635 *request_proto); 639 *request_proto);
636 640
637 http_post->Start(base::Bind(callback, http_post)); 641 http_post->Start(base::Bind(callback, http_post));
638 pending_posts_.insert(http_post); 642 pending_posts_.insert(http_post);
639 } 643 }
640 644
641 } // namespace copresence 645 } // 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