Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Unified Diff: include/core/SkFlattenableBuffers.h

Issue 23021015: Initial error handling code (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Serialization with strings as ID Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: include/core/SkFlattenableBuffers.h
diff --git a/include/core/SkFlattenableBuffers.h b/include/core/SkFlattenableBuffers.h
index 03c03f3877e6f8e3f508d29e371d5c7ebd91624e..5bb6043f74e142a89c0b0e81d0f5319a737654c5 100644
--- a/include/core/SkFlattenableBuffers.h
+++ b/include/core/SkFlattenableBuffers.h
@@ -41,14 +41,20 @@ public:
kCrossProcess_Flag = 1 << 0,
kScalarIsFloat_Flag = 1 << 1,
kPtrIs64Bit_Flag = 1 << 2,
+ /** The kValidation_Flag is used to force stream validations (by making
+ * sure that no operation reads past the end of the stream, for example)
+ * and error handling if any reading operation yields an invalid value.
+ */
+ kValidation_Flag = 1 << 3,
};
void setFlags(uint32_t flags) { fFlags = flags; }
uint32_t getFlags() const { return fFlags; }
- bool isCrossProcess() const { return SkToBool(fFlags & kCrossProcess_Flag); }
+ bool isCrossProcess() const { return SkToBool(fFlags & (kCrossProcess_Flag | kValidation_Flag)); }
bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag); }
bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); }
+ bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); }
// primitives
virtual bool readBool() = 0;
@@ -64,7 +70,16 @@ public:
virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding) = 0;
// common data structures
- virtual SkFlattenable* readFlattenable() = 0;
+ virtual SkFlattenable* readFlattenable(
+ /**
+ @param type This parameter is only used when using SkValidatingReadBuffer. It will verify
+ that the object about to be deserialized is of the given type or early return
+ NULL otherwise. The type provided here is either the same type or the type of
+ one of the base classes of the object to deserialize. This can effectively be
+ bypassed by providing the type SkFlattenable::kSkFlattenable_Type here, since
mtklein 2013/10/07 19:29:56 kSkFlattenableType_Type -> GetName()?
sugoi1 2013/10/08 20:23:10 Done.
+ SkFlattenable is a base class to all other classes that can be deserialized.
+ */
+ const char* name = SkFlattenable::GetName()) = 0;
virtual void readPoint(SkPoint* point) = 0;
virtual void readMatrix(SkMatrix* matrix) = 0;
virtual void readIRect(SkIRect* rect) = 0;
@@ -99,9 +114,16 @@ public:
}
template <typename T> T* readFlattenableT() {
- return static_cast<T*>(this->readFlattenable());
+ return static_cast<T*>(this->readFlattenable(T::GetName()));
}
+ void validate(bool isValid) {
+ fError = fError || !isValid;
+ }
+
+protected:
+ bool fError;
mtklein 2013/10/07 19:29:56 This seems a little odd to add this state here if
sugoi1 2013/10/08 20:23:10 Done.
+
private:
uint32_t fFlags;
};
@@ -154,13 +176,22 @@ public:
enum Flags {
kCrossProcess_Flag = 0x01,
+ /** The kValidation_Flag is used here to make sure the write operation
+ * is symmetric with the read operation using the equivalent flag
mtklein 2013/10/07 19:29:56 I don't think I understand what this comment is tr
sugoi1 2013/10/08 20:23:10 We can phrase it any other way, but essentially :
+ * SkFlattenableReadBuffer::kValidation_Flag.
+ */
+ kValidation_Flag = 0x02,
};
uint32_t getFlags() const { return fFlags; }
void setFlags(uint32_t flags) { fFlags = flags; }
bool isCrossProcess() const {
- return SkToBool(fFlags & kCrossProcess_Flag);
+ return SkToBool(fFlags & (kCrossProcess_Flag | kValidation_Flag));
+ }
+
+ bool isValidating() const {
+ return SkToBool(fFlags & kValidation_Flag);
}
bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; }

Powered by Google App Engine
This is Rietveld 408576698