diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 06:35:52 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 06:35:52 +0000 |
commit | b1064d692d5f1d56877d0b1eb0b38920115227ba (patch) | |
tree | 6145df9c1a9d94bf5879cbdbf03cb9fcab4211c7 /ipc | |
parent | ca0206c7aba32aa151c94514a0456a6c58252fb5 (diff) | |
download | chromium_src-b1064d692d5f1d56877d0b1eb0b38920115227ba.zip chromium_src-b1064d692d5f1d56877d0b1eb0b38920115227ba.tar.gz chromium_src-b1064d692d5f1d56877d0b1eb0b38920115227ba.tar.bz2 |
net: Change type of UploadData::elements from std::vector to ScopedVector
Using std::vector to hold UploadElement is bad for two reasons:
1. It results in a lot of unnecessary copy of uploaded data.
2. Appending new chunks may result in invalidating the pointer held by UploadBytesElementReader.
BUG=160028
TEST=git try
TBR=ananta@chromium.org, tony@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11275223
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167611 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/ipc_message_utils.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h index 0e4c68e..19622b2 100644 --- a/ipc/ipc_message_utils.h +++ b/ipc/ipc_message_utils.h @@ -12,6 +12,7 @@ #include <vector> #include "base/format_macros.h" +#include "base/memory/scoped_vector.h" #include "base/platform_file.h" #include "base/string16.h" #include "base/stringprintf.h" @@ -633,6 +634,37 @@ struct ParamTraits< Tuple5<A, B, C, D, E> > { } }; +template<class P> +struct ParamTraits<ScopedVector<P> > { + typedef ScopedVector<P> param_type; + static void Write(Message* m, const param_type& p) { + WriteParam(m, static_cast<int>(p.size())); + for (size_t i = 0; i < p.size(); i++) + WriteParam(m, *p[i]); + } + static bool Read(const Message* m, PickleIterator* iter, param_type* r) { + int size = 0; + if (!m->ReadLength(iter, &size)) + return false; + if (INT_MAX/sizeof(P) <= static_cast<size_t>(size)) + return false; + r->resize(size); + for (int i = 0; i < size; i++) { + (*r)[i] = new P(); + if (!ReadParam(m, iter, (*r)[i])) + return false; + } + return true; + } + static void Log(const param_type& p, std::string* l) { + for (size_t i = 0; i < p.size(); ++i) { + if (i != 0) + l->append(" "); + LogParam(*p[i], l); + } + } +}; + // IPC types ParamTraits ------------------------------------------------------- // A ChannelHandle is basically a platform-inspecific wrapper around the |