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

Side by Side Diff: third_party/WebKit/Source/platform/SharedBuffer.h

Issue 2249533003: [Platform] Enable to get a partial data of SharedBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/SharedBuffer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 return getSomeDataInternal(data, position); 118 return getSomeDataInternal(data, position);
119 } 119 }
120 120
121 // Returns the content data into "dest" as a flat buffer. "byteLength" must 121 // Returns the content data into "dest" as a flat buffer. "byteLength" must
122 // exactly match with size(). Returns true on success, otherwise the content 122 // exactly match with size(). Returns true on success, otherwise the content
123 // of "dest" is not guaranteed. 123 // of "dest" is not guaranteed.
124 HAS_STRICTLY_TYPED_ARG 124 HAS_STRICTLY_TYPED_ARG
125 bool getAsBytes(void* dest, STRICTLY_TYPED_ARG(byteLength)) const 125 bool getAsBytes(void* dest, STRICTLY_TYPED_ARG(byteLength)) const
126 { 126 {
127 STRICT_ARG_TYPE(size_t); 127 STRICT_ARG_TYPE(size_t);
128 return getAsBytesInternal(dest, byteLength); 128 if (byteLength != size())
129 return false;
130
131 return getAsBytesInternal(dest, 0, byteLength);
132 }
133
134 // Copies "byteLength" bytes from "position"-th bytes (0 origin) of the cont ent
135 // data into "dest" as a flat buffer,
136 // Returns true on success, otherwise the content of "dest" is not guarantee d.
137 HAS_STRICTLY_TYPED_ARG
138 bool getPartAsBytes(void* dest, STRICTLY_TYPED_ARG(position), STRICTLY_TYPED _ARG(byteLength)) const
139 {
140 STRICT_ARG_TYPE(size_t);
141 return getAsBytesInternal(dest, position, byteLength);
129 } 142 }
130 143
131 // Creates an SkData and copies this SharedBuffer's contents to that 144 // Creates an SkData and copies this SharedBuffer's contents to that
132 // SkData without merging segmented buffers into a flat buffer. 145 // SkData without merging segmented buffers into a flat buffer.
133 sk_sp<SkData> getAsSkData() const; 146 sk_sp<SkData> getAsSkData() const;
134 147
135 // See PurgeableVector::lock(). 148 // See PurgeableVector::lock().
136 bool lock(); 149 bool lock();
137 150
138 // WARNING: Calling unlock() on a SharedBuffer that wasn't created with the 151 // WARNING: Calling unlock() on a SharedBuffer that wasn't created with the
139 // purgeability option does an extra memcpy(). Please use 152 // purgeability option does an extra memcpy(). Please use
140 // SharedBuffer::createPurgeable() if you intend to call unlock(). 153 // SharedBuffer::createPurgeable() if you intend to call unlock().
141 void unlock(); 154 void unlock();
142 155
143 bool isLocked() const; 156 bool isLocked() const;
144 157
145 void onMemoryDump(const String& dumpPrefix, WebProcessMemoryDump*) const; 158 void onMemoryDump(const String& dumpPrefix, WebProcessMemoryDump*) const;
146 159
147 private: 160 private:
148 SharedBuffer(); 161 SharedBuffer();
149 explicit SharedBuffer(size_t); 162 explicit SharedBuffer(size_t);
150 SharedBuffer(const char*, size_t); 163 SharedBuffer(const char*, size_t);
151 SharedBuffer(const unsigned char*, size_t); 164 SharedBuffer(const unsigned char*, size_t);
152 SharedBuffer(const char*, size_t, PurgeableVector::PurgeableOption); 165 SharedBuffer(const char*, size_t, PurgeableVector::PurgeableOption);
153 166
154 // See SharedBuffer::data(). 167 // See SharedBuffer::data().
155 void mergeSegmentsIntoBuffer() const; 168 void mergeSegmentsIntoBuffer() const;
156 169
157 void appendInternal(const char* data, size_t); 170 void appendInternal(const char* data, size_t);
158 bool getAsBytesInternal(void* dest, size_t) const; 171 bool getAsBytesInternal(void* dest, size_t, size_t) const;
159 size_t getSomeDataInternal(const char*& data, size_t position) const; 172 size_t getSomeDataInternal(const char*& data, size_t position) const;
160 173
161 size_t m_size; 174 size_t m_size;
162 mutable PurgeableVector m_buffer; 175 mutable PurgeableVector m_buffer;
163 mutable Vector<char*> m_segments; 176 mutable Vector<char*> m_segments;
164 }; 177 };
165 178
166 } // namespace blink 179 } // namespace blink
167 180
168 #endif // SharedBuffer_h 181 #endif // SharedBuffer_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/SharedBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698