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

Side by Side Diff: base/memory/shared_memory_win.cc

Issue 2727673003: Clean up: Name is always not empty in SharedMemory on Windows (Closed)
Patch Set: Created 3 years, 9 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/shared_memory.h" 5 #include "base/memory/shared_memory.h"
6 6
7 #include <aclapi.h> 7 #include <aclapi.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 } 250 }
251 251
252 // Windows ignores DACLs on certain unnamed objects (like shared sections). 252 // Windows ignores DACLs on certain unnamed objects (like shared sections).
253 // So, we generate a random name when we need to enforce read-only. 253 // So, we generate a random name when we need to enforce read-only.
254 uint64_t rand_values[4]; 254 uint64_t rand_values[4];
255 RandBytes(&rand_values, sizeof(rand_values)); 255 RandBytes(&rand_values, sizeof(rand_values));
256 name_ = StringPrintf(L"CrSharedMem_%016llx%016llx%016llx%016llx", 256 name_ = StringPrintf(L"CrSharedMem_%016llx%016llx%016llx%016llx",
257 rand_values[0], rand_values[1], 257 rand_values[0], rand_values[1],
258 rand_values[2], rand_values[3]); 258 rand_values[2], rand_values[3]);
259 } 259 }
260 mapped_file_.Set(CreateFileMappingWithReducedPermissions( 260 DCHECK(!name_.empty());
261 &sa, rounded_size, name_.empty() ? nullptr : name_.c_str())); 261 mapped_file_.Set(CreateFileMappingWithReducedPermissions(&sa, rounded_size,
262 name_.c_str()));
262 if (!mapped_file_.IsValid()) { 263 if (!mapped_file_.IsValid()) {
263 // The error is logged within CreateFileMappingWithReducedPermissions(). 264 // The error is logged within CreateFileMappingWithReducedPermissions().
264 return false; 265 return false;
265 } 266 }
266 267
267 requested_size_ = options.size; 268 requested_size_ = options.size;
268 269
269 // Check if the shared memory pre-exists. 270 // Check if the shared memory pre-exists.
270 if (GetLastError() == ERROR_ALREADY_EXISTS) { 271 if (GetLastError() == ERROR_ALREADY_EXISTS) {
271 // If the file already existed, set requested_size_ to 0 to show that 272 // If the file already existed, set requested_size_ to 0 to show that
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 387
387 SharedMemoryHandle SharedMemory::TakeHandle() { 388 SharedMemoryHandle SharedMemory::TakeHandle() {
388 SharedMemoryHandle handle(mapped_file_.Take(), base::GetCurrentProcId()); 389 SharedMemoryHandle handle(mapped_file_.Take(), base::GetCurrentProcId());
389 handle.SetOwnershipPassesToIPC(true); 390 handle.SetOwnershipPassesToIPC(true);
390 memory_ = nullptr; 391 memory_ = nullptr;
391 mapped_size_ = 0; 392 mapped_size_ = 0;
392 return handle; 393 return handle;
393 } 394 }
394 395
395 } // namespace base 396 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698