OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/api/cast_channel/cast_socket.h" | 5 #include "extensions/browser/api/cast_channel/cast_socket.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/numerics/safe_conversions.h" | 13 #include "base/numerics/safe_conversions.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/sys_byteorder.h" | 15 #include "base/sys_byteorder.h" |
16 #include "chrome/browser/extensions/api/cast_channel/cast_auth_util.h" | 16 #include "extensions/browser/api/cast_channel/cast_auth_util.h" |
17 #include "chrome/browser/extensions/api/cast_channel/cast_channel.pb.h" | 17 #include "extensions/browser/api/cast_channel/cast_channel.pb.h" |
18 #include "chrome/browser/extensions/api/cast_channel/cast_message_util.h" | 18 #include "extensions/browser/api/cast_channel/cast_message_util.h" |
19 #include "net/base/address_list.h" | 19 #include "net/base/address_list.h" |
20 #include "net/base/host_port_pair.h" | 20 #include "net/base/host_port_pair.h" |
21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
22 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
23 #include "net/cert/cert_verifier.h" | 23 #include "net/cert/cert_verifier.h" |
24 #include "net/cert/x509_certificate.h" | 24 #include "net/cert/x509_certificate.h" |
25 #include "net/http/transport_security_state.h" | 25 #include "net/http/transport_security_state.h" |
26 #include "net/socket/client_socket_factory.h" | 26 #include "net/socket/client_socket_factory.h" |
27 #include "net/socket/client_socket_handle.h" | 27 #include "net/socket/client_socket_handle.h" |
28 #include "net/socket/ssl_client_socket.h" | 28 #include "net/socket/ssl_client_socket.h" |
(...skipping 13 matching lines...) Expand all Loading... |
42 // the socket is idle for this length of time, and the socket will be closed | 42 // the socket is idle for this length of time, and the socket will be closed |
43 // after 9 failed probes. So the total idle time before close is 10 * | 43 // after 9 failed probes. So the total idle time before close is 10 * |
44 // kTcpKeepAliveDelaySecs. | 44 // kTcpKeepAliveDelaySecs. |
45 const int kTcpKeepAliveDelaySecs = 10; | 45 const int kTcpKeepAliveDelaySecs = 10; |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 namespace extensions { | 49 namespace extensions { |
50 | 50 |
51 static base::LazyInstance<BrowserContextKeyedAPIFactory< | 51 static base::LazyInstance<BrowserContextKeyedAPIFactory< |
52 ApiResourceManager<api::cast_channel::CastSocket> > > g_factory = | 52 ApiResourceManager<core_api::cast_channel::CastSocket> > > g_factory = |
53 LAZY_INSTANCE_INITIALIZER; | 53 LAZY_INSTANCE_INITIALIZER; |
54 | 54 |
55 // static | 55 // static |
56 template <> | 56 template <> |
57 BrowserContextKeyedAPIFactory< | 57 BrowserContextKeyedAPIFactory< |
58 ApiResourceManager<api::cast_channel::CastSocket> >* | 58 ApiResourceManager<core_api::cast_channel::CastSocket> >* |
59 ApiResourceManager<api::cast_channel::CastSocket>::GetFactoryInstance() { | 59 ApiResourceManager<core_api::cast_channel::CastSocket>::GetFactoryInstance() { |
60 return g_factory.Pointer(); | 60 return g_factory.Pointer(); |
61 } | 61 } |
62 | 62 |
63 namespace api { | 63 namespace core_api { |
64 namespace cast_channel { | 64 namespace cast_channel { |
65 | 65 |
66 CastSocket::CastSocket(const std::string& owner_extension_id, | 66 CastSocket::CastSocket(const std::string& owner_extension_id, |
67 const net::IPEndPoint& ip_endpoint, | 67 const net::IPEndPoint& ip_endpoint, |
68 ChannelAuthType channel_auth, | 68 ChannelAuthType channel_auth, |
69 CastSocket::Delegate* delegate, | 69 CastSocket::Delegate* delegate, |
70 net::NetLog* net_log, | 70 net::NetLog* net_log, |
71 const base::TimeDelta& timeout) : | 71 const base::TimeDelta& timeout) : |
72 ApiResource(owner_extension_id), | 72 ApiResource(owner_extension_id), |
73 channel_id_(0), | 73 channel_id_(0), |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 return thread_checker_.CalledOnValidThread(); | 732 return thread_checker_.CalledOnValidThread(); |
733 } | 733 } |
734 | 734 |
735 base::Timer* CastSocket::GetTimer() { | 735 base::Timer* CastSocket::GetTimer() { |
736 return connect_timeout_timer_.get(); | 736 return connect_timeout_timer_.get(); |
737 } | 737 } |
738 | 738 |
739 CastSocket::MessageHeader::MessageHeader() : message_size(0) { } | 739 CastSocket::MessageHeader::MessageHeader() : message_size(0) { } |
740 | 740 |
741 void CastSocket::MessageHeader::SetMessageSize(size_t size) { | 741 void CastSocket::MessageHeader::SetMessageSize(size_t size) { |
742 DCHECK(size < static_cast<size_t>(kuint32max)); | 742 DCHECK_LT(size, static_cast<size_t>(kuint32max)); |
743 DCHECK(size > 0); | 743 DCHECK_GT(size, 0U); |
744 message_size = static_cast<size_t>(size); | 744 message_size = static_cast<size_t>(size); |
745 } | 745 } |
746 | 746 |
747 // TODO(mfoltz): Investigate replacing header serialization with base::Pickle, | 747 // TODO(mfoltz): Investigate replacing header serialization with base::Pickle, |
748 // if bit-for-bit compatible. | 748 // if bit-for-bit compatible. |
749 void CastSocket::MessageHeader::PrependToString(std::string* str) { | 749 void CastSocket::MessageHeader::PrependToString(std::string* str) { |
750 MessageHeader output = *this; | 750 MessageHeader output = *this; |
751 output.message_size = base::HostToNet32(message_size); | 751 output.message_size = base::HostToNet32(message_size); |
752 size_t header_size = base::checked_cast<size_t,uint32>( | 752 size_t header_size = base::checked_cast<size_t,uint32>( |
753 MessageHeader::header_size()); | 753 MessageHeader::header_size()); |
(...skipping 27 matching lines...) Expand all Loading... |
781 if (!Serialize(message_proto, &message_data)) | 781 if (!Serialize(message_proto, &message_data)) |
782 return false; | 782 return false; |
783 io_buffer = new net::DrainableIOBuffer(new net::StringIOBuffer(message_data), | 783 io_buffer = new net::DrainableIOBuffer(new net::StringIOBuffer(message_data), |
784 message_data.size()); | 784 message_data.size()); |
785 return true; | 785 return true; |
786 } | 786 } |
787 | 787 |
788 CastSocket::WriteRequest::~WriteRequest() { } | 788 CastSocket::WriteRequest::~WriteRequest() { } |
789 | 789 |
790 } // namespace cast_channel | 790 } // namespace cast_channel |
791 } // namespace api | 791 } // namespace core_api |
792 } // namespace extensions | 792 } // namespace extensions |
793 | 793 |
794 #undef VLOG_WITH_CONNECTION | 794 #undef VLOG_WITH_CONNECTION |
OLD | NEW |