Chromium Code Reviews| 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_STORAGE_PARTITION_DETAILS_H_ | |
| 6 #define CHROME_BROWSER_STORAGE_PARTITION_DETAILS_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 profile. | |
| 15 struct StoragePartitionDetails { | |
|
awong
2012/10/18 22:36:15
nit: Can we call this StoragePartitionDescriptor o
nasko
2012/10/19 17:29:14
Done.
| |
| 16 const FilePath path; | |
| 17 const bool in_memory; | |
| 18 | |
| 19 StoragePartitionDetails(const FilePath& partition_path, | |
|
awong
2012/10/18 22:36:15
The constructor should come first in declaration o
nasko
2012/10/19 17:29:14
Done.
| |
| 20 const bool in_memory_only) | |
| 21 : path(partition_path), | |
| 22 in_memory(in_memory_only) {} | |
| 23 | |
| 24 }; | |
| 25 | |
| 26 // Functor for operator <. | |
| 27 struct StoragePartitionDetailsLess { | |
| 28 bool operator()(const StoragePartitionDetails& left, | |
|
awong
2012/10/18 22:36:15
lhs and rhs seem to be more common than "left" and
nasko
2012/10/19 17:29:14
Done.
| |
| 29 const StoragePartitionDetails& right) const { | |
| 30 if (left.path < right.path) | |
| 31 return true; | |
| 32 if (left.in_memory != right.in_memory) | |
|
awong
2012/10/18 22:36:15
This isn't a valid Strict Weak Ordering which stl
nasko
2012/10/19 17:29:14
Done.
| |
| 33 return true; | |
| 34 | |
| 35 return false; | |
| 36 } | |
| 37 }; | |
| 38 | |
| 39 // Functor for operator ==. | |
| 40 struct StoragePartitionDetailsEq { | |
| 41 bool operator()(const StoragePartitionDetails& left, | |
| 42 const StoragePartitionDetails& right) const { | |
|
awong
2012/10/18 22:36:15
Simplify to
return left.path == right.path && lef
nasko
2012/10/19 17:29:14
Done.
| |
| 43 if (left.path != right.path) | |
| 44 return false; | |
| 45 if (left.in_memory != right.in_memory) | |
| 46 return false; | |
| 47 | |
| 48 return true; | |
| 49 } | |
| 50 }; | |
| 51 | |
| 52 // Provide a hash function so that hash_sets and maps can contain | |
| 53 // StoragePartitionDetails structs. | |
| 54 namespace BASE_HASH_NAMESPACE { | |
| 55 | |
| 56 #if defined(COMPILER_MSVC) | |
| 57 | |
| 58 inline size_t hash_value(const StoragePartitionDetails& input) { | |
| 59 size_t value = hash_value(input.path.value()); | |
| 60 return input.in_memory ? value : value + 1; | |
| 61 } | |
| 62 | |
| 63 #elif defined(COMPILER_GCC) | |
| 64 | |
| 65 template <> | |
| 66 struct hash<StoragePartitionDetails> { | |
| 67 size_t operator()(const StoragePartitionDetails& input) const { | |
| 68 size_t value = hash<FilePath::StringType>()(input.path.value()); | |
| 69 return input.in_memory ? value : value + 1; | |
|
awong
2012/10/18 22:36:15
My hash algorithm OCDness really wants to say this
nasko
2012/10/19 17:29:14
Done.
| |
| 70 } | |
| 71 }; | |
| 72 | |
| 73 #endif | |
| 74 } // namespace BASE_HASH_NAMESPACE | |
| 75 | |
| 76 // A macro to typedef a hash_map, keyed by StoragePartitionDetails to lookup | |
| 77 // other types. The goal is to save each place we use such map from including | |
| 78 // all of this compiler specific syntax. | |
| 79 #if defined(COMPILER_MSVC) | |
| 80 #define DefineStoragePartitionDetailsMap(_X_) \ | |
| 81 typedef BASE_HASH_NAMESPACE::hash_map< \ | |
| 82 StoragePartitionDetails, \ | |
| 83 _X_, \ | |
| 84 BASE_HASH_NAMESPACE::hash_compare<StoragePartitionDetails, \ | |
| 85 StoragePartitionDetailsLess> > | |
| 86 #elif defined(COMPILER_GCC) | |
| 87 #define DefineStoragePartitionDetailsMap(_X_) \ | |
| 88 typedef BASE_HASH_NAMESPACE::hash_map< \ | |
| 89 StoragePartitionDetails, \ | |
| 90 _X_, \ | |
| 91 BASE_HASH_NAMESPACE::hash<StoragePartitionDetails>, \ | |
| 92 StoragePartitionDetailsEq> | |
| 93 #endif | |
| 94 | |
| 95 #endif // CHROME_BROWSER_STORAGE_PARTITION_DETAILS_H_ | |
| OLD | NEW |