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

Side by Side Diff: mojo/edk/system/options_validation.h

Issue 1350023003: Add a Mojo EDK for Chrome that uses one OS pipe per message pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move to mojo::edk namespace in preparation for runtim flag Created 5 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Functions to help with verifying various |Mojo...Options| structs from the 5 // Functions to help with verifying various |Mojo...Options| structs from the
6 // (public, C) API. These are "extensible" structs, which all have |struct_size| 6 // (public, C) API. These are "extensible" structs, which all have |struct_size|
7 // as their first member. All fields (other than |struct_size|) are optional, 7 // as their first member. All fields (other than |struct_size|) are optional,
8 // but any |flags| specified must be known to the system (otherwise, an error of 8 // but any |flags| specified must be known to the system (otherwise, an error of
9 // |MOJO_RESULT_UNIMPLEMENTED| should be returned). 9 // |MOJO_RESULT_UNIMPLEMENTED| should be returned).
10 10
11 #ifndef MOJO_EDK_SYSTEM_OPTIONS_VALIDATION_H_ 11 #ifndef MOJO_EDK_SYSTEM_OPTIONS_VALIDATION_H_
12 #define MOJO_EDK_SYSTEM_OPTIONS_VALIDATION_H_ 12 #define MOJO_EDK_SYSTEM_OPTIONS_VALIDATION_H_
13 13
14 #include <stddef.h> 14 #include <stddef.h>
15 #include <stdint.h> 15 #include <stdint.h>
16 16
17 #include <algorithm> 17 #include <algorithm>
18 18
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "mojo/edk/system/memory.h" 20 #include "mojo/edk/system/memory.h"
21 #include "mojo/edk/system/system_impl_export.h" 21 #include "mojo/edk/system/system_impl_export.h"
22 #include "mojo/public/c/system/types.h" 22 #include "mojo/public/c/system/types.h"
23 #include "mojo/public/cpp/system/macros.h" 23 #include "mojo/public/cpp/system/macros.h"
24 24
25 namespace mojo { 25 namespace mojo {
26 namespace system { 26 namespace edk {
27 27
28 template <class Options> 28 template <class Options>
29 class UserOptionsReader { 29 class UserOptionsReader {
30 public: 30 public:
31 // Constructor from a |UserPointer<const Options>| (which it checks -- this 31 // Constructor from a |UserPointer<const Options>| (which it checks -- this
32 // constructor has side effects!). 32 // constructor has side effects!).
33 // Note: We initialize |options_reader_| without checking, since we do a check 33 // Note: We initialize |options_reader_| without checking, since we do a check
34 // in |GetSizeForReader()|. 34 // in |GetSizeForReader()|.
35 explicit UserOptionsReader(UserPointer<const Options> options) 35 explicit UserOptionsReader(UserPointer<const Options> options)
36 : options_reader_(UserPointer<const char>::Reader::NoCheck(), 36 : options_reader_(UserPointer<const char>::Reader::NoCheck(),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // 89 //
90 // (We can't just give |HasMember()| a member pointer template argument instead, 90 // (We can't just give |HasMember()| a member pointer template argument instead,
91 // since there's no good/strictly-correct way to get an offset from that.) 91 // since there's no good/strictly-correct way to get an offset from that.)
92 // 92 //
93 // TODO(vtl): With C++11, use |sizeof(Options::member)| instead of (the 93 // TODO(vtl): With C++11, use |sizeof(Options::member)| instead of (the
94 // contortion below). We might also be able to pull out the type |Options| from 94 // contortion below). We might also be able to pull out the type |Options| from
95 // |reader| (using |decltype|) instead of requiring a parameter. 95 // |reader| (using |decltype|) instead of requiring a parameter.
96 #define OPTIONS_STRUCT_HAS_MEMBER(Options, member, reader) \ 96 #define OPTIONS_STRUCT_HAS_MEMBER(Options, member, reader) \
97 reader.HasMember(offsetof(Options, member), sizeof(reader.options().member)) 97 reader.HasMember(offsetof(Options, member), sizeof(reader.options().member))
98 98
99 } // namespace system 99 } // namespace edk
100 } // namespace mojo 100 } // namespace mojo
101 101
102 #endif // MOJO_EDK_SYSTEM_OPTIONS_VALIDATION_H_ 102 #endif // MOJO_EDK_SYSTEM_OPTIONS_VALIDATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698