Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2689)

Unified Diff: chrome/browser/storage_partition_details.h

Issue 11147026: Initial refactor to get profiles to propagate storage partition details. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changing bool param to pass by reference. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/storage_partition_details.h
diff --git a/chrome/browser/storage_partition_details.h b/chrome/browser/storage_partition_details.h
new file mode 100644
index 0000000000000000000000000000000000000000..4856d28b261e43d194edddaa61d90c29e77ec077
--- /dev/null
+++ b/chrome/browser/storage_partition_details.h
@@ -0,0 +1,95 @@
+// 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_STORAGE_PARTITION_DETAILS_H_
+#define CHROME_BROWSER_STORAGE_PARTITION_DETAILS_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 profile.
+struct StoragePartitionDetails {
awong 2012/10/18 22:36:15 nit: Can we call this StoragePartitionDescriptor o
nasko 2012/10/19 17:29:14 Done.
+ const FilePath path;
+ const bool in_memory;
+
+ 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.
+ const bool in_memory_only)
+ : path(partition_path),
+ in_memory(in_memory_only) {}
+
+};
+
+// Functor for operator <.
+struct StoragePartitionDetailsLess {
+ 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.
+ const StoragePartitionDetails& right) const {
+ if (left.path < right.path)
+ return true;
+ 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.
+ return true;
+
+ return false;
+ }
+};
+
+// Functor for operator ==.
+struct StoragePartitionDetailsEq {
+ bool operator()(const StoragePartitionDetails& left,
+ 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.
+ if (left.path != right.path)
+ return false;
+ if (left.in_memory != right.in_memory)
+ return false;
+
+ return true;
+ }
+};
+
+// Provide a hash function so that hash_sets and maps can contain
+// StoragePartitionDetails structs.
+namespace BASE_HASH_NAMESPACE {
+
+#if defined(COMPILER_MSVC)
+
+inline size_t hash_value(const StoragePartitionDetails& input) {
+ size_t value = hash_value(input.path.value());
+ return input.in_memory ? value : value + 1;
+}
+
+#elif defined(COMPILER_GCC)
+
+template <>
+struct hash<StoragePartitionDetails> {
+ size_t operator()(const StoragePartitionDetails& input) const {
+ size_t value = hash<FilePath::StringType>()(input.path.value());
+ 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.
+ }
+};
+
+#endif
+} // namespace BASE_HASH_NAMESPACE
+
+// A macro to typedef a hash_map, keyed by StoragePartitionDetails 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 DefineStoragePartitionDetailsMap(_X_) \
+ typedef BASE_HASH_NAMESPACE::hash_map< \
+ StoragePartitionDetails, \
+ _X_, \
+ BASE_HASH_NAMESPACE::hash_compare<StoragePartitionDetails, \
+ StoragePartitionDetailsLess> >
+#elif defined(COMPILER_GCC)
+ #define DefineStoragePartitionDetailsMap(_X_) \
+ typedef BASE_HASH_NAMESPACE::hash_map< \
+ StoragePartitionDetails, \
+ _X_, \
+ BASE_HASH_NAMESPACE::hash<StoragePartitionDetails>, \
+ StoragePartitionDetailsEq>
+#endif
+
+#endif // CHROME_BROWSER_STORAGE_PARTITION_DETAILS_H_

Powered by Google App Engine
This is Rietveld 408576698