Index: base/pickle.h |
diff --git a/base/pickle.h b/base/pickle.h |
index 02bc432ad0bd27564e289f9d8fae0b9ca9408241..2487aebc3e6bbb74551204b9e56ee58c89f88e00 100644 |
--- a/base/pickle.h |
+++ b/base/pickle.h |
@@ -14,6 +14,7 @@ |
#include "base/compiler_specific.h" |
#include "base/gtest_prod_util.h" |
#include "base/logging.h" |
+#include "base/memory/ref_counted.h" |
#include "base/strings/string16.h" |
#include "base/strings/string_piece.h" |
@@ -123,6 +124,19 @@ class BASE_EXPORT PickleIterator { |
// |
class BASE_EXPORT Pickle { |
public: |
+ // A base attachment type for a Pickle subclass to implement if it supports |
+ // reading and writing attachments. |
+ class BASE_EXPORT Attachment : public RefCountedThreadSafe<Attachment> { |
+ public: |
+ Attachment(); |
+ |
+ protected: |
+ friend class RefCountedThreadSafe<Attachment>; |
+ virtual ~Attachment(); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Attachment); |
+ }; |
+ |
// Initialize a Pickle object using the default header size. |
Pickle(); |
@@ -206,6 +220,23 @@ class BASE_EXPORT Pickle { |
// known size. See also WriteData. |
bool WriteBytes(const void* data, int length); |
+ // WriteAttachment appends |attachment| to the pickle. It returns |
+ // false iff the set is full. |
+ // |
+ // NOTE: It is NOT OK to call this or ReadAttachment() on a simple |
Tom Sepez
2016/02/02 19:25:55
It feels wrong to design a virtual API that requir
|
+ // base::Pickle. These must be implemented and called only on subclasses that |
+ // support attachments. |
+ virtual bool WriteAttachment(scoped_refptr<Attachment> attachment); |
+ |
+ // ReadAttachment parses an attachment given the parsing state |iter| and |
+ // writes it to |*attachment|. It returns true on success. |
+ // |
+ // NOTE: It is NOT OK to call this or WriteAttachment() on a simple |
+ // base::Pickle. These must be implemented and called only subclasses that |
+ // support attachments. |
+ virtual bool ReadAttachment(base::PickleIterator* iter, |
+ scoped_refptr<Attachment>* attachment) const; |
+ |
// Reserves space for upcoming writes when multiple writes will be made and |
// their sizes are computed in advance. It can be significantly faster to call |
// Reserve() before calling WriteFoo() multiple times. |