| Index: chrome/browser/profiles/storage_partition_descriptor.h
|
| diff --git a/chrome/browser/profiles/storage_partition_descriptor.h b/chrome/browser/profiles/storage_partition_descriptor.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..664f1b6f7751e354eaa43afd8f8b4a7fbcab7203
|
| --- /dev/null
|
| +++ b/chrome/browser/profiles/storage_partition_descriptor.h
|
| @@ -0,0 +1,89 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CHROME_BROWSER_PROFILES_STORAGE_PARTITION_DESCRIPTOR_H_
|
| +#define CHROME_BROWSER_PROFILES_STORAGE_PARTITION_DESCRIPTOR_H_
|
| +
|
| +#include "base/file_path.h"
|
| +#include "base/hash.h"
|
| +#include "base/hash_tables.h"
|
| +
|
| +// This structure combines the on-disk path and a boolean whether the partition
|
| +// should be persisted on disk. It's purpose is to serve as a unique key to
|
| +// look up RequestContext objects in the ProfileIOData derived classes.
|
| +struct StoragePartitionDescriptor {
|
| + StoragePartitionDescriptor(const FilePath& partition_path,
|
| + const bool in_memory_only)
|
| + : path(partition_path),
|
| + in_memory(in_memory_only) {}
|
| +
|
| + const FilePath path;
|
| + const bool in_memory;
|
| +};
|
| +
|
| +// Functor for operator <.
|
| +struct StoragePartitionDescriptorLess {
|
| + bool operator()(const StoragePartitionDescriptor& lhs,
|
| + const StoragePartitionDescriptor& rhs) const {
|
| + if (lhs.path < rhs.path)
|
| + return true;
|
| + if (lhs.in_memory < rhs.in_memory)
|
| + return true;
|
| +
|
| + return false;
|
| + }
|
| +};
|
| +
|
| +// Functor for operator ==.
|
| +struct StoragePartitionDescriptorEq {
|
| + bool operator()(const StoragePartitionDescriptor& lhs,
|
| + const StoragePartitionDescriptor& rhs) const {
|
| + return lhs.path == rhs.path && lhs.in_memory == rhs.in_memory;
|
| + }
|
| +};
|
| +
|
| +// Provide a hash function so that hash_sets and maps can contain
|
| +// StoragePartitionDescriptor structs.
|
| +namespace BASE_HASH_NAMESPACE {
|
| +
|
| +#if defined(COMPILER_MSVC)
|
| +
|
| +inline size_t hash_value(const StoragePartitionDescriptor& input) {
|
| + size_t value = hash_value(input.path.value());
|
| + return input.in_memory ? value : value + 1;
|
| +}
|
| +
|
| +#elif defined(COMPILER_GCC)
|
| +
|
| +template <>
|
| +struct hash<StoragePartitionDescriptor> {
|
| + size_t operator()(const StoragePartitionDescriptor& input) const {
|
| + size_t value = hash<FilePath::StringType>()(input.path.value());
|
| + return input.in_memory ? value : value + 1;
|
| + }
|
| +};
|
| +
|
| +#endif
|
| +} // namespace BASE_HASH_NAMESPACE
|
| +
|
| +// A macro to typedef a hash_map, keyed by StoragePartitionDescriptor to lookup
|
| +// other types. The goal is to save each place we use such map from including
|
| +// all of this compiler specific syntax.
|
| +#if defined(COMPILER_MSVC)
|
| + #define DefineStoragePartitionDescriptorMap(_X_) \
|
| + typedef BASE_HASH_NAMESPACE::hash_map< \
|
| + StoragePartitionDescriptor, \
|
| + _X_, \
|
| + BASE_HASH_NAMESPACE::hash_compare<StoragePartitionDescriptor, \
|
| + StoragePartitionDescriptorLess> >
|
| +#elif defined(COMPILER_GCC)
|
| + #define DefineStoragePartitionDescriptorMap(_X_) \
|
| + typedef BASE_HASH_NAMESPACE::hash_map< \
|
| + StoragePartitionDescriptor, \
|
| + _X_, \
|
| + BASE_HASH_NAMESPACE::hash<StoragePartitionDescriptor>, \
|
| + StoragePartitionDescriptorEq>
|
| +#endif
|
| +
|
| +#endif // CHROME_BROWSER_PROFILES_STORAGE_PARTITION_DESCRIPTOR_H_
|
|
|