| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * |
| 3 * Copyright 2015-2016, Google Inc. |
| 4 * All rights reserved. |
| 3 * | 5 * |
| 4 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
| 6 * met: | 8 * met: |
| 7 * | 9 * |
| 8 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 11 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 12 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer | 13 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 14 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 15 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 16 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 17 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 18 * this software without specific prior written permission. |
| 17 * | 19 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 * |
| 29 */ | 32 */ |
| 30 | 33 |
| 31 #ifndef OpenTypeSanitizer_h | 34 #ifndef GRPCXX_SUPPORT_SLICE_H |
| 32 #define OpenTypeSanitizer_h | 35 #define GRPCXX_SUPPORT_SLICE_H |
| 33 | 36 |
| 34 #include "opentype-sanitiser.h" | 37 #include <grpc/support/slice.h> |
| 35 #include "wtf/Allocator.h" | 38 #include <grpc++/support/config.h> |
| 36 #include "wtf/Forward.h" | |
| 37 #include "wtf/text/WTFString.h" | |
| 38 | 39 |
| 39 namespace blink { | 40 namespace grpc { |
| 40 | 41 |
| 41 class SharedBuffer; | 42 /// A wrapper around \a gpr_slice. |
| 43 /// |
| 44 /// A slice represents a contiguous reference counted array of bytes. |
| 45 /// It is cheap to take references to a slice, and it is cheap to create a |
| 46 /// slice pointing to a subset of another slice. |
| 47 class Slice GRPC_FINAL { |
| 48 public: |
| 49 /// Construct an empty slice. |
| 50 Slice(); |
| 51 // Destructor - drops one reference. |
| 52 ~Slice(); |
| 42 | 53 |
| 43 class OpenTypeSanitizer { | 54 enum AddRef { ADD_REF }; |
| 44 STACK_ALLOCATED(); | 55 /// Construct a slice from \a slice, adding a reference. |
| 45 public: | 56 Slice(gpr_slice slice, AddRef); |
| 46 explicit OpenTypeSanitizer(SharedBuffer* buffer) | |
| 47 : m_buffer(buffer) | |
| 48 , m_otsErrorString("") | |
| 49 { | |
| 50 } | |
| 51 | 57 |
| 52 PassRefPtr<SharedBuffer> sanitize(); | 58 enum StealRef { STEAL_REF }; |
| 59 /// Construct a slice from \a slice, stealing a reference. |
| 60 Slice(gpr_slice slice, StealRef); |
| 53 | 61 |
| 54 static bool supportsFormat(const String&); | 62 /// Copy constructor, adds a reference. |
| 55 String getErrorString() const { return static_cast<String>(m_otsErrorString)
; } | 63 Slice(const Slice& other); |
| 56 | 64 |
| 57 void setErrorString(const String& errorString) { m_otsErrorString = errorStr
ing; } | 65 /// Assignment, reference count is unchanged. |
| 66 Slice& operator=(Slice other) { |
| 67 std::swap(slice_, other.slice_); |
| 68 return *this; |
| 69 } |
| 58 | 70 |
| 59 private: | 71 /// Byte size. |
| 60 SharedBuffer* const m_buffer; | 72 size_t size() const { return GPR_SLICE_LENGTH(slice_); } |
| 61 String m_otsErrorString; | 73 |
| 74 /// Raw pointer to the beginning (first element) of the slice. |
| 75 const uint8_t* begin() const { return GPR_SLICE_START_PTR(slice_); } |
| 76 |
| 77 /// Raw pointer to the end (one byte \em past the last element) of the slice. |
| 78 const uint8_t* end() const { return GPR_SLICE_END_PTR(slice_); } |
| 79 |
| 80 private: |
| 81 friend class ByteBuffer; |
| 82 |
| 83 gpr_slice slice_; |
| 62 }; | 84 }; |
| 63 | 85 |
| 64 class BlinkOTSContext: public ots::OTSContext { | 86 } // namespace grpc |
| 65 DISALLOW_NEW(); | |
| 66 public: | |
| 67 BlinkOTSContext() | |
| 68 : m_errorString("") | |
| 69 { | |
| 70 } | |
| 71 | 87 |
| 72 virtual void Message(int level, const char *format, ...); | 88 #endif // GRPCXX_SUPPORT_SLICE_H |
| 73 virtual ots::TableAction GetTableAction(uint32_t tag); | |
| 74 String getErrorString() const { return static_cast<String>(m_errorString
); } | |
| 75 private: | |
| 76 String m_errorString; | |
| 77 }; | |
| 78 | |
| 79 } // namespace blink | |
| 80 | |
| 81 #endif // OpenTypeSanitizer_h | |
| OLD | NEW |