| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_PROFILES_STORAGE_PARTITION_DESCRIPTOR_H_ |
| 6 #define CHROME_BROWSER_PROFILES_STORAGE_PARTITION_DESCRIPTOR_H_ |
| 7 |
| 8 #include "base/file_path.h" |
| 9 #include "base/hash.h" |
| 10 #include "base/hash_tables.h" |
| 11 |
| 12 // This structure combines the on-disk path and a boolean whether the partition |
| 13 // should be persisted on disk. It's purpose is to serve as a unique key to |
| 14 // look up RequestContext objects in the ProfileIOData derived classes. |
| 15 struct StoragePartitionDescriptor { |
| 16 StoragePartitionDescriptor(const FilePath& partition_path, |
| 17 const bool in_memory_only) |
| 18 : path(partition_path), |
| 19 in_memory(in_memory_only) {} |
| 20 |
| 21 const FilePath path; |
| 22 const bool in_memory; |
| 23 }; |
| 24 |
| 25 // Functor for operator <. |
| 26 struct StoragePartitionDescriptorLess { |
| 27 bool operator()(const StoragePartitionDescriptor& lhs, |
| 28 const StoragePartitionDescriptor& rhs) const { |
| 29 if (lhs.path < rhs.path) |
| 30 return true; |
| 31 if (lhs.in_memory < rhs.in_memory) |
| 32 return true; |
| 33 |
| 34 return false; |
| 35 } |
| 36 }; |
| 37 |
| 38 // Functor for operator ==. |
| 39 struct StoragePartitionDescriptorEq { |
| 40 bool operator()(const StoragePartitionDescriptor& lhs, |
| 41 const StoragePartitionDescriptor& rhs) const { |
| 42 return lhs.path == rhs.path && lhs.in_memory == rhs.in_memory; |
| 43 } |
| 44 }; |
| 45 |
| 46 // Provide a hash function so that hash_sets and maps can contain |
| 47 // StoragePartitionDescriptor structs. |
| 48 namespace BASE_HASH_NAMESPACE { |
| 49 |
| 50 #if defined(COMPILER_MSVC) |
| 51 |
| 52 inline size_t hash_value(const StoragePartitionDescriptor& input) { |
| 53 size_t value = hash_value(input.path.value()); |
| 54 return input.in_memory ? value : value + 1; |
| 55 } |
| 56 |
| 57 #elif defined(COMPILER_GCC) |
| 58 |
| 59 template <> |
| 60 struct hash<StoragePartitionDescriptor> { |
| 61 size_t operator()(const StoragePartitionDescriptor& input) const { |
| 62 size_t value = hash<FilePath::StringType>()(input.path.value()); |
| 63 return input.in_memory ? value : value + 1; |
| 64 } |
| 65 }; |
| 66 |
| 67 #endif |
| 68 } // namespace BASE_HASH_NAMESPACE |
| 69 |
| 70 // A macro to typedef a hash_map, keyed by StoragePartitionDescriptor to lookup |
| 71 // other types. The goal is to save each place we use such map from including |
| 72 // all of this compiler specific syntax. |
| 73 #if defined(COMPILER_MSVC) |
| 74 #define DefineStoragePartitionDescriptorMap(_X_) \ |
| 75 typedef BASE_HASH_NAMESPACE::hash_map< \ |
| 76 StoragePartitionDescriptor, \ |
| 77 _X_, \ |
| 78 BASE_HASH_NAMESPACE::hash_compare<StoragePartitionDescriptor, \ |
| 79 StoragePartitionDescriptorLess> > |
| 80 #elif defined(COMPILER_GCC) |
| 81 #define DefineStoragePartitionDescriptorMap(_X_) \ |
| 82 typedef BASE_HASH_NAMESPACE::hash_map< \ |
| 83 StoragePartitionDescriptor, \ |
| 84 _X_, \ |
| 85 BASE_HASH_NAMESPACE::hash<StoragePartitionDescriptor>, \ |
| 86 StoragePartitionDescriptorEq> |
| 87 #endif |
| 88 |
| 89 #endif // CHROME_BROWSER_PROFILES_STORAGE_PARTITION_DESCRIPTOR_H_ |
| OLD | NEW |