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

Unified Diff: content/browser/storage_partition_map.cc

Issue 10600009: Support partitioning of storage contexts based on render_id. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Forgot a funciton. Created 8 years, 5 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: content/browser/storage_partition_map.cc
diff --git a/content/browser/storage_partition_map.cc b/content/browser/storage_partition_map.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f25a0d29c8f1f53fe75a3d285e7c11c75c1a64cd
--- /dev/null
+++ b/content/browser/storage_partition_map.cc
@@ -0,0 +1,91 @@
+// 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.
+
+#include "content/browser/storage_partition_map.h"
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/file_path.h"
+#include "base/stl_util.h"
+#include "base/string_util.h"
+#include "content/browser/appcache/chrome_appcache_service.h"
+#include "content/browser/resource_context_impl.h"
+#include "content/browser/storage_partition.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/common/content_constants.h"
+
+using content::BrowserThread;
+
+// Dirname for storing persistent data for renderers with isolated storage.
+const FilePath::CharType kStoragePartitionDirName[] =
+ FILE_PATH_LITERAL("Storage Partitions");
+StoragePartitionMap::StoragePartitionMap(
+ content::BrowserContext* browser_context)
+ : browser_context_(browser_context) {
+}
+
+StoragePartitionMap::~StoragePartitionMap() {
+ STLDeleteContainerPairSecondPointers(partitions_.begin(),
+ partitions_.end());
+}
+
+StoragePartition* StoragePartitionMap::Get(const std::string& partition_id) {
+ // Find the previously created partition if it's available.
+ std::map<std::string, StoragePartition*>::const_iterator it =
+ partitions_.find(partition_id);
+ if (it != partitions_.end())
+ return it->second;
+
+ // There was no previous partition, so let's make a new one.
+ FilePath partition_path = browser_context_->GetPath();
+ if (!partition_id.empty()) {
+ // TODO(ajwong): This should check the pth is valid?
+ CHECK(IsStringASCII(partition_id));
+ partition_path = partition_path.Append(kStoragePartitionDirName)
+ .AppendASCII(partition_id);
+ }
+
+ StoragePartition* storage_partition =
+ StoragePartition::Create(browser_context_, partition_path);
+ partitions_[partition_id] = storage_partition;
+
+ PostCreateInitialization(storage_partition, partition_path);
+
+ // TODO(ajwong): We need to remove this conditional by making
+ // InitializeResourceContext() understand having different partition data
+ // based on the renderer_id.
+ if (partition_id.empty()) {
+ InitializeResourceContext(browser_context_);
+ }
+
+ return storage_partition;
+}
+
+void StoragePartitionMap::ForEach(
+ const base::Callback<void(StoragePartition*)>& callback) {
+ for (std::map<std::string, StoragePartition*>::const_iterator it =
+ partitions_.begin();
+ it != partitions_.end();
+ ++it) {
+ callback.Run(it->second);
+ }
+}
+
+void StoragePartitionMap::PostCreateInitialization(
+ StoragePartition* partition,
+ const FilePath& partition_path) {
+ // Check first to avoid memory leak in unittests.
+ if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&ChromeAppCacheService::InitializeOnIOThread,
+ partition->appcache_service(),
+ browser_context_->IsOffTheRecord() ? FilePath() :
+ partition_path.Append(content::kAppCacheDirname),
+ browser_context_->GetResourceContext(),
+ make_scoped_refptr(
+ browser_context_->GetSpecialStoragePolicy())));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698