| 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_manager_impl.h" | 10 #include "content/browser/download/download_manager_impl.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 using base::UserDataAdapter; | 25 using base::UserDataAdapter; |
| 26 | 26 |
| 27 // Key names on BrowserContext. | 27 // Key names on BrowserContext. |
| 28 static const char* kDownloadManagerKeyName = "download_manager"; | 28 static const char* kDownloadManagerKeyName = "download_manager"; |
| 29 static const char* kStorageParitionMapKeyName = "content_storage_partition_map"; | 29 static const char* kStorageParitionMapKeyName = "content_storage_partition_map"; |
| 30 | 30 |
| 31 namespace content { | 31 namespace content { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 StoragePartition* GetStoragePartition(BrowserContext* browser_context, | 35 StoragePartition* GetStoragePartitionByPartitionId( |
| 36 int renderer_child_id) { | 36 BrowserContext* browser_context, |
| 37 const std::string& partition_id) { |
| 37 StoragePartitionMap* partition_map = static_cast<StoragePartitionMap*>( | 38 StoragePartitionMap* partition_map = static_cast<StoragePartitionMap*>( |
| 38 browser_context->GetUserData(kStorageParitionMapKeyName)); | 39 browser_context->GetUserData(kStorageParitionMapKeyName)); |
| 39 if (!partition_map) { | 40 if (!partition_map) { |
| 40 partition_map = new StoragePartitionMap(browser_context); | 41 partition_map = new StoragePartitionMap(browser_context); |
| 41 browser_context->SetUserData(kStorageParitionMapKeyName, partition_map); | 42 browser_context->SetUserData(kStorageParitionMapKeyName, partition_map); |
| 42 } | 43 } |
| 43 | 44 |
| 45 return partition_map->Get(partition_id); |
| 46 } |
| 47 |
| 48 StoragePartition* GetStoragePartition(BrowserContext* browser_context, |
| 49 int renderer_child_id) { |
| 44 const std::string& partition_id = | 50 const std::string& partition_id = |
| 45 GetContentClient()->browser()->GetStoragePartitionIdForChildProcess( | 51 GetContentClient()->browser()->GetStoragePartitionIdForChildProcess( |
| 46 browser_context, | 52 browser_context, |
| 47 renderer_child_id); | 53 renderer_child_id); |
| 48 | 54 |
| 49 return partition_map->Get(partition_id); | 55 return GetStoragePartitionByPartitionId(browser_context, partition_id); |
| 50 } | 56 } |
| 51 | 57 |
| 52 // Run |callback| on each storage partition in |browser_context|. | 58 // Run |callback| on each storage partition in |browser_context|. |
| 53 void ForEachStoragePartition( | 59 void ForEachStoragePartition( |
| 54 BrowserContext* browser_context, | 60 BrowserContext* browser_context, |
| 55 const base::Callback<void(StoragePartition*)>& callback) { | 61 const base::Callback<void(StoragePartition*)>& callback) { |
| 56 StoragePartitionMap* partition_map = static_cast<StoragePartitionMap*>( | 62 StoragePartitionMap* partition_map = static_cast<StoragePartitionMap*>( |
| 57 browser_context->GetUserData(kStorageParitionMapKeyName)); | 63 browser_context->GetUserData(kStorageParitionMapKeyName)); |
| 58 if (!partition_map) { | 64 if (!partition_map) { |
| 59 return; | 65 return; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 152 } |
| 147 | 153 |
| 148 DOMStorageContext* BrowserContext::GetDOMStorageContext( | 154 DOMStorageContext* BrowserContext::GetDOMStorageContext( |
| 149 BrowserContext* browser_context, | 155 BrowserContext* browser_context, |
| 150 int render_child_id) { | 156 int render_child_id) { |
| 151 StoragePartition* partition = | 157 StoragePartition* partition = |
| 152 GetStoragePartition(browser_context, render_child_id); | 158 GetStoragePartition(browser_context, render_child_id); |
| 153 return partition->dom_storage_context(); | 159 return partition->dom_storage_context(); |
| 154 } | 160 } |
| 155 | 161 |
| 162 DOMStorageContext* BrowserContext::GetDOMStorageContextByPartitionId( |
| 163 BrowserContext* browser_context, |
| 164 const std::string& partition_id) { |
| 165 StoragePartition* partition = |
| 166 GetStoragePartitionByPartitionId(browser_context, partition_id); |
| 167 return partition->dom_storage_context(); |
| 168 } |
| 169 |
| 156 IndexedDBContext* BrowserContext::GetIndexedDBContext( | 170 IndexedDBContext* BrowserContext::GetIndexedDBContext( |
| 157 BrowserContext* browser_context) { | 171 BrowserContext* browser_context) { |
| 158 // TODO(ajwong): Change this API to require a process id instead of using | 172 // TODO(ajwong): Change this API to require a process id instead of using |
| 159 // kInvalidChildProcessId. | 173 // kInvalidChildProcessId. |
| 160 StoragePartition* partition = | 174 StoragePartition* partition = |
| 161 GetStoragePartition(browser_context, | 175 GetStoragePartition(browser_context, |
| 162 ChildProcessHostImpl::kInvalidChildProcessId); | 176 ChildProcessHostImpl::kInvalidChildProcessId); |
| 163 return partition->indexed_db_context(); | 177 return partition->indexed_db_context(); |
| 164 } | 178 } |
| 165 | 179 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 ForEachDOMStorageContext(browser_context, | 253 ForEachDOMStorageContext(browser_context, |
| 240 base::Bind(&DOMStorageContextImpl::PurgeMemory)); | 254 base::Bind(&DOMStorageContextImpl::PurgeMemory)); |
| 241 } | 255 } |
| 242 | 256 |
| 243 BrowserContext::~BrowserContext() { | 257 BrowserContext::~BrowserContext() { |
| 244 if (GetUserData(kDownloadManagerKeyName)) | 258 if (GetUserData(kDownloadManagerKeyName)) |
| 245 GetDownloadManager(this)->Shutdown(); | 259 GetDownloadManager(this)->Shutdown(); |
| 246 } | 260 } |
| 247 | 261 |
| 248 } // namespace content | 262 } // namespace content |
| OLD | NEW |