summaryrefslogtreecommitdiffstats
path: root/chrome/common/common_param_traits.cc
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-24 20:29:02 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-24 20:29:02 +0000
commit939856a0f55cefee7a8dfb0746b1eb4455730d65 (patch)
treee8fe853f5c31ae7ea1244e25070618782cdb0a06 /chrome/common/common_param_traits.cc
parentd480a3ecadc882225c2b249346dae3759e3f8fce (diff)
downloadchromium_src-939856a0f55cefee7a8dfb0746b1eb4455730d65.zip
chromium_src-939856a0f55cefee7a8dfb0746b1eb4455730d65.tar.gz
chromium_src-939856a0f55cefee7a8dfb0746b1eb4455730d65.tar.bz2
FBTF: Move individual XXXMsg_Params structs to a new file.
The new file, render_messages_params.h, is included in 57 files, while render_messages.h is included in 176 files. Moving the Params structs to their own file allow pruning the included headers. (Part 2 of this cleanup will be sorting the individual structs into themes to further minimize header inclusion.) BUG=51411 TEST=compiles Review URL: http://codereview.chromium.org/3119035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57229 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/common_param_traits.cc')
-rw-r--r--chrome/common/common_param_traits.cc123
1 files changed, 104 insertions, 19 deletions
diff --git a/chrome/common/common_param_traits.cc b/chrome/common/common_param_traits.cc
index 0eed189..19ef93b 100644
--- a/chrome/common/common_param_traits.cc
+++ b/chrome/common/common_param_traits.cc
@@ -6,9 +6,11 @@
#include "chrome/common/chrome_constants.h"
#include "chrome/common/content_settings.h"
+#include "chrome/common/geoposition.h"
#include "chrome/common/thumbnail_score.h"
#include "gfx/rect.h"
#include "googleurl/src/gurl.h"
+#include "net/base/upload_data.h"
#include "printing/native_metafile.h"
#include "printing/page_range.h"
@@ -315,6 +317,90 @@ void ParamTraits<URLRequestStatus>::Log(const param_type& p, std::string* l) {
}
}
+// Only the net::UploadData ParamTraits<> definition needs this definition, so
+// keep this in the implementation file so we can forward declare UploadData in
+// the header.
+template <>
+struct ParamTraits<net::UploadData::Element> {
+ typedef net::UploadData::Element param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, static_cast<int>(p.type()));
+ if (p.type() == net::UploadData::TYPE_BYTES) {
+ m->WriteData(&p.bytes()[0], static_cast<int>(p.bytes().size()));
+ } else {
+ WriteParam(m, p.file_path());
+ WriteParam(m, p.file_range_offset());
+ WriteParam(m, p.file_range_length());
+ WriteParam(m, p.expected_file_modification_time());
+ }
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ int type;
+ if (!ReadParam(m, iter, &type))
+ return false;
+ if (type == net::UploadData::TYPE_BYTES) {
+ const char* data;
+ int len;
+ if (!m->ReadData(iter, &data, &len))
+ return false;
+ r->SetToBytes(data, len);
+ } else {
+ DCHECK(type == net::UploadData::TYPE_FILE);
+ FilePath file_path;
+ uint64 offset, length;
+ base::Time expected_modification_time;
+ if (!ReadParam(m, iter, &file_path))
+ return false;
+ if (!ReadParam(m, iter, &offset))
+ return false;
+ if (!ReadParam(m, iter, &length))
+ return false;
+ if (!ReadParam(m, iter, &expected_modification_time))
+ return false;
+ r->SetToFilePathRange(file_path, offset, length,
+ expected_modification_time);
+ }
+ return true;
+ }
+ static void Log(const param_type& p, std::string* l) {
+ l->append("<net::UploadData::Element>");
+ }
+};
+
+void ParamTraits<scoped_refptr<net::UploadData> >::Write(Message* m,
+ const param_type& p) {
+ WriteParam(m, p.get() != NULL);
+ if (p) {
+ WriteParam(m, *p->elements());
+ WriteParam(m, p->identifier());
+ }
+}
+
+bool ParamTraits<scoped_refptr<net::UploadData> >::Read(const Message* m,
+ void** iter,
+ param_type* r) {
+ bool has_object;
+ if (!ReadParam(m, iter, &has_object))
+ return false;
+ if (!has_object)
+ return true;
+ std::vector<net::UploadData::Element> elements;
+ if (!ReadParam(m, iter, &elements))
+ return false;
+ int64 identifier;
+ if (!ReadParam(m, iter, &identifier))
+ return false;
+ *r = new net::UploadData;
+ (*r)->swap_elements(&elements);
+ (*r)->set_identifier(identifier);
+ return true;
+}
+
+void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p,
+ std::string* l) {
+ l->append("<net::UploadData>");
+}
+
void ParamTraits<ThumbnailScore>::Write(Message* m, const param_type& p) {
IPC::ParamTraits<double>::Write(m, p.boring_score);
IPC::ParamTraits<bool>::Write(m, p.good_clipping);
@@ -345,25 +431,24 @@ void ParamTraits<ThumbnailScore>::Log(const param_type& p, std::string* l) {
p.boring_score, p.good_clipping, p.at_top));
}
-void ParamTraits<Geoposition::ErrorCode>::Write(
- Message* m, const Geoposition::ErrorCode& p) {
- int error_code = p;
- WriteParam(m, error_code);
-}
-
-bool ParamTraits<Geoposition::ErrorCode>::Read(
- const Message* m, void** iter, Geoposition::ErrorCode* p) {
- int error_code_param = 0;
- bool ret = ReadParam(m, iter, &error_code_param);
- *p = static_cast<Geoposition::ErrorCode>(error_code_param);
- return ret;
-}
-
-void ParamTraits<Geoposition::ErrorCode>::Log(
- const Geoposition::ErrorCode& p, std::string* l) {
- int error_code = p;
- l->append(StringPrintf("<Geoposition::ErrorCode>%d", error_code));
-}
+template <>
+struct ParamTraits<Geoposition::ErrorCode> {
+ typedef Geoposition::ErrorCode param_type;
+ static void Write(Message* m, const param_type& p) {
+ int error_code = p;
+ WriteParam(m, error_code);
+ }
+ static bool Read(const Message* m, void** iter, param_type* p) {
+ int error_code_param = 0;
+ bool ret = ReadParam(m, iter, &error_code_param);
+ *p = static_cast<Geoposition::ErrorCode>(error_code_param);
+ return ret;
+ }
+ static void Log(const param_type& p, std::string* l) {
+ int error_code = p;
+ l->append(StringPrintf("<Geoposition::ErrorCode>%d", error_code));
+ }
+};
void ParamTraits<Geoposition>::Write(Message* m, const Geoposition& p) {
WriteParam(m, p.latitude);