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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #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.
6 #define PPAPI_PROXY_CONTENT_DECRYPTOR_PRIVATE_SERIALIZER_INL_H_
7
8 #include <cstring>
9 #include <string>
10
11 #include "ppapi/c/private/pp_content_decryptor.h"
12
13 namespace ppapi {
14 namespace proxy {
15
16 // Serialization/deserialization utility functions for storing/extracting
17 // PP_{De|En}cryptedBlockInfo structs within std::string's for passing through
18 // IPC. Both functions return true upon success, and false upon failure.
19 //
20 // Note, these functions check the size of |block_info| against the size of
21 // the "serialized" data stored within |serialized_block_info|, and will report
22 // failure if expectations are not met. Use of CHECK/DCHECK has been avoided
23 // because the functions are intended for use on both sides of the IPC proxy.
24
25 template <typename T>
26 bool SerializeBlockInfo(const T& block_info,
27 std::string* serialized_block_info) {
28 if (!serialized_block_info)
29 return false;
30
31 serialized_block_info->assign(reinterpret_cast<const char*>(&block_info),
32 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
33
34 if (serialized_block_info->size() != sizeof(block_info))
35 return false;
36
37 return true;
38 }
39
40 template <typename T>
41 bool DeserializeBlockInfo(const std::string& serialized_block_info,
42 T* block_info) {
43 if (!block_info)
44 return false;
45
46 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.
47 return false;
48
49 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.
50 return true;
51 }
52
53 } // namespace proxy
54 } // namespace ppapi
55
56 #endif // PPAPI_PROXY_CONTENT_DECRYPTOR_PRIVATE_SERIALIZER_INL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698