Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 // Original author: ekr@rtfm.com
9 #ifndef databuffer_h__
10 #define databuffer_h__
11 #include <algorithm>
12 #include <mozilla/Scoped.h>
13 #include <m_cpp_utils.h>
14 #include <nsISupportsImpl.h>
16 namespace mozilla {
18 class DataBuffer {
19 public:
20 DataBuffer() : data_(nullptr), len_(0) {}
21 DataBuffer(const uint8_t *data, size_t len) {
22 Assign(data, len);
23 }
25 void Assign(const uint8_t *data, size_t len) {
26 data_ = new unsigned char[ len ? len : 1]; // Don't depend on new [0].
27 memcpy(static_cast<void *>(data_.get()),
28 static_cast<const void *>(data), len);
29 len_ = len;
30 }
32 const uint8_t *data() const { return data_; }
33 size_t len() const { return len_; }
34 const bool empty() const { return len_ != 0; }
36 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DataBuffer)
38 private:
39 ScopedDeleteArray<uint8_t> data_;
40 size_t len_;
42 DISALLOW_COPY_ASSIGN(DataBuffer);
43 };
45 }
47 #endif