Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <limits>
6 #include <windows.h>
8 #include "base/logging.h"
9 #include "base/sys_info.h"
10 #include "chrome/common/transport_dib.h"
12 TransportDIB::TransportDIB() {
13 }
15 TransportDIB::~TransportDIB() {
16 }
18 TransportDIB::TransportDIB(HANDLE handle)
19 : shared_memory_(handle, false /* read write */) {
20 }
22 // static
23 TransportDIB* TransportDIB::Create(size_t size, uint32_t sequence_num) {
24 size_t allocation_granularity = base::SysInfo::VMAllocationGranularity();
25 size = size / allocation_granularity + 1;
26 size = size * allocation_granularity;
28 TransportDIB* dib = new TransportDIB;
30 if (!dib->shared_memory_.Create("", false /* read write */,
31 true /* open existing */, size)) {
32 delete dib;
33 return NULL;
34 }
36 dib->size_ = size;
37 dib->sequence_num_ = sequence_num;
39 return dib;
40 }
42 // static
43 TransportDIB* TransportDIB::Map(TransportDIB::Handle handle) {
44 TransportDIB* dib = new TransportDIB(handle);
45 if (!dib->shared_memory_.Map(0 /* map whole shared memory segment */)) {
46 CHROMIUM_LOG(ERROR) << "Failed to map transport DIB"
47 << " handle:" << handle
48 << " error:" << GetLastError();
49 delete dib;
50 return NULL;
51 }
53 // There doesn't seem to be any way to find the size of the shared memory
54 // region! GetFileSize indicates that the handle is invalid. Thus, we
55 // conservatively set the size to the maximum and hope that the renderer
56 // isn't about to ask us to read off the end of the array.
57 dib->size_ = std::numeric_limits<size_t>::max();
59 return dib;
60 }
62 void* TransportDIB::memory() const {
63 return shared_memory_.memory();
64 }
66 TransportDIB::Handle TransportDIB::handle() const {
67 return shared_memory_.handle();
68 }
70 TransportDIB::Id TransportDIB::id() const {
71 return Id(shared_memory_.handle(), sequence_num_);
72 }