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

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

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