| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/public/browser/browser_context.h" | 5 #include "content/public/browser/browser_context.h" |
| 6 | 6 |
| 7 #include "content/browser/appcache/chrome_appcache_service.h" | 7 #include "content/browser/appcache/chrome_appcache_service.h" |
| 8 #include "webkit/database/database_tracker.h" | 8 #include "webkit/database/database_tracker.h" |
| 9 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 9 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
| 10 #include "content/browser/download/download_file_manager.h" | 10 #include "content/browser/download/download_file_manager.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 using base::UserDataAdapter; | 26 using base::UserDataAdapter; |
| 27 | 27 |
| 28 // Key names on BrowserContext. | 28 // Key names on BrowserContext. |
| 29 static const char* kDownloadManagerKeyName = "download_manager"; | 29 static const char* kDownloadManagerKeyName = "download_manager"; |
| 30 static const char* kStorageParitionMapKeyName = "content_storage_partition_map"; | 30 static const char* kStorageParitionMapKeyName = "content_storage_partition_map"; |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 StoragePartition* GetStoragePartition(BrowserContext* browser_context, | 36 StoragePartition* GetStoragePartitionByPartitionId( |
| 37 int renderer_child_id) { | 37 BrowserContext* browser_context, |
| 38 const std::string& partition_id) { |
| 38 StoragePartitionMap* partition_map = static_cast<StoragePartitionMap*>( | 39 StoragePartitionMap* partition_map = static_cast<StoragePartitionMap*>( |
| 39 browser_context->GetUserData(kStorageParitionMapKeyName)); | 40 browser_context->GetUserData(kStorageParitionMapKeyName)); |
| 40 if (!partition_map) { | 41 if (!partition_map) { |
| 41 partition_map = new StoragePartitionMap(browser_context); | 42 partition_map = new StoragePartitionMap(browser_context); |
| 42 browser_context->SetUserData(kStorageParitionMapKeyName, partition_map); | 43 browser_context->SetUserData(kStorageParitionMapKeyName, partition_map); |
| 43 } | 44 } |
| 44 | 45 |
| 46 return partition_map->Get(partition_id); |
| 47 } |
| 48 |
| 49 StoragePartition* GetStoragePartition(BrowserContext* browser_context, |
| 50 int renderer_child_id) { |
| 45 const std::string& partition_id = | 51 const std::string& partition_id = |
| 46 GetContentClient()->browser()->GetStoragePartitionIdForChildProcess( | 52 GetContentClient()->browser()->GetStoragePartitionIdForChildProcess( |
| 47 browser_context, | 53 browser_context, |
| 48 renderer_child_id); | 54 renderer_child_id); |
| 49 | 55 |
| 50 return partition_map->Get(partition_id); | 56 return GetStoragePartitionByPartitionId(browser_context, partition_id); |
| 51 } | 57 } |
| 52 | 58 |
| 53 // Run |callback| on each storage partition in |browser_context|. | 59 // Run |callback| on each storage partition in |browser_context|. |
| 54 void ForEachStoragePartition( | 60 void ForEachStoragePartition( |
| 55 BrowserContext* browser_context, | 61 BrowserContext* browser_context, |
| 56 const base::Callback<void(StoragePartition*)>& callback) { | 62 const base::Callback<void(StoragePartition*)>& callback) { |
| 57 StoragePartitionMap* partition_map = static_cast<StoragePartitionMap*>( | 63 StoragePartitionMap* partition_map = static_cast<StoragePartitionMap*>( |
| 58 browser_context->GetUserData(kStorageParitionMapKeyName)); | 64 browser_context->GetUserData(kStorageParitionMapKeyName)); |
| 59 if (!partition_map) { | 65 if (!partition_map) { |
| 60 return; | 66 return; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 156 } |
| 151 | 157 |
| 152 DOMStorageContext* BrowserContext::GetDOMStorageContext( | 158 DOMStorageContext* BrowserContext::GetDOMStorageContext( |
| 153 BrowserContext* browser_context, | 159 BrowserContext* browser_context, |
| 154 int render_child_id) { | 160 int render_child_id) { |
| 155 StoragePartition* partition = | 161 StoragePartition* partition = |
| 156 GetStoragePartition(browser_context, render_child_id); | 162 GetStoragePartition(browser_context, render_child_id); |
| 157 return partition->dom_storage_context(); | 163 return partition->dom_storage_context(); |
| 158 } | 164 } |
| 159 | 165 |
| 166 DOMStorageContext* BrowserContext::GetDOMStorageContextByPartitionId( |
| 167 BrowserContext* browser_context, |
| 168 const std::string& partition_id) { |
| 169 StoragePartition* partition = |
| 170 GetStoragePartitionByPartitionId(browser_context, partition_id); |
| 171 return partition->dom_storage_context(); |
| 172 } |
| 173 |
| 160 IndexedDBContext* BrowserContext::GetIndexedDBContext( | 174 IndexedDBContext* BrowserContext::GetIndexedDBContext( |
| 161 BrowserContext* browser_context) { | 175 BrowserContext* browser_context) { |
| 162 // TODO(ajwong): Change this API to require a process id instead of using | 176 // TODO(ajwong): Change this API to require a process id instead of using |
| 163 // kInvalidChildProcessId. | 177 // kInvalidChildProcessId. |
| 164 StoragePartition* partition = | 178 StoragePartition* partition = |
| 165 GetStoragePartition(browser_context, | 179 GetStoragePartition(browser_context, |
| 166 ChildProcessHostImpl::kInvalidChildProcessId); | 180 ChildProcessHostImpl::kInvalidChildProcessId); |
| 167 return partition->indexed_db_context(); | 181 return partition->indexed_db_context(); |
| 168 } | 182 } |
| 169 | 183 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 ForEachDOMStorageContext(browser_context, | 257 ForEachDOMStorageContext(browser_context, |
| 244 base::Bind(&DOMStorageContextImpl::PurgeMemory)); | 258 base::Bind(&DOMStorageContextImpl::PurgeMemory)); |
| 245 } | 259 } |
| 246 | 260 |
| 247 BrowserContext::~BrowserContext() { | 261 BrowserContext::~BrowserContext() { |
| 248 if (GetUserData(kDownloadManagerKeyName)) | 262 if (GetUserData(kDownloadManagerKeyName)) |
| 249 GetDownloadManager(this)->Shutdown(); | 263 GetDownloadManager(this)->Shutdown(); |
| 250 } | 264 } |
| 251 | 265 |
| 252 } // namespace content | 266 } // namespace content |
| OLD | NEW |