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

Unified Diff: ppapi/proxy/content_decryptor_private_serializer-inl.h

Issue 10854209: Modify the PPAPI CDM interface to pass more info. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updates that resolve xhwang's comments. Created 8 years, 4 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: ppapi/proxy/content_decryptor_private_serializer-inl.h
diff --git a/ppapi/proxy/content_decryptor_private_serializer-inl.h b/ppapi/proxy/content_decryptor_private_serializer-inl.h
new file mode 100644
index 0000000000000000000000000000000000000000..c282564f5eb2d4d68eeb5c9d5a15e7b087e0ea5d
--- /dev/null
+++ b/ppapi/proxy/content_decryptor_private_serializer-inl.h
@@ -0,0 +1,56 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_PROXY_CONTENT_DECRYPTOR_PRIVATE_SERIALIZER_INL_H_
dmichael (off chromium) 2012/08/21 17:37:08 I wouldn't use the -inl suffix
Tom Finegan 2012/08/21 22:57:39 Done.
+#define PPAPI_PROXY_CONTENT_DECRYPTOR_PRIVATE_SERIALIZER_INL_H_
+
+#include <cstring>
+#include <string>
+
+#include "ppapi/c/private/pp_content_decryptor.h"
+
+namespace ppapi {
+namespace proxy {
+
+// Serialization/deserialization utility functions for storing/extracting
+// PP_{De|En}cryptedBlockInfo structs within std::string's for passing through
+// IPC. Both functions return true upon success, and false upon failure.
+//
+// Note, these functions check the size of |block_info| against the size of
+// the "serialized" data stored within |serialized_block_info|, and will report
+// failure if expectations are not met. Use of CHECK/DCHECK has been avoided
+// because the functions are intended for use on both sides of the IPC proxy.
+
+template <typename T>
+bool SerializeBlockInfo(const T& block_info,
+ std::string* serialized_block_info) {
+ if (!serialized_block_info)
+ return false;
+
+ serialized_block_info->assign(reinterpret_cast<const char*>(&block_info),
+ sizeof(T));
dmichael (off chromium) 2012/08/21 17:37:08 nit: You should prefer to use sizeof on a variable
Tom Finegan 2012/08/21 22:57:39 Doh! Missed this one when I fixed the other for xh
+
+ if (serialized_block_info->size() != sizeof(block_info))
+ return false;
+
+ return true;
+}
+
+template <typename T>
+bool DeserializeBlockInfo(const std::string& serialized_block_info,
+ T* block_info) {
+ if (!block_info)
+ return false;
+
+ if (serialized_block_info.size() != sizeof(T))
dmichael (off chromium) 2012/08/21 17:37:08 sizeof(*block_info)
Tom Finegan 2012/08/21 22:57:39 Done.
+ return false;
+
+ std::memcpy(block_info, serialized_block_info.data(), sizeof(T));
dmichael (off chromium) 2012/08/21 17:37:08 sizeof(*block_info)
Tom Finegan 2012/08/21 22:57:39 Done.
+ return true;
+}
+
+} // namespace proxy
+} // namespace ppapi
+
+#endif // PPAPI_PROXY_CONTENT_DECRYPTOR_PRIVATE_SERIALIZER_INL_H_

Powered by Google App Engine
This is Rietveld 408576698