#include "url/ipc/url_param_traits.h"
#include <string>
#include "base/pickle.h"
#include "url/gurl.h"
#include "url/url_constants.h"
namespace IPC {
void ParamTraits<GURL>::Write(base::Pickle* m, const GURL& p) {
if (p.possibly_invalid_spec().length() > url::kMaxURLChars) {
m->WriteString(std::string());
return;
}
if (!p.is_valid()) {
m->WriteString(std::string());
return;
}
m->WriteString(p.possibly_invalid_spec());
}
bool ParamTraits<GURL>::Read(const base::Pickle* m,
base::PickleIterator* iter,
GURL* p) {
std::string s;
if (!iter->ReadString(&s) || s.length() > url::kMaxURLChars) {
*p = GURL();
return false;
}
*p = GURL(s);
if (!s.empty() && !p->is_valid()) {
*p = GURL();
return false;
}
return true;
}
void ParamTraits<GURL>::Log(const GURL& p, std::string* l) {
l->append(p.spec());
}
}