Reduce header dependencies.
Random files in V8Bindings were getting rebuilt when I touched process_util.h. I tracked it down to stats_table.h and shared_memory.h. This change cuts down some dependencies there; more could be removed if we made some of our FooHandle typedefs into abstract data types instead. Review URL: http://codereview.chromium.org/7307 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3770 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
base
chrome/browser
@ -5,8 +5,9 @@
|
|||||||
#ifndef BASE_SHARED_MEMORY_H_
|
#ifndef BASE_SHARED_MEMORY_H_
|
||||||
#define BASE_SHARED_MEMORY_H_
|
#define BASE_SHARED_MEMORY_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include "base/basictypes.h"
|
#include "base/basictypes.h"
|
||||||
#include "base/process_util.h"
|
#include "base/process.h"
|
||||||
|
|
||||||
// SharedMemoryHandle is a platform specific type which represents
|
// SharedMemoryHandle is a platform specific type which represents
|
||||||
// the underlying OS handle to a shared memory segment.
|
// the underlying OS handle to a shared memory segment.
|
||||||
@ -44,13 +45,13 @@ class SharedMemory {
|
|||||||
// If open_existing is true, and the shared memory already exists,
|
// If open_existing is true, and the shared memory already exists,
|
||||||
// opens the existing shared memory and ignores the size parameter.
|
// opens the existing shared memory and ignores the size parameter.
|
||||||
// Returns true on success, false on failure.
|
// Returns true on success, false on failure.
|
||||||
bool Create(const std::wstring &name, bool read_only, bool open_existing,
|
bool Create(const std::wstring& name, bool read_only, bool open_existing,
|
||||||
size_t size);
|
size_t size);
|
||||||
|
|
||||||
// Opens a shared memory segment based on a name.
|
// Opens a shared memory segment based on a name.
|
||||||
// If read_only is true, opens for read-only access.
|
// If read_only is true, opens for read-only access.
|
||||||
// Returns true on success, false on failure.
|
// Returns true on success, false on failure.
|
||||||
bool Open(const std::wstring &name, bool read_only);
|
bool Open(const std::wstring& name, bool read_only);
|
||||||
|
|
||||||
// Maps the shared memory into the caller's address space.
|
// Maps the shared memory into the caller's address space.
|
||||||
// Returns true on success, false otherwise. The memory address
|
// Returns true on success, false otherwise. The memory address
|
||||||
@ -89,7 +90,7 @@ class SharedMemory {
|
|||||||
// the handle for use in the remote process.
|
// the handle for use in the remote process.
|
||||||
// Returns true on success, false otherwise.
|
// Returns true on success, false otherwise.
|
||||||
bool ShareToProcess(ProcessHandle process,
|
bool ShareToProcess(ProcessHandle process,
|
||||||
SharedMemoryHandle *new_handle) {
|
SharedMemoryHandle* new_handle) {
|
||||||
return ShareToProcessCommon(process, new_handle, false);
|
return ShareToProcessCommon(process, new_handle, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +99,7 @@ class SharedMemory {
|
|||||||
// Close();
|
// Close();
|
||||||
// return ok;
|
// return ok;
|
||||||
bool GiveToProcess(ProcessHandle process,
|
bool GiveToProcess(ProcessHandle process,
|
||||||
SharedMemoryHandle *new_handle) {
|
SharedMemoryHandle* new_handle) {
|
||||||
return ShareToProcessCommon(process, new_handle, true);
|
return ShareToProcessCommon(process, new_handle, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +116,8 @@ class SharedMemory {
|
|||||||
bool CreateOrOpen(const std::wstring &name, int posix_flags);
|
bool CreateOrOpen(const std::wstring &name, int posix_flags);
|
||||||
#endif
|
#endif
|
||||||
bool ShareToProcessCommon(ProcessHandle process,
|
bool ShareToProcessCommon(ProcessHandle process,
|
||||||
SharedMemoryHandle *new_handle, bool close_self);
|
SharedMemoryHandle* new_handle,
|
||||||
|
bool close_self);
|
||||||
|
|
||||||
std::wstring name_;
|
std::wstring name_;
|
||||||
SharedMemoryHandle mapped_file_;
|
SharedMemoryHandle mapped_file_;
|
||||||
@ -147,4 +149,3 @@ class SharedMemoryAutoLock {
|
|||||||
|
|
||||||
|
|
||||||
#endif // BASE_SHARED_MEMORY_H_
|
#endif // BASE_SHARED_MEMORY_H_
|
||||||
|
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
|
|
||||||
#include "base/stats_table.h"
|
#include "base/stats_table.h"
|
||||||
|
|
||||||
#include "base/string_util.h"
|
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "base/thread_local_storage.h"
|
|
||||||
#include "base/platform_thread.h"
|
#include "base/platform_thread.h"
|
||||||
|
#include "base/shared_memory.h"
|
||||||
|
#include "base/string_util.h"
|
||||||
|
#include "base/thread_local_storage.h"
|
||||||
|
|
||||||
#if defined(OS_POSIX)
|
#if defined(OS_POSIX)
|
||||||
#include "errno.h"
|
#include "errno.h"
|
||||||
@ -115,8 +116,12 @@ class StatsTablePrivate {
|
|||||||
int max_threads;
|
int max_threads;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the StatsTablePrivate based on expected size parameters.
|
// Construct a new StatsTablePrivate based on expected size parameters, or
|
||||||
StatsTablePrivate(void* memory, int size, int max_threads, int max_counters);
|
// return NULL on failure.
|
||||||
|
static StatsTablePrivate* New(const std::wstring& name, int size,
|
||||||
|
int max_threads, int max_counters);
|
||||||
|
|
||||||
|
SharedMemory* shared_memory() { return &shared_memory_; }
|
||||||
|
|
||||||
// Accessors for our header pointers
|
// Accessors for our header pointers
|
||||||
TableHeader* table_header() const { return table_header_; }
|
TableHeader* table_header() const { return table_header_; }
|
||||||
@ -145,6 +150,9 @@ class StatsTablePrivate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Constructor is private because you should use New() instead.
|
||||||
|
StatsTablePrivate() {}
|
||||||
|
|
||||||
// Initializes the table on first access. Sets header values
|
// Initializes the table on first access. Sets header values
|
||||||
// appropriately and zeroes all counters.
|
// appropriately and zeroes all counters.
|
||||||
void InitializeTable(void* memory, int size, int max_counters,
|
void InitializeTable(void* memory, int size, int max_counters,
|
||||||
@ -153,6 +161,7 @@ class StatsTablePrivate {
|
|||||||
// Initializes our in-memory pointers into a pre-created StatsTable.
|
// Initializes our in-memory pointers into a pre-created StatsTable.
|
||||||
void ComputeMappedPointers(void* memory);
|
void ComputeMappedPointers(void* memory);
|
||||||
|
|
||||||
|
SharedMemory shared_memory_;
|
||||||
TableHeader* table_header_;
|
TableHeader* table_header_;
|
||||||
wchar_t* thread_names_table_;
|
wchar_t* thread_names_table_;
|
||||||
int* thread_tid_table_;
|
int* thread_tid_table_;
|
||||||
@ -161,16 +170,30 @@ class StatsTablePrivate {
|
|||||||
int* data_table_;
|
int* data_table_;
|
||||||
};
|
};
|
||||||
|
|
||||||
StatsTablePrivate::StatsTablePrivate(void* memory, int size, int max_threads,
|
// static
|
||||||
int max_counters) {
|
StatsTablePrivate* StatsTablePrivate::New(const std::wstring& name,
|
||||||
|
int size,
|
||||||
|
int max_threads,
|
||||||
|
int max_counters) {
|
||||||
|
scoped_ptr<StatsTablePrivate> priv(new StatsTablePrivate());
|
||||||
|
|
||||||
|
if (!priv->shared_memory_.Create(name, false, true, size))
|
||||||
|
return NULL;
|
||||||
|
if (!priv->shared_memory_.Map(size))
|
||||||
|
return NULL;
|
||||||
|
void* memory = priv->shared_memory_.memory();
|
||||||
|
|
||||||
TableHeader* header = static_cast<TableHeader*>(memory);
|
TableHeader* header = static_cast<TableHeader*>(memory);
|
||||||
|
|
||||||
// If the version does not match, then assume the table needs
|
// If the version does not match, then assume the table needs
|
||||||
// to be initialized.
|
// to be initialized.
|
||||||
if (header->version != kTableVersion)
|
if (header->version != kTableVersion)
|
||||||
InitializeTable(memory, size, max_counters, max_threads);
|
priv->InitializeTable(memory, size, max_counters, max_threads);
|
||||||
|
|
||||||
// We have a valid table, so compute our pointers.
|
// We have a valid table, so compute our pointers.
|
||||||
ComputeMappedPointers(memory);
|
priv->ComputeMappedPointers(memory);
|
||||||
|
|
||||||
|
return priv.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatsTablePrivate::InitializeTable(void* memory, int size,
|
void StatsTablePrivate::InitializeTable(void* memory, int size,
|
||||||
@ -229,7 +252,8 @@ StatsTable* StatsTable::global_table_ = NULL;
|
|||||||
|
|
||||||
StatsTable::StatsTable(const std::wstring& name, int max_threads,
|
StatsTable::StatsTable(const std::wstring& name, int max_threads,
|
||||||
int max_counters)
|
int max_counters)
|
||||||
: tls_index_(SlotReturnFunction) {
|
: impl_(NULL),
|
||||||
|
tls_index_(SlotReturnFunction) {
|
||||||
int table_size =
|
int table_size =
|
||||||
AlignedSize(sizeof(StatsTablePrivate::TableHeader)) +
|
AlignedSize(sizeof(StatsTablePrivate::TableHeader)) +
|
||||||
AlignedSize((max_counters * sizeof(wchar_t) * kMaxCounterNameLength)) +
|
AlignedSize((max_counters * sizeof(wchar_t) * kMaxCounterNameLength)) +
|
||||||
@ -238,12 +262,9 @@ StatsTable::StatsTable(const std::wstring& name, int max_threads,
|
|||||||
AlignedSize(max_threads * sizeof(int)) +
|
AlignedSize(max_threads * sizeof(int)) +
|
||||||
AlignedSize((sizeof(int) * (max_counters * max_threads)));
|
AlignedSize((sizeof(int) * (max_counters * max_threads)));
|
||||||
|
|
||||||
impl_ = NULL;
|
impl_ = StatsTablePrivate::New(name, table_size, max_threads, max_counters);
|
||||||
// TODO(mbelshe): Move this out of the constructor
|
|
||||||
if (shared_memory_.Create(name, false, true, table_size))
|
// TODO(port): clean up this error reporting.
|
||||||
if (shared_memory_.Map(table_size))
|
|
||||||
impl_ = new StatsTablePrivate(shared_memory_.memory(), table_size,
|
|
||||||
max_threads, max_counters);
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
if (!impl_)
|
if (!impl_)
|
||||||
LOG(ERROR) << "StatsTable did not initialize:" << GetLastError();
|
LOG(ERROR) << "StatsTable did not initialize:" << GetLastError();
|
||||||
@ -277,7 +298,7 @@ int StatsTable::RegisterThread(const std::wstring& name) {
|
|||||||
// so that two threads don't grab the same slot. Fortunately,
|
// so that two threads don't grab the same slot. Fortunately,
|
||||||
// thread creation shouldn't happen in inner loops.
|
// thread creation shouldn't happen in inner loops.
|
||||||
{
|
{
|
||||||
SharedMemoryAutoLock lock(&shared_memory_);
|
SharedMemoryAutoLock lock(impl_->shared_memory());
|
||||||
slot = FindEmptyThread();
|
slot = FindEmptyThread();
|
||||||
if (!slot) {
|
if (!slot) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -433,7 +454,7 @@ int StatsTable::AddCounter(const std::wstring& name) {
|
|||||||
{
|
{
|
||||||
// To add a counter to the shared memory, we need the
|
// To add a counter to the shared memory, we need the
|
||||||
// shared memory lock.
|
// shared memory lock.
|
||||||
SharedMemoryAutoLock lock(&shared_memory_);
|
SharedMemoryAutoLock lock(impl_->shared_memory());
|
||||||
|
|
||||||
// We have space, so create a new counter.
|
// We have space, so create a new counter.
|
||||||
counter_id = FindCounterOrEmptyRow(name);
|
counter_id = FindCounterOrEmptyRow(name);
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include "base/basictypes.h"
|
#include "base/basictypes.h"
|
||||||
#include "base/hash_tables.h"
|
#include "base/hash_tables.h"
|
||||||
#include "base/lock.h"
|
#include "base/lock.h"
|
||||||
#include "base/shared_memory.h"
|
|
||||||
#include "base/thread_local_storage.h"
|
#include "base/thread_local_storage.h"
|
||||||
|
|
||||||
class StatsTablePrivate;
|
class StatsTablePrivate;
|
||||||
@ -165,7 +164,6 @@ class StatsTable {
|
|||||||
typedef base::hash_map<std::wstring, int> CountersMap;
|
typedef base::hash_map<std::wstring, int> CountersMap;
|
||||||
|
|
||||||
bool opened_;
|
bool opened_;
|
||||||
SharedMemory shared_memory_;
|
|
||||||
StatsTablePrivate* impl_;
|
StatsTablePrivate* impl_;
|
||||||
// The counters_lock_ protects the counters_ hash table.
|
// The counters_lock_ protects the counters_ hash table.
|
||||||
Lock counters_lock_;
|
Lock counters_lock_;
|
||||||
@ -182,4 +180,3 @@ class StatsTable {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif // BASE_STATS_TABLE_H__
|
#endif // BASE_STATS_TABLE_H__
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "chrome/browser/automation/automation_provider.h"
|
#include "chrome/browser/automation/automation_provider.h"
|
||||||
|
|
||||||
#include "base/path_service.h"
|
#include "base/path_service.h"
|
||||||
|
#include "base/process_util.h"
|
||||||
#include "chrome/app/chrome_dll_resource.h"
|
#include "chrome/app/chrome_dll_resource.h"
|
||||||
#include "chrome/browser/automation/automation_provider_list.h"
|
#include "chrome/browser/automation/automation_provider_list.h"
|
||||||
#include "chrome/browser/automation/ui_controls.h"
|
#include "chrome/browser/automation/ui_controls.h"
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "base/file_util.h"
|
#include "base/file_util.h"
|
||||||
#include "base/histogram.h"
|
#include "base/histogram.h"
|
||||||
#include "base/path_service.h"
|
#include "base/path_service.h"
|
||||||
|
#include "base/process_util.h"
|
||||||
#include "base/string_util.h"
|
#include "base/string_util.h"
|
||||||
#include "base/win_util.h"
|
#include "base/win_util.h"
|
||||||
#include "chrome/app/locales/locale_settings.h"
|
#include "chrome/app/locales/locale_settings.h"
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "base/gfx/vector_canvas.h"
|
#include "base/gfx/vector_canvas.h"
|
||||||
#include "base/histogram.h"
|
#include "base/histogram.h"
|
||||||
#include "base/path_service.h"
|
#include "base/path_service.h"
|
||||||
|
#include "base/process_util.h"
|
||||||
#include "base/registry.h"
|
#include "base/registry.h"
|
||||||
#include "base/string_util.h"
|
#include "base/string_util.h"
|
||||||
#include "base/tracked_objects.h"
|
#include "base/tracked_objects.h"
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
#include "base/compiler_specific.h"
|
#include "base/compiler_specific.h"
|
||||||
#include "base/file_version_info.h"
|
#include "base/file_version_info.h"
|
||||||
|
#include "base/process_util.h"
|
||||||
#include "chrome/app/locales/locale_settings.h"
|
#include "chrome/app/locales/locale_settings.h"
|
||||||
#include "chrome/browser/bookmarks/bookmark_model.h"
|
#include "chrome/browser/bookmarks/bookmark_model.h"
|
||||||
#include "chrome/browser/browser.h"
|
#include "chrome/browser/browser.h"
|
||||||
|
Reference in New Issue
Block a user