Index: third_party/grpc/src/cpp/util/byte_buffer.cc |
diff --git a/third_party/WebKit/Source/core/dom/custom/V0CustomElementLifecycleCallbacks.h b/third_party/grpc/src/cpp/util/byte_buffer.cc |
similarity index 52% |
copy from third_party/WebKit/Source/core/dom/custom/V0CustomElementLifecycleCallbacks.h |
copy to third_party/grpc/src/cpp/util/byte_buffer.cc |
index 2b1e584aafc13b2075e85ec8afa985dc784698f6..3a2318d1a60f57b17f6da66b016e891c94e7b2fa 100644 |
--- a/third_party/WebKit/Source/core/dom/custom/V0CustomElementLifecycleCallbacks.h |
+++ b/third_party/grpc/src/cpp/util/byte_buffer.cc |
@@ -1,5 +1,7 @@ |
/* |
- * Copyright (C) 2013 Google Inc. All rights reserved. |
+ * |
+ * Copyright 2015-2016, Google Inc. |
+ * All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions are |
@@ -26,46 +28,67 @@ |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * |
*/ |
-#ifndef V0CustomElementLifecycleCallbacks_h |
-#define V0CustomElementLifecycleCallbacks_h |
- |
-#include "platform/heap/Handle.h" |
-#include "wtf/text/AtomicString.h" |
- |
-namespace blink { |
- |
-class Element; |
+#include <grpc++/support/byte_buffer.h> |
+#include <grpc/byte_buffer_reader.h> |
-class V0CustomElementLifecycleCallbacks : public GarbageCollectedFinalized<V0CustomElementLifecycleCallbacks> { |
-public: |
- virtual ~V0CustomElementLifecycleCallbacks() { } |
+namespace grpc { |
- enum CallbackType { |
- None = 0, |
- CreatedCallback = 1 << 0, |
- AttachedCallback = 1 << 1, |
- DetachedCallback = 1 << 2, |
- AttributeChangedCallback = 1 << 3 |
- }; |
+ByteBuffer::ByteBuffer(const Slice* slices, size_t nslices) { |
+ // TODO(yangg) maybe expose some core API to simplify this |
+ std::vector<gpr_slice> c_slices(nslices); |
+ for (size_t i = 0; i < nslices; i++) { |
+ c_slices[i] = slices[i].slice_; |
+ } |
+ buffer_ = grpc_raw_byte_buffer_create(c_slices.data(), nslices); |
+} |
- bool hasCallback(CallbackType type) const { return m_callbackType & type; } |
+ByteBuffer::~ByteBuffer() { |
+ if (buffer_) { |
+ grpc_byte_buffer_destroy(buffer_); |
+ } |
+} |
- virtual void created(Element*) = 0; |
- virtual void attached(Element*) = 0; |
- virtual void detached(Element*) = 0; |
- virtual void attributeChanged(Element*, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue) = 0; |
+void ByteBuffer::Clear() { |
+ if (buffer_) { |
+ grpc_byte_buffer_destroy(buffer_); |
+ buffer_ = nullptr; |
+ } |
+} |
- DEFINE_INLINE_VIRTUAL_TRACE() { } |
+void ByteBuffer::Dump(std::vector<Slice>* slices) const { |
+ slices->clear(); |
+ if (!buffer_) { |
+ return; |
+ } |
+ grpc_byte_buffer_reader reader; |
+ grpc_byte_buffer_reader_init(&reader, buffer_); |
+ gpr_slice s; |
+ while (grpc_byte_buffer_reader_next(&reader, &s)) { |
+ slices->push_back(Slice(s, Slice::STEAL_REF)); |
+ } |
+ grpc_byte_buffer_reader_destroy(&reader); |
+} |
-protected: |
- explicit V0CustomElementLifecycleCallbacks(CallbackType type) : m_callbackType(type) { } |
+size_t ByteBuffer::Length() const { |
+ if (buffer_) { |
+ return grpc_byte_buffer_length(buffer_); |
+ } else { |
+ return 0; |
+ } |
+} |
-private: |
- CallbackType m_callbackType; |
-}; |
+ByteBuffer::ByteBuffer(const ByteBuffer& buf) |
+ : buffer_(grpc_byte_buffer_copy(buf.buffer_)) {} |
-} // namespace blink |
+ByteBuffer& ByteBuffer::operator=(const ByteBuffer& buf) { |
+ Clear(); // first remove existing data |
+ if (buf.buffer_) { |
+ buffer_ = grpc_byte_buffer_copy(buf.buffer_); // then copy |
+ } |
+ return *this; |
+} |
-#endif // V0CustomElementLifecycleCallbacks_h |
+} // namespace grpc |