| OLD | NEW | 
|---|
| 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  Loading... | 
| 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   // Do not use |directive_handler_| here, it will already have been | 
|  | 174   // destructed. | 
|  | 175   for (HttpPost* post : pending_posts_) | 
| 175     delete post; | 176     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 } | 177 } | 
| 184 | 178 | 
| 185 void RpcHandler::RegisterForToken(const std::string& auth_token, | 179 void RpcHandler::RegisterForToken(const std::string& auth_token, | 
| 186                                   const SuccessCallback& init_done_callback) { | 180                                   const SuccessCallback& init_done_callback) { | 
| 187   if (IsRegisteredForToken(auth_token)) { | 181   if (IsRegisteredForToken(auth_token)) { | 
| 188     LOG(WARNING) << "Attempted re-registration for the same auth token."; | 182     LOG(WARNING) << "Attempted re-registration for the same auth token."; | 
| 189     init_done_callback.Run(true); | 183     init_done_callback.Run(true); | 
| 190     return; | 184     return; | 
| 191   } | 185   } | 
| 192   scoped_ptr<RegisterDeviceRequest> request(new RegisterDeviceRequest); | 186   scoped_ptr<RegisterDeviceRequest> request(new RegisterDeviceRequest); | 
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 517       api_key, | 511       api_key, | 
| 518       auth_token, | 512       auth_token, | 
| 519       command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken), | 513       command_line->GetSwitchValueASCII(switches::kCopresenceTracingToken), | 
| 520       *request_proto); | 514       *request_proto); | 
| 521 | 515 | 
| 522   http_post->Start(base::Bind(callback, http_post)); | 516   http_post->Start(base::Bind(callback, http_post)); | 
| 523   pending_posts_.insert(http_post); | 517   pending_posts_.insert(http_post); | 
| 524 } | 518 } | 
| 525 | 519 | 
| 526 }  // namespace copresence | 520 }  // namespace copresence | 
| OLD | NEW | 
|---|