From 502c94ff1a9f99b5c4ecfe700415cc4ed14228dd Mon Sep 17 00:00:00 2001 From: rockot Date: Wed, 3 Feb 2016 12:20:16 -0800 Subject: IPC::Message -> base::Pickle This changes consumers of IPC::Message to generally refer refer to base::Pickle instead when performing serialization and deserialization operations. The few specific instances where the IPC::Message interface (Read/WriteAttachent) is needed can safely be static_cast'd, as IPC::Message is the only public subclass of base::Pickle. The purpose of this change is to facilitate the transition to Mojo IPC, as we've trained the Mojo bindings layer to use existing ParamTraits parameterized over base::Pickle. To support this base::Pickle has had some stub interfaces added for WriteAttachment and ReadAttachment, along with a Pickle::Attachment. A follow-up patch will add sizing traits to the standard IPC_STRUCT macros, enabling the majority of Chrome IPC structs to be carried over Mojo message pipes as-is. BUG=577685 R=jam@chromium.org Review URL: https://codereview.chromium.org/1659003003 Cr-Commit-Position: refs/heads/master@{#373323} --- extensions/common/extension_messages.cc | 43 ++++++++++--------- extensions/common/extension_messages.h | 48 ++++++++++++++-------- extensions/common/permissions/api_permission.cc | 4 +- extensions/common/permissions/api_permission.h | 4 +- .../common/permissions/manifest_permission.cc | 4 +- .../common/permissions/manifest_permission.h | 4 +- .../permissions/set_disjunction_permission.h | 6 +-- .../permissions/settings_override_permission.cc | 4 +- .../permissions/settings_override_permission.h | 4 +- 9 files changed, 67 insertions(+), 54 deletions(-) (limited to 'extensions/common') diff --git a/extensions/common/extension_messages.cc b/extensions/common/extension_messages.cc index 15bc121..5cccc11 100644 --- a/extensions/common/extension_messages.cc +++ b/extensions/common/extension_messages.cc @@ -92,11 +92,11 @@ namespace IPC { template <> struct ParamTraits { typedef Manifest::Location param_type; - static void Write(Message* m, const param_type& p) { + static void Write(base::Pickle* m, const param_type& p) { int val = static_cast(p); WriteParam(m, val); } - static bool Read(const Message* m, + static bool Read(const base::Pickle* m, base::PickleIterator* iter, param_type* p) { int val = 0; @@ -112,12 +112,12 @@ struct ParamTraits { } }; -void ParamTraits::Write(Message* m, const param_type& p) { +void ParamTraits::Write(base::Pickle* m, const param_type& p) { WriteParam(m, p.valid_schemes()); WriteParam(m, p.GetAsString()); } -bool ParamTraits::Read(const Message* m, +bool ParamTraits::Read(const base::Pickle* m, base::PickleIterator* iter, param_type* p) { int valid_schemes; @@ -141,11 +141,11 @@ void ParamTraits::Log(const param_type& p, std::string* l) { LogParam(p.GetAsString(), l); } -void ParamTraits::Write(Message* m, const param_type& p) { +void ParamTraits::Write(base::Pickle* m, const param_type& p) { WriteParam(m, p.patterns()); } -bool ParamTraits::Read(const Message* m, +bool ParamTraits::Read(const base::Pickle* m, base::PickleIterator* iter, param_type* p) { std::set patterns; @@ -162,12 +162,12 @@ void ParamTraits::Log(const param_type& p, std::string* l) { LogParam(p.patterns(), l); } -void ParamTraits::Write( - Message* m, const param_type& p) { +void ParamTraits::Write(base::Pickle* m, + const param_type& p) { WriteParam(m, static_cast(p)); } -bool ParamTraits::Read(const Message* m, +bool ParamTraits::Read(const base::Pickle* m, base::PickleIterator* iter, param_type* p) { int api_id = -2; @@ -183,8 +183,8 @@ void ParamTraits::Log( LogParam(static_cast(p), l); } -void ParamTraits::Write( - Message* m, const param_type& p) { +void ParamTraits::Write(base::Pickle* m, + const param_type& p) { APIPermissionSet::const_iterator it = p.begin(); const APIPermissionSet::const_iterator end = p.end(); WriteParam(m, p.size()); @@ -194,7 +194,7 @@ void ParamTraits::Write( } } -bool ParamTraits::Read(const Message* m, +bool ParamTraits::Read(const base::Pickle* m, base::PickleIterator* iter, param_type* r) { size_t size; @@ -221,8 +221,8 @@ void ParamTraits::Log( LogParam(p.map(), l); } -void ParamTraits::Write( - Message* m, const param_type& p) { +void ParamTraits::Write(base::Pickle* m, + const param_type& p) { ManifestPermissionSet::const_iterator it = p.begin(); const ManifestPermissionSet::const_iterator end = p.end(); WriteParam(m, p.size()); @@ -232,7 +232,7 @@ void ParamTraits::Write( } } -bool ParamTraits::Read(const Message* m, +bool ParamTraits::Read(const base::Pickle* m, base::PickleIterator* iter, param_type* r) { size_t size; @@ -257,13 +257,12 @@ void ParamTraits::Log( LogParam(p.map(), l); } -void ParamTraits::Write( - Message* m, const param_type& p) { +void ParamTraits::Write(base::Pickle* m, const param_type& p) { WriteParam(m, p.type()); WriteParam(m, p.id()); } -bool ParamTraits::Read(const Message* m, +bool ParamTraits::Read(const base::Pickle* m, base::PickleIterator* iter, param_type* r) { HostID::HostType type; @@ -282,7 +281,7 @@ void ParamTraits::Log( LogParam(p.id(), l); } -void ParamTraits::Write(Message* m, +void ParamTraits::Write(base::Pickle* m, const param_type& p) { WriteParam(m, p.apis); WriteParam(m, p.manifest_permissions); @@ -291,7 +290,7 @@ void ParamTraits::Write(Message* m, } bool ParamTraits::Read( - const Message* m, + const base::Pickle* m, base::PickleIterator* iter, param_type* p) { return ReadParam(m, iter, &p->apis) && @@ -308,7 +307,7 @@ void ParamTraits::Log(const param_type& p, LogParam(p.scriptable_hosts, l); } -void ParamTraits::Write(Message* m, +void ParamTraits::Write(base::Pickle* m, const param_type& p) { WriteParam(m, p.location); WriteParam(m, p.path); @@ -318,7 +317,7 @@ void ParamTraits::Write(Message* m, WriteParam(m, p.withheld_permissions); } -bool ParamTraits::Read(const Message* m, +bool ParamTraits::Read(const base::Pickle* m, base::PickleIterator* iter, param_type* p) { p->manifest.reset(new base::DictionaryValue()); diff --git a/extensions/common/extension_messages.h b/extensions/common/extension_messages.h index 2e025ac..5125941 100644 --- a/extensions/common/extension_messages.h +++ b/extensions/common/extension_messages.h @@ -304,64 +304,80 @@ namespace IPC { template <> struct ParamTraits { typedef URLPattern param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); + static void Write(base::Pickle* m, const param_type& p); + static bool Read(const base::Pickle* m, + base::PickleIterator* iter, + param_type* p); static void Log(const param_type& p, std::string* l); }; template <> struct ParamTraits { typedef extensions::URLPatternSet param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); + static void Write(base::Pickle* m, const param_type& p); + static bool Read(const base::Pickle* m, + base::PickleIterator* iter, + param_type* p); static void Log(const param_type& p, std::string* l); }; template <> struct ParamTraits { typedef extensions::APIPermission::ID param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); + static void Write(base::Pickle* m, const param_type& p); + static bool Read(const base::Pickle* m, + base::PickleIterator* iter, + param_type* p); static void Log(const param_type& p, std::string* l); }; template <> struct ParamTraits { typedef extensions::APIPermissionSet param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); + static void Write(base::Pickle* m, const param_type& p); + static bool Read(const base::Pickle* m, + base::PickleIterator* iter, + param_type* r); static void Log(const param_type& p, std::string* l); }; template <> struct ParamTraits { typedef extensions::ManifestPermissionSet param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); + static void Write(base::Pickle* m, const param_type& p); + static bool Read(const base::Pickle* m, + base::PickleIterator* iter, + param_type* r); static void Log(const param_type& p, std::string* l); }; template <> struct ParamTraits { typedef HostID param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, base::PickleIterator* iter, param_type* r); + static void Write(base::Pickle* m, const param_type& p); + static bool Read(const base::Pickle* m, + base::PickleIterator* iter, + param_type* r); static void Log(const param_type& p, std::string* l); }; template <> struct ParamTraits { typedef ExtensionMsg_PermissionSetStruct param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); + static void Write(base::Pickle* m, const param_type& p); + static bool Read(const base::Pickle* m, + base::PickleIterator* iter, + param_type* p); static void Log(const param_type& p, std::string* l); }; template <> struct ParamTraits { typedef ExtensionMsg_Loaded_Params param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); + static void Write(base::Pickle* m, const param_type& p); + static bool Read(const base::Pickle* m, + base::PickleIterator* iter, + param_type* p); static void Log(const param_type& p, std::string* l); }; diff --git a/extensions/common/permissions/api_permission.cc b/extensions/common/permissions/api_permission.cc index 89eaea5..77a1317 100644 --- a/extensions/common/permissions/api_permission.cc +++ b/extensions/common/permissions/api_permission.cc @@ -69,9 +69,9 @@ class SimpleAPIPermission : public APIPermission { return new SimpleAPIPermission(info()); } - void Write(IPC::Message* m) const override {} + void Write(base::Pickle* m) const override {} - bool Read(const IPC::Message* m, base::PickleIterator* iter) override { + bool Read(const base::Pickle* m, base::PickleIterator* iter) override { return true; } diff --git a/extensions/common/permissions/api_permission.h b/extensions/common/permissions/api_permission.h index 5d46ce9..0b6f1a3 100644 --- a/extensions/common/permissions/api_permission.h +++ b/extensions/common/permissions/api_permission.h @@ -324,10 +324,10 @@ class APIPermission { // IPC functions // Writes this into the given IPC message |m|. - virtual void Write(IPC::Message* m) const = 0; + virtual void Write(base::Pickle* m) const = 0; // Reads from the given IPC message |m|. - virtual bool Read(const IPC::Message* m, base::PickleIterator* iter) = 0; + virtual bool Read(const base::Pickle* m, base::PickleIterator* iter) = 0; // Logs this permission. virtual void Log(std::string* log) const = 0; diff --git a/extensions/common/permissions/manifest_permission.cc b/extensions/common/permissions/manifest_permission.cc index a3ba98e..9742138 100644 --- a/extensions/common/permissions/manifest_permission.cc +++ b/extensions/common/permissions/manifest_permission.cc @@ -27,14 +27,14 @@ bool ManifestPermission::Equal(const ManifestPermission* rhs) const { return ToValue()->Equals(rhs->ToValue().get()); } -void ManifestPermission::Write(IPC::Message* m) const { +void ManifestPermission::Write(base::Pickle* m) const { base::ListValue singleton; base::Value* value = ToValue().release(); singleton.Append(value); IPC::WriteParam(m, singleton); } -bool ManifestPermission::Read(const IPC::Message* m, +bool ManifestPermission::Read(const base::Pickle* m, base::PickleIterator* iter) { base::ListValue singleton; if (!IPC::ReadParam(m, iter, &singleton)) diff --git a/extensions/common/permissions/manifest_permission.h b/extensions/common/permissions/manifest_permission.h index 67c41d5..db8f07c 100644 --- a/extensions/common/permissions/manifest_permission.h +++ b/extensions/common/permissions/manifest_permission.h @@ -69,10 +69,10 @@ class ManifestPermission { // IPC functions // Writes this into the given IPC message |m|. - void Write(IPC::Message* m) const; + void Write(base::Pickle* m) const; // Reads from the given IPC message |m|. - bool Read(const IPC::Message* m, base::PickleIterator* iter); + bool Read(const base::Pickle* m, base::PickleIterator* iter); // Logs this permission. void Log(std::string* log) const; diff --git a/extensions/common/permissions/set_disjunction_permission.h b/extensions/common/permissions/set_disjunction_permission.h index 1e124ab..0e97e9d 100644 --- a/extensions/common/permissions/set_disjunction_permission.h +++ b/extensions/common/permissions/set_disjunction_permission.h @@ -147,11 +147,9 @@ class SetDisjunctionPermission : public APIPermission { return scoped_ptr(list); } - void Write(IPC::Message* m) const override { - IPC::WriteParam(m, data_set_); - } + void Write(base::Pickle* m) const override { IPC::WriteParam(m, data_set_); } - bool Read(const IPC::Message* m, base::PickleIterator* iter) override { + bool Read(const base::Pickle* m, base::PickleIterator* iter) override { return IPC::ReadParam(m, iter, &data_set_); } diff --git a/extensions/common/permissions/settings_override_permission.cc b/extensions/common/permissions/settings_override_permission.cc index 7756c5e..43765d2 100644 --- a/extensions/common/permissions/settings_override_permission.cc +++ b/extensions/common/permissions/settings_override_permission.cc @@ -84,9 +84,9 @@ APIPermission* SettingsOverrideAPIPermission::Intersect( return new SettingsOverrideAPIPermission(info(), setting_value_); } -void SettingsOverrideAPIPermission::Write(IPC::Message* m) const {} +void SettingsOverrideAPIPermission::Write(base::Pickle* m) const {} -bool SettingsOverrideAPIPermission::Read(const IPC::Message* m, +bool SettingsOverrideAPIPermission::Read(const base::Pickle* m, base::PickleIterator* iter) { return true; } diff --git a/extensions/common/permissions/settings_override_permission.h b/extensions/common/permissions/settings_override_permission.h index 32dc8b3..81a2730 100644 --- a/extensions/common/permissions/settings_override_permission.h +++ b/extensions/common/permissions/settings_override_permission.h @@ -33,8 +33,8 @@ class SettingsOverrideAPIPermission : public APIPermission { APIPermission* Diff(const APIPermission* rhs) const override; APIPermission* Union(const APIPermission* rhs) const override; APIPermission* Intersect(const APIPermission* rhs) const override; - void Write(IPC::Message* m) const override; - bool Read(const IPC::Message* m, base::PickleIterator* iter) override; + void Write(base::Pickle* m) const override; + bool Read(const base::Pickle* m, base::PickleIterator* iter) override; void Log(std::string* log) const override; private: -- cgit v1.1