diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-29 20:32:22 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-29 20:32:22 +0000 |
commit | b6413b49b4a1bf216bbc70cc330e905c42db5c5b (patch) | |
tree | 1ea76480a59217bd06dadcb071dad2d8150a6518 /base | |
parent | a6c642112b067d998e699e09302d8c48649b108f (diff) | |
download | chromium_src-b6413b49b4a1bf216bbc70cc330e905c42db5c5b.zip chromium_src-b6413b49b4a1bf216bbc70cc330e905c42db5c5b.tar.gz chromium_src-b6413b49b4a1bf216bbc70cc330e905c42db5c5b.tar.bz2 |
shared_memory: remove wstrings, fix callers.
BUG=23581
TEST=compiles
Review URL: http://codereview.chromium.org/3555002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60985 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/shared_memory.h | 11 | ||||
-rw-r--r-- | base/shared_memory_posix.cc | 23 | ||||
-rw-r--r-- | base/shared_memory_unittest.cc | 16 | ||||
-rw-r--r-- | base/shared_memory_win.cc | 15 | ||||
-rw-r--r-- | base/stats_table.cc | 2 | ||||
-rw-r--r-- | base/stats_table_unittest.cc | 4 |
6 files changed, 35 insertions, 36 deletions
diff --git a/base/shared_memory.h b/base/shared_memory.h index 1f7cc26..053026e 100644 --- a/base/shared_memory.h +++ b/base/shared_memory.h @@ -72,18 +72,18 @@ class SharedMemory { // opens the existing shared memory and ignores the size parameter. // If name is the empty string, use a unique name. // Returns true on success, false on failure. - bool Create(const std::wstring& name, bool read_only, bool open_existing, + bool Create(const std::string& name, bool read_only, bool open_existing, uint32 size); // Deletes resources associated with a shared memory segment based on name. // Not all platforms require this call. - bool Delete(const std::wstring& name); + bool Delete(const std::string& name); // Opens a shared memory segment based on a name. // If read_only is true, opens for read-only access. // If name is the empty string, use a unique name. // Returns true on success, false on failure. - bool Open(const std::wstring& name, bool read_only); + bool Open(const std::string& name, bool read_only); // Maps the shared memory into the caller's address space. // Returns true on success, false otherwise. The memory address @@ -161,10 +161,9 @@ class SharedMemory { private: #if defined(OS_POSIX) - bool CreateOrOpen(const std::wstring &name, int posix_flags, uint32 size); - bool FilePathForMemoryName(const std::wstring& memname, FilePath* path); + bool CreateOrOpen(const std::string& name, int posix_flags, uint32 size); + bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); void LockOrUnlockCommon(int function); - #endif bool ShareToProcessCommon(ProcessHandle process, SharedMemoryHandle* new_handle, diff --git a/base/shared_memory_posix.cc b/base/shared_memory_posix.cc index 2dae8af..32b3dae7 100644 --- a/base/shared_memory_posix.cc +++ b/base/shared_memory_posix.cc @@ -77,7 +77,7 @@ void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) { close(handle.fd); } -bool SharedMemory::Create(const std::wstring &name, bool read_only, +bool SharedMemory::Create(const std::string& name, bool read_only, bool open_existing, uint32 size) { read_only_ = read_only; @@ -96,7 +96,7 @@ bool SharedMemory::Create(const std::wstring &name, bool read_only, // Our current implementation of shmem is with mmap()ing of files. // These files need to be deleted explicitly. // In practice this call is only needed for unit tests. -bool SharedMemory::Delete(const std::wstring& name) { +bool SharedMemory::Delete(const std::string& name) { FilePath path; if (!FilePathForMemoryName(name, &path)) return false; @@ -109,7 +109,7 @@ bool SharedMemory::Delete(const std::wstring& name) { return true; } -bool SharedMemory::Open(const std::wstring &name, bool read_only) { +bool SharedMemory::Open(const std::string& name, bool read_only) { read_only_ = read_only; int posix_flags = 0; @@ -118,22 +118,21 @@ bool SharedMemory::Open(const std::wstring &name, bool read_only) { return CreateOrOpen(name, posix_flags, 0); } -// For the given shmem named |memname|, return a filename to mmap() +// For the given shmem named |mem_name|, return a filename to mmap() // (and possibly create). Modifies |filename|. Return false on // error, or true of we are happy. -bool SharedMemory::FilePathForMemoryName(const std::wstring& memname, +bool SharedMemory::FilePathForMemoryName(const std::string& mem_name, FilePath* path) { // mem_name will be used for a filename; make sure it doesn't // contain anything which will confuse us. - DCHECK(memname.find_first_of(L"/") == std::string::npos); - DCHECK(memname.find_first_of(L"\0") == std::string::npos); + DCHECK(mem_name.find('/') == std::string::npos); + DCHECK(mem_name.find('\0') == std::string::npos); FilePath temp_dir; - if (file_util::GetShmemTempDir(&temp_dir) == false) + if (!file_util::GetShmemTempDir(&temp_dir)) return false; - *path = temp_dir.AppendASCII("com.google.chrome.shmem." + - WideToUTF8(memname)); + *path = temp_dir.AppendASCII("com.google.chrome.shmem." + mem_name); return true; } @@ -143,7 +142,7 @@ bool SharedMemory::FilePathForMemoryName(const std::wstring& memname, // we restart from a crash. (That isn't a new problem, but it is a problem.) // In case we want to delete it later, it may be useful to save the value // of mem_filename after FilePathForMemoryName(). -bool SharedMemory::CreateOrOpen(const std::wstring &name, +bool SharedMemory::CreateOrOpen(const std::string& name, int posix_flags, uint32 size) { DCHECK(mapped_file_ == -1); @@ -151,7 +150,7 @@ bool SharedMemory::CreateOrOpen(const std::wstring &name, FILE *fp; FilePath path; - if (name == L"") { + if (name.empty()) { // It doesn't make sense to have a read-only private piece of shmem DCHECK(posix_flags & (O_RDWR | O_WRONLY)); diff --git a/base/shared_memory_unittest.cc b/base/shared_memory_unittest.cc index 4e83311..97287fa 100644 --- a/base/shared_memory_unittest.cc +++ b/base/shared_memory_unittest.cc @@ -55,13 +55,13 @@ class MultipleThreadMain : public PlatformThread::Delegate { private: int16 id_; - static const wchar_t* const s_test_name_; + static const char* const s_test_name_; DISALLOW_COPY_AND_ASSIGN(MultipleThreadMain); }; -const wchar_t* const MultipleThreadMain::s_test_name_ = - L"SharedMemoryOpenThreadTest"; +const char* const MultipleThreadMain::s_test_name_ = + "SharedMemoryOpenThreadTest"; // TODO(port): // This test requires the ability to pass file descriptors between processes. @@ -82,7 +82,7 @@ class MultipleLockThread : public PlatformThread::Delegate { SharedMemoryHandle handle = NULL; { SharedMemory memory1; - EXPECT_TRUE(memory1.Create(L"SharedMemoryMultipleLockThreadTest", + EXPECT_TRUE(memory1.Create("SharedMemoryMultipleLockThreadTest", false, true, kDataSize)); EXPECT_TRUE(memory1.ShareToProcess(GetCurrentProcess(), &handle)); // TODO(paulg): Implement this once we have a posix version of @@ -117,7 +117,7 @@ class MultipleLockThread : public PlatformThread::Delegate { TEST(SharedMemoryTest, OpenClose) { const uint32 kDataSize = 1024; - std::wstring test_name = L"SharedMemoryOpenCloseTest"; + std::string test_name = "SharedMemoryOpenCloseTest"; // Open two handles to a memory segment, confirm that they are mapped // separately yet point to the same space. @@ -243,7 +243,7 @@ TEST(SharedMemoryTest, AnonymousPrivate) { ASSERT_TRUE(pointers.get()); for (i = 0; i < count; i++) { - rv = memories[i].Create(L"", false, true, kDataSize); + rv = memories[i].Create("", false, true, kDataSize); EXPECT_TRUE(rv); rv = memories[i].Map(kDataSize); EXPECT_TRUE(rv); @@ -314,10 +314,10 @@ class SharedMemoryProcessTest : public base::MultiProcessTest { } private: - static const wchar_t* const s_test_name_; + static const char* const s_test_name_; }; -const wchar_t* const SharedMemoryProcessTest::s_test_name_ = L"MPMem"; +const char* const SharedMemoryProcessTest::s_test_name_ = "MPMem"; TEST_F(SharedMemoryProcessTest, Tasks) { diff --git a/base/shared_memory_win.cc b/base/shared_memory_win.cc index 7974e14..f35ada1 100644 --- a/base/shared_memory_win.cc +++ b/base/shared_memory_win.cc @@ -5,6 +5,7 @@ #include "base/shared_memory.h" #include "base/logging.h" +#include "base/utf_string_conversions.h" namespace base { @@ -60,7 +61,7 @@ void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) { ::CloseHandle(handle); } -bool SharedMemory::Create(const std::wstring &name, bool read_only, +bool SharedMemory::Create(const std::string& name, bool read_only, bool open_existing, uint32 size) { DCHECK(mapped_file_ == NULL); @@ -70,12 +71,12 @@ bool SharedMemory::Create(const std::wstring &name, bool read_only, // To avoid client impact, we continue to retain the size as the // actual requested size. uint32 rounded_size = (size + 0xffff) & ~0xffff; - name_ = name; + name_ = ASCIIToWide(name); read_only_ = read_only; mapped_file_ = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, read_only_ ? PAGE_READONLY : PAGE_READWRITE, 0, static_cast<DWORD>(rounded_size), - name.empty() ? NULL : name.c_str()); + name_.empty() ? NULL : name_.c_str()); if (!mapped_file_) return false; @@ -88,19 +89,19 @@ bool SharedMemory::Create(const std::wstring &name, bool read_only, return true; } -bool SharedMemory::Delete(const std::wstring& name) { +bool SharedMemory::Delete(const std::string& name) { // intentionally empty -- there is nothing for us to do on Windows. return true; } -bool SharedMemory::Open(const std::wstring &name, bool read_only) { +bool SharedMemory::Open(const std::string& name, bool read_only) { DCHECK(mapped_file_ == NULL); - name_ = name; + name_ = ASCIIToWide(name); read_only_ = read_only; mapped_file_ = OpenFileMapping( read_only_ ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS, false, - name.empty() ? NULL : name.c_str()); + name_.empty() ? NULL : name_.c_str()); if (mapped_file_ != NULL) { // Note: size_ is not set in this case. return true; diff --git a/base/stats_table.cc b/base/stats_table.cc index 2edbb44..2ef78e8 100644 --- a/base/stats_table.cc +++ b/base/stats_table.cc @@ -170,7 +170,7 @@ StatsTablePrivate* StatsTablePrivate::New(const std::string& name, int max_threads, int max_counters) { scoped_ptr<StatsTablePrivate> priv(new StatsTablePrivate()); - if (!priv->shared_memory_.Create(UTF8ToWide(name), false, true, size)) + if (!priv->shared_memory_.Create(name, false, true, size)) return NULL; if (!priv->shared_memory_.Map(size)) return NULL; diff --git a/base/stats_table_unittest.cc b/base/stats_table_unittest.cc index 4fd79b5..f926f29 100644 --- a/base/stats_table_unittest.cc +++ b/base/stats_table_unittest.cc @@ -23,9 +23,9 @@ namespace base { class StatsTableTest : public MultiProcessTest { public: - void DeleteShmem(std::string name) { + void DeleteShmem(const std::string& name) { base::SharedMemory mem; - mem.Delete(UTF8ToWide(name)); + mem.Delete(name); } }; |