OLD | NEW |
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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 DCHECK(!mapped_file_); | 106 DCHECK(!mapped_file_); |
107 if (options.size == 0) | 107 if (options.size == 0) |
108 return false; | 108 return false; |
109 | 109 |
110 // Check maximum accounting for overflow. | 110 // Check maximum accounting for overflow. |
111 if (options.size > | 111 if (options.size > |
112 static_cast<size_t>(std::numeric_limits<int>::max()) - kSectionMask) | 112 static_cast<size_t>(std::numeric_limits<int>::max()) - kSectionMask) |
113 return false; | 113 return false; |
114 | 114 |
115 size_t rounded_size = (options.size + kSectionMask) & ~kSectionMask; | 115 size_t rounded_size = (options.size + kSectionMask) & ~kSectionMask; |
116 name_ = ASCIIToWide(options.name == NULL ? "" : *options.name); | 116 name_ = ASCIIToWide(options.name_deprecated == NULL ? "" : |
| 117 *options.name_deprecated); |
117 mapped_file_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, | 118 mapped_file_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, |
118 PAGE_READWRITE, 0, static_cast<DWORD>(rounded_size), | 119 PAGE_READWRITE, 0, static_cast<DWORD>(rounded_size), |
119 name_.empty() ? NULL : name_.c_str()); | 120 name_.empty() ? NULL : name_.c_str()); |
120 if (!mapped_file_) | 121 if (!mapped_file_) |
121 return false; | 122 return false; |
122 | 123 |
123 requested_size_ = options.size; | 124 requested_size_ = options.size; |
124 | 125 |
125 // Check if the shared memory pre-exists. | 126 // Check if the shared memory pre-exists. |
126 if (GetLastError() == ERROR_ALREADY_EXISTS) { | 127 if (GetLastError() == ERROR_ALREADY_EXISTS) { |
127 // If the file already existed, set requested_size_ to 0 to show that | 128 // If the file already existed, set requested_size_ to 0 to show that |
128 // we don't know the size. | 129 // we don't know the size. |
129 requested_size_ = 0; | 130 requested_size_ = 0; |
130 if (!options.open_existing) { | 131 if (!options.open_existing_deprecated) { |
131 Close(); | 132 Close(); |
132 return false; | 133 return false; |
133 } | 134 } |
134 } | 135 } |
135 | 136 |
136 return true; | 137 return true; |
137 } | 138 } |
138 | 139 |
139 bool SharedMemory::Delete(const std::string& name) { | 140 bool SharedMemory::Delete(const std::string& name) { |
140 // intentionally empty -- there is nothing for us to do on Windows. | 141 // intentionally empty -- there is nothing for us to do on Windows. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 void SharedMemory::UnlockDeprecated() { | 249 void SharedMemory::UnlockDeprecated() { |
249 DCHECK(lock_ != NULL); | 250 DCHECK(lock_ != NULL); |
250 ReleaseMutex(lock_); | 251 ReleaseMutex(lock_); |
251 } | 252 } |
252 | 253 |
253 SharedMemoryHandle SharedMemory::handle() const { | 254 SharedMemoryHandle SharedMemory::handle() const { |
254 return mapped_file_; | 255 return mapped_file_; |
255 } | 256 } |
256 | 257 |
257 } // namespace base | 258 } // namespace base |
OLD | NEW |