gfx/skia/trunk/src/images/SkStreamHelpers.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #include "SkStream.h"
michael@0 9 #include "SkStreamHelpers.h"
michael@0 10 #include "SkTypes.h"
michael@0 11
michael@0 12 size_t CopyStreamToStorage(SkAutoMalloc* storage, SkStream* stream) {
michael@0 13 SkASSERT(storage != NULL);
michael@0 14 SkASSERT(stream != NULL);
michael@0 15
michael@0 16 if (stream->hasLength()) {
michael@0 17 const size_t length = stream->getLength();
michael@0 18 void* dst = storage->reset(length);
michael@0 19 if (stream->read(dst, length) != length) {
michael@0 20 return 0;
michael@0 21 }
michael@0 22 return length;
michael@0 23 }
michael@0 24
michael@0 25 SkDynamicMemoryWStream tempStream;
michael@0 26 // Arbitrary buffer size.
michael@0 27 const size_t bufferSize = 256 * 1024; // 256KB
michael@0 28 char buffer[bufferSize];
michael@0 29 SkDEBUGCODE(size_t debugLength = 0;)
michael@0 30 do {
michael@0 31 size_t bytesRead = stream->read(buffer, bufferSize);
michael@0 32 tempStream.write(buffer, bytesRead);
michael@0 33 SkDEBUGCODE(debugLength += bytesRead);
michael@0 34 SkASSERT(tempStream.bytesWritten() == debugLength);
michael@0 35 } while (!stream->isAtEnd());
michael@0 36 const size_t length = tempStream.bytesWritten();
michael@0 37 void* dst = storage->reset(length);
michael@0 38 tempStream.copyTo(dst);
michael@0 39 return length;
michael@0 40 }

mercurial