Chromium Code Reviews| Index: components/dns_prefetch/common/prefetch_messages.cc |
| diff --git a/components/dns_prefetch/common/prefetch_messages.cc b/components/dns_prefetch/common/prefetch_messages.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..85b86815d768781fe38ac854956fd3185ac30038 |
| --- /dev/null |
| +++ b/components/dns_prefetch/common/prefetch_messages.cc |
| @@ -0,0 +1,44 @@ |
| +// Copyright 2014 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 "components/dns_prefetch/common/prefetch_messages.h" |
| + |
| +#include "base/strings/string_number_conversions.h" |
| +#include "components/dns_prefetch/common/prefetch_common.h" |
| + |
| +namespace IPC { |
| + |
| +void ParamTraits<dns_prefetch::LookupRequest>::Write( |
| + Message* m, const dns_prefetch::LookupRequest& request) { |
| + IPC::WriteParam(m, request.hostname_list); |
| +} |
| + |
| +bool ParamTraits<dns_prefetch::LookupRequest>::Read( |
| + const Message* m, |
| + PickleIterator* iter, |
| + dns_prefetch::LookupRequest* request) { |
| + // Verify the hostname limits after deserialization success. |
| + if (IPC::ReadParam(m, iter, &request->hostname_list)) { |
| + dns_prefetch::NameList& hostnames = request->hostname_list; |
| + if (hostnames.size() > dns_prefetch::kMaxDnsHostnamesPerRequest) |
| + return false; |
| + |
| + for (dns_prefetch::NameList::const_iterator it = hostnames.begin(); |
|
Nico
2014/10/30 00:03:05
if you want, you can write
for (const auot& hos
gunsch
2014/10/30 00:32:50
Done.
|
| + it < hostnames.end(); |
| + ++it) { |
| + if (it->length() > dns_prefetch::kMaxDnsHostnameLength) |
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| + |
| +void ParamTraits<dns_prefetch::LookupRequest>::Log( |
| + const dns_prefetch::LookupRequest& p, std::string* l) { |
| + l->append("<dns_prefetch::LookupRequest: "); |
| + l->append(base::UintToString(p.hostname_list.size())); |
| + l->append(" hostnames>"); |
| +} |
| + |
| +} // namespace IPC |