diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-05 02:00:42 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-05 02:00:42 +0000 |
commit | db803aaecaa3270b2b21c3d4200dc04cf733b655 (patch) | |
tree | c88d90537845ef39c4d33c8b00deea1fc5844e60 /content | |
parent | 83c8265e74ad2bca349e291e440ab9a8a0759093 (diff) | |
download | chromium_src-db803aaecaa3270b2b21c3d4200dc04cf733b655.zip chromium_src-db803aaecaa3270b2b21c3d4200dc04cf733b655.tar.gz chromium_src-db803aaecaa3270b2b21c3d4200dc04cf733b655.tar.bz2 |
Move socket stream messages to content, in preparation for moving its dispatcher. In this change I also converted p2p_messages to use the new automated way of serializing structs.
Review URL: http://codereview.chromium.org/6621025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77019 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/renderer_host/socket_stream_dispatcher_host.cc | 42 | ||||
-rw-r--r-- | content/browser/renderer_host/socket_stream_host.cc | 6 | ||||
-rw-r--r-- | content/common/common_param_traits.cc | 30 | ||||
-rw-r--r-- | content/common/common_param_traits.h | 40 | ||||
-rw-r--r-- | content/common/content_constants.cc | 14 | ||||
-rw-r--r-- | content/common/content_constants.h | 26 | ||||
-rw-r--r-- | content/common/content_message_generator.cc | 32 | ||||
-rw-r--r-- | content/common/content_message_generator.h | 8 | ||||
-rw-r--r-- | content/common/p2p_messages.cc | 31 | ||||
-rw-r--r-- | content/common/p2p_messages.h | 30 | ||||
-rw-r--r-- | content/common/socket_stream.h | 15 | ||||
-rw-r--r-- | content/common/socket_stream_messages.h | 71 | ||||
-rw-r--r-- | content/content_common.gypi | 19 |
13 files changed, 283 insertions, 81 deletions
diff --git a/content/browser/renderer_host/socket_stream_dispatcher_host.cc b/content/browser/renderer_host/socket_stream_dispatcher_host.cc index 4b88ff0..d3c1b3a 100644 --- a/content/browser/renderer_host/socket_stream_dispatcher_host.cc +++ b/content/browser/renderer_host/socket_stream_dispatcher_host.cc @@ -6,11 +6,11 @@ #include "base/logging.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" -#include "chrome/common/net/socket_stream.h" #include "chrome/common/net/url_request_context_getter.h" +#include "chrome/common/render_messages_params.h" #include "content/browser/renderer_host/socket_stream_host.h" +#include "content/common/socket_stream.h" +#include "content/common/socket_stream_messages.h" #include "net/websockets/websocket_job.h" #include "net/websockets/websocket_throttle.h" @@ -34,9 +34,9 @@ bool SocketStreamDispatcherHost::OnMessageReceived(const IPC::Message& message, bool* message_was_ok) { bool handled = true; IPC_BEGIN_MESSAGE_MAP_EX(SocketStreamDispatcherHost, message, *message_was_ok) - IPC_MESSAGE_HANDLER(ViewHostMsg_SocketStream_Connect, OnConnect) - IPC_MESSAGE_HANDLER(ViewHostMsg_SocketStream_SendData, OnSendData) - IPC_MESSAGE_HANDLER(ViewHostMsg_SocketStream_Close, OnCloseReq) + IPC_MESSAGE_HANDLER(SocketStreamHostMsg_Connect, OnConnect) + IPC_MESSAGE_HANDLER(SocketStreamHostMsg_SendData, OnSendData) + IPC_MESSAGE_HANDLER(SocketStreamHostMsg_Close, OnCloseReq) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP_EX() return handled; @@ -48,13 +48,13 @@ void SocketStreamDispatcherHost::OnConnected(net::SocketStream* socket, int socket_id = SocketStreamHost::SocketIdFromSocketStream(socket); DVLOG(1) << "SocketStreamDispatcherHost::OnConnected socket_id=" << socket_id << " max_pending_send_allowed=" << max_pending_send_allowed; - if (socket_id == chrome_common_net::kNoSocketId) { + if (socket_id == content_common::kNoSocketId) { LOG(ERROR) << "NoSocketId in OnConnected"; return; } - if (!Send(new ViewMsg_SocketStream_Connected( + if (!Send(new SocketStreamMsg_Connected( socket_id, max_pending_send_allowed))) { - LOG(ERROR) << "ViewMsg_SocketStream_Connected failed."; + LOG(ERROR) << "SocketStreamMsg_Connected failed."; DeleteSocketStreamHost(socket_id); } } @@ -64,12 +64,12 @@ void SocketStreamDispatcherHost::OnSentData(net::SocketStream* socket, int socket_id = SocketStreamHost::SocketIdFromSocketStream(socket); DVLOG(1) << "SocketStreamDispatcherHost::OnSentData socket_id=" << socket_id << " amount_sent=" << amount_sent; - if (socket_id == chrome_common_net::kNoSocketId) { + if (socket_id == content_common::kNoSocketId) { LOG(ERROR) << "NoSocketId in OnReceivedData"; return; } - if (!Send(new ViewMsg_SocketStream_SentData(socket_id, amount_sent))) { - LOG(ERROR) << "ViewMsg_SocketStream_SentData failed."; + if (!Send(new SocketStreamMsg_SentData(socket_id, amount_sent))) { + LOG(ERROR) << "SocketStreamMsg_SentData failed."; DeleteSocketStreamHost(socket_id); } } @@ -79,13 +79,13 @@ void SocketStreamDispatcherHost::OnReceivedData( int socket_id = SocketStreamHost::SocketIdFromSocketStream(socket); DVLOG(1) << "SocketStreamDispatcherHost::OnReceiveData socket_id=" << socket_id; - if (socket_id == chrome_common_net::kNoSocketId) { + if (socket_id == content_common::kNoSocketId) { LOG(ERROR) << "NoSocketId in OnReceivedData"; return; } - if (!Send(new ViewMsg_SocketStream_ReceivedData( + if (!Send(new SocketStreamMsg_ReceivedData( socket_id, std::vector<char>(data, data + len)))) { - LOG(ERROR) << "ViewMsg_SocketStream_ReceivedData failed."; + LOG(ERROR) << "SocketStreamMsg_ReceivedData failed."; DeleteSocketStreamHost(socket_id); } } @@ -93,7 +93,7 @@ void SocketStreamDispatcherHost::OnReceivedData( void SocketStreamDispatcherHost::OnClose(net::SocketStream* socket) { int socket_id = SocketStreamHost::SocketIdFromSocketStream(socket); DVLOG(1) << "SocketStreamDispatcherHost::OnClosed socket_id=" << socket_id; - if (socket_id == chrome_common_net::kNoSocketId) { + if (socket_id == content_common::kNoSocketId) { LOG(ERROR) << "NoSocketId in OnClose"; return; } @@ -104,7 +104,7 @@ void SocketStreamDispatcherHost::OnClose(net::SocketStream* socket) { void SocketStreamDispatcherHost::OnConnect(const GURL& url, int socket_id) { DVLOG(1) << "SocketStreamDispatcherHost::OnConnect url=" << url << " socket_id=" << socket_id; - DCHECK_NE(chrome_common_net::kNoSocketId, socket_id); + DCHECK_NE(content_common::kNoSocketId, socket_id); if (hosts_.Lookup(socket_id)) { LOG(ERROR) << "socket_id=" << socket_id << " already registered."; return; @@ -142,14 +142,18 @@ void SocketStreamDispatcherHost::DeleteSocketStreamHost(int socket_id) { DCHECK(socket_stream_host); delete socket_stream_host; hosts_.Remove(socket_id); - if (!Send(new ViewMsg_SocketStream_Closed(socket_id))) { - LOG(ERROR) << "ViewMsg_SocketStream_Closed failed."; + if (!Send(new SocketStreamMsg_Closed(socket_id))) { + LOG(ERROR) << "SocketStreamMsg_Closed failed."; } } net::URLRequestContext* SocketStreamDispatcherHost::GetURLRequestContext() { net::URLRequestContext* rv = NULL; if (url_request_context_override_.get()) { + // TODO(jam): temporary code until Gears is taken out, then + // GetRequestContext will take a different parameter and we can take out + // this struct and the #include "chrome/common/render_messages_params.h" + // above. ViewHostMsg_Resource_Request request; rv = url_request_context_override_->GetRequestContext(request); } diff --git a/content/browser/renderer_host/socket_stream_host.cc b/content/browser/renderer_host/socket_stream_host.cc index e98f7db..c2f1a79 100644 --- a/content/browser/renderer_host/socket_stream_host.cc +++ b/content/browser/renderer_host/socket_stream_host.cc @@ -5,7 +5,7 @@ #include "content/browser/renderer_host/socket_stream_host.h" #include "base/logging.h" -#include "chrome/common/net/socket_stream.h" +#include "content/common/socket_stream.h" #include "net/socket_stream/socket_stream_job.h" static const char* kSocketIdKey = "socketId"; @@ -25,7 +25,7 @@ SocketStreamHost::SocketStreamHost( int socket_id) : delegate_(delegate), socket_id_(socket_id) { - DCHECK_NE(socket_id_, chrome_common_net::kNoSocketId); + DCHECK_NE(socket_id_, content_common::kNoSocketId); VLOG(1) << "SocketStreamHost: socket_id=" << socket_id_; } @@ -36,7 +36,7 @@ int SocketStreamHost::SocketIdFromSocketStream(net::SocketStream* socket) { SocketStreamId* socket_stream_id = static_cast<SocketStreamId*>(d); return socket_stream_id->socket_id(); } - return chrome_common_net::kNoSocketId; + return content_common::kNoSocketId; } SocketStreamHost::~SocketStreamHost() { diff --git a/content/common/common_param_traits.cc b/content/common/common_param_traits.cc new file mode 100644 index 0000000..d25cb5b --- /dev/null +++ b/content/common/common_param_traits.cc @@ -0,0 +1,30 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/common/common_param_traits.h" + +#include "content/common/content_constants.h" + +namespace IPC { + +void ParamTraits<GURL>::Write(Message* m, const GURL& p) { + m->WriteString(p.possibly_invalid_spec()); + // TODO(brettw) bug 684583: Add encoding for query params. +} + +bool ParamTraits<GURL>::Read(const Message* m, void** iter, GURL* p) { + std::string s; + if (!m->ReadString(iter, &s) || s.length() > content::kMaxURLChars) { + *p = GURL(); + return false; + } + *p = GURL(s); + return true; +} + +void ParamTraits<GURL>::Log(const GURL& p, std::string* l) { + l->append(p.spec()); +} + +} // namespace IPC diff --git a/content/common/common_param_traits.h b/content/common/common_param_traits.h new file mode 100644 index 0000000..9717dcc --- /dev/null +++ b/content/common/common_param_traits.h @@ -0,0 +1,40 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is used to define IPC::ParamTraits<> specializations for a number +// of types so that they can be serialized over IPC. IPC::ParamTraits<> +// specializations for basic types (like int and std::string) and types in the +// 'base' project can be found in ipc/ipc_message_utils.h. This file contains +// specializations for types that are used by the content code, and which need +// manual serialization code. This is usually because they're not structs with +// public members.. + +#ifndef CONTENT_COMMON_COMMON_PARAM_TRAITS_H_ +#define CONTENT_COMMON_COMMON_PARAM_TRAITS_H_ +#pragma once + +#include "googleurl/src/gurl.h" +#include "ipc/ipc_message_utils.h" +// !!! WARNING: DO NOT ADD NEW WEBKIT DEPENDENCIES !!! +// +// That means don't add #includes to any file in 'webkit/' or +// 'third_party/WebKit/'. Chrome Frame and NACL build parts of base/ and +// content/common/ for a mini-library that doesn't depend on webkit. + +// Forward declarations. +class GURL; + +namespace IPC { + +template <> +struct ParamTraits<GURL> { + typedef GURL param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* p); + static void Log(const param_type& p, std::string* l); +}; + +} // namespace IPC + +#endif // CONTENT_COMMON_COMMON_PARAM_TRAITS_H_ diff --git a/content/common/content_constants.cc b/content/common/content_constants.cc new file mode 100644 index 0000000..2532fc1 --- /dev/null +++ b/content/common/content_constants.cc @@ -0,0 +1,14 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/common/content_constants.h" + +namespace content { + +const size_t kMaxURLChars = 2 * 1024 * 1024; +const size_t kMaxURLDisplayChars = 32 * 1024; + +} // namespace content + +#undef FPL diff --git a/content/common/content_constants.h b/content/common/content_constants.h new file mode 100644 index 0000000..ca94329 --- /dev/null +++ b/content/common/content_constants.h @@ -0,0 +1,26 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// A handful of resource-like constants related to the Content application. + +#ifndef CONTENT_COMMON_CHROME_CONSTANTS_H_ +#define CONTENT_COMMON_CHROME_CONSTANTS_H_ +#pragma once + +#include <stddef.h> // For size_t + +namespace content { + +// The maximum number of characters in the URL that we're willing to accept +// in the browser process. It is set low enough to avoid damage to the browser +// but high enough that a web site can abuse location.hash for a little storage. +// We have different values for "max accepted" and "max displayed" because +// a data: URI may be legitimately massive, but the full URI would kill all +// known operating systems if you dropped it into a UI control. +extern const size_t kMaxURLChars; +extern const size_t kMaxURLDisplayChars; + +} // namespace content + +#endif // CONTENT_COMMON_CHROME_CONSTANTS_H_ diff --git a/content/common/content_message_generator.cc b/content/common/content_message_generator.cc new file mode 100644 index 0000000..eacddef --- /dev/null +++ b/content/common/content_message_generator.cc @@ -0,0 +1,32 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Get basic type definitions. +#define IPC_MESSAGE_IMPL +#include "content/common/common_param_traits.h" +#include "content/common/content_message_generator.h" + +// Generate constructors. +#include "ipc/struct_constructor_macros.h" +#include "content/common/content_message_generator.h" + +// Generate destructors. +#include "ipc/struct_destructor_macros.h" +#include "content/common/content_message_generator.h" + +namespace IPC { + +// Generate param traits write methods. +#include "ipc/param_traits_write_macros.h" +#include "content/common/content_message_generator.h" + +// Generate param traits read methods. +#include "ipc/param_traits_read_macros.h" +#include "content/common/content_message_generator.h" + +// Generate param traits log methods. +#include "ipc/param_traits_log_macros.h" +#include "content/common/content_message_generator.h" + +} // namespace IPC diff --git a/content/common/content_message_generator.h b/content/common/content_message_generator.h new file mode 100644 index 0000000..bcda993 --- /dev/null +++ b/content/common/content_message_generator.h @@ -0,0 +1,8 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Multiply-included file, hence no include guard. + +#include "content/common/p2p_messages.h" +#include "content/common/socket_stream_messages.h" diff --git a/content/common/p2p_messages.cc b/content/common/p2p_messages.cc deleted file mode 100644 index 82c5983..0000000 --- a/content/common/p2p_messages.cc +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#define IPC_MESSAGE_IMPL -#include "content/common/p2p_messages.h" - -namespace IPC { - -void ParamTraits<P2PSocketAddress>::Write(Message* m, const param_type& p) { - WriteParam(m, p.address); - WriteParam(m, p.port); -} - -bool ParamTraits<P2PSocketAddress>::Read(const Message* m, - void** iter, - param_type* p) { - return - ReadParam(m, iter, &p->address) && - ReadParam(m, iter, &p->port); -} - -void ParamTraits<P2PSocketAddress>::Log(const param_type& p, std::string* l) { - l->append("("); - LogParam(p.address, l); - l->append(", "); - LogParam(p.port, l); - l->append(")"); -} - -} // namespace IPC diff --git a/content/common/p2p_messages.h b/content/common/p2p_messages.h index 6ab75df..8424fe1 100644 --- a/content/common/p2p_messages.h +++ b/content/common/p2p_messages.h @@ -3,15 +3,20 @@ // found in the LICENSE file. // IPC messages for the P2P Transport API. - -#ifndef CONTENT_COMMON_P2P_MESSAGES_H_ -#define CONTENT_COMMON_P2P_MESSAGES_H_ +// Multiply-included message file, hence no include guard. #include "content/common/p2p_sockets.h" #include "ipc/ipc_message_macros.h" #define IPC_MESSAGE_START P2PMsgStart +IPC_STRUCT_TRAITS_BEGIN(P2PSocketAddress) + IPC_STRUCT_TRAITS_MEMBER(address) + IPC_STRUCT_TRAITS_MEMBER(port) +IPC_STRUCT_TRAITS_END() + +IPC_ENUM_TRAITS(P2PSocketType) + // P2P Socket messages sent from the browser to the renderer. IPC_MESSAGE_ROUTED2(P2PMsg_OnSocketCreated, @@ -41,22 +46,3 @@ IPC_MESSAGE_ROUTED3(P2PHostMsg_Send, IPC_MESSAGE_ROUTED1(P2PHostMsg_DestroySocket, int /* socket_id */) - -namespace IPC { - -template <> -struct ParamTraits<P2PSocketAddress> { - typedef P2PSocketAddress param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* p); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct SimilarTypeTraits<P2PSocketType> { - typedef int Type; -}; - -} // namespace IPC - -#endif // CONTENT_COMMON_P2P_MESSAGES_H_ diff --git a/content/common/socket_stream.h b/content/common/socket_stream.h new file mode 100644 index 0000000..29d1860 --- /dev/null +++ b/content/common/socket_stream.h @@ -0,0 +1,15 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_COMMON_SOCKET_STREAM_H_ +#define CONTENT_COMMON_SOCKET_STREAM_H_ +#pragma once + +namespace content_common { + +const int kNoSocketId = 0; + +} // namespace chrome_common_net + +#endif // CONTENT_COMMON_SOCKET_STREAM_H_ diff --git a/content/common/socket_stream_messages.h b/content/common/socket_stream_messages.h new file mode 100644 index 0000000..3da8983 --- /dev/null +++ b/content/common/socket_stream_messages.h @@ -0,0 +1,71 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Multiply-included message file, hence no include guard. + +#include <vector> + +#include "ipc/ipc_message_macros.h" +#include "ipc/ipc_param_traits.h" + +class GURL; + +#define IPC_MESSAGE_START SocketStreamMsgStart + +// Web Sockets messages sent from the renderer to the browser. + +// Open new Socket Stream for the |socket_url| identified by |socket_id| +// in the renderer process. +// The browser starts connecting asynchronously. +// Once Socket Stream connection is established, the browser will send +// SocketStreamMsg_Connected back. +IPC_MESSAGE_CONTROL2(SocketStreamHostMsg_Connect, + GURL /* socket_url */, + int /* socket_id */) + +// Request to send data on the Socket Stream. +// SocketStreamHandle can send data at most |max_pending_send_allowed| bytes, +// which is given by ViewMsg_SocketStream_Connected at any time. +// The number of pending bytes can be tracked by size of |data| sent +// and |amount_sent| parameter of ViewMsg_SocketStream_DataSent. +// That is, the following constraints is applied: +// (accumulated total of |data|) - (accumulated total of |amount_sent|) +// <= |max_pending_send_allowed| +// If the SocketStreamHandle ever tries to exceed the +// |max_pending_send_allowed|, the connection will be closed. +IPC_MESSAGE_CONTROL2(SocketStreamHostMsg_SendData, + int /* socket_id */, + std::vector<char> /* data */) + +// Request to close the Socket Stream. +// The browser will send ViewMsg_SocketStream_Closed back when the Socket +// Stream is completely closed. +IPC_MESSAGE_CONTROL1(SocketStreamHostMsg_Close, + int /* socket_id */) + + +// Speech input messages sent from the browser to the renderer. + +// A |socket_id| is assigned by SocketStreamHostMsg_Connect. +// The Socket Stream is connected. The SocketStreamHandle should keep track +// of how much it has pending (how much it has requested to be sent) and +// shouldn't go over |max_pending_send_allowed| bytes. +IPC_MESSAGE_CONTROL2(SocketStreamMsg_Connected, + int /* socket_id */, + int /* max_pending_send_allowed */) + +// |data| is received on the Socket Stream. +IPC_MESSAGE_CONTROL2(SocketStreamMsg_ReceivedData, + int /* socket_id */, + std::vector<char> /* data */) + +// |amount_sent| bytes of data requested by +// SocketStreamHostMsg_SendData has been sent on the Socket Stream. +IPC_MESSAGE_CONTROL2(SocketStreamMsg_SentData, + int /* socket_id */, + int /* amount_sent */) + +// The Socket Stream is closed. +IPC_MESSAGE_CONTROL1(SocketStreamMsg_Closed, + int /* socket_id */) diff --git a/content/content_common.gypi b/content/content_common.gypi index 477d460..8b8753e 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -14,14 +14,21 @@ '..', ], 'sources': [ - "common/content_switches.cc", - "common/content_switches.h", + 'common/common_param_traits.cc', + 'common/common_param_traits.h', + 'common/content_message_generator.cc', + 'common/content_message_generator.h', + 'common/content_constants.cc', + 'common/content_constants.h', + 'common/content_switches.cc', + 'common/content_switches.h', 'common/message_router.cc', 'common/message_router.h', - "common/p2p_messages.cc", - "common/p2p_messages.h", - "common/p2p_sockets.cc", - "common/p2p_sockets.h", + 'common/p2p_messages.h', + 'common/p2p_sockets.cc', + 'common/p2p_sockets.h', + 'common/socket_stream.h', + 'common/socket_stream_messages.h', ], 'conditions': [ ['OS=="win"', { |