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/browser/storage_partition_impl_map.h" | 5 #include "content/browser/storage_partition_impl_map.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "content/browser/appcache/chrome_appcache_service.h" | 12 #include "content/browser/appcache/chrome_appcache_service.h" |
13 #include "content/browser/resource_context_impl.h" | 13 #include "content/browser/resource_context_impl.h" |
14 #include "content/browser/storage_partition_impl.h" | 14 #include "content/browser/storage_partition_impl.h" |
15 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/common/content_constants.h" | 17 #include "content/public/common/content_constants.h" |
| 18 #include "net/url_request/url_request_context_getter.h" |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
21 StoragePartitionImplMap::StoragePartitionImplMap( | 22 StoragePartitionImplMap::StoragePartitionImplMap( |
22 BrowserContext* browser_context) | 23 BrowserContext* browser_context) |
23 : browser_context_(browser_context) { | 24 : browser_context_(browser_context) { |
24 } | 25 } |
25 | 26 |
26 StoragePartitionImplMap::~StoragePartitionImplMap() { | 27 StoragePartitionImplMap::~StoragePartitionImplMap() { |
27 STLDeleteContainerPairSecondPointers(partitions_.begin(), | 28 STLDeleteContainerPairSecondPointers(partitions_.begin(), |
(...skipping 14 matching lines...) Expand all Loading... |
42 // TODO(ajwong): This should check the path is valid? | 43 // TODO(ajwong): This should check the path is valid? |
43 CHECK(IsStringASCII(partition_id)); | 44 CHECK(IsStringASCII(partition_id)); |
44 partition_path = partition_path.Append(kStoragePartitionDirname) | 45 partition_path = partition_path.Append(kStoragePartitionDirname) |
45 .AppendASCII(partition_id); | 46 .AppendASCII(partition_id); |
46 } | 47 } |
47 | 48 |
48 StoragePartitionImpl* storage_partition = | 49 StoragePartitionImpl* storage_partition = |
49 StoragePartitionImpl::Create(browser_context_, partition_path); | 50 StoragePartitionImpl::Create(browser_context_, partition_path); |
50 partitions_[partition_id] = storage_partition; | 51 partitions_[partition_id] = storage_partition; |
51 | 52 |
52 PostCreateInitialization(storage_partition, partition_path); | 53 net::URLRequestContextGetter* request_context = partition_id.empty() ? |
| 54 browser_context_->GetRequestContext() : |
| 55 browser_context_->GetRequestContextForStoragePartition(partition_id); |
| 56 |
| 57 PostCreateInitialization(storage_partition, partition_path, request_context); |
53 | 58 |
54 // TODO(ajwong): We need to remove this conditional by making | 59 // TODO(ajwong): We need to remove this conditional by making |
55 // InitializeResourceContext() understand having different partition data | 60 // InitializeResourceContext() understand having different partition data |
56 // based on the renderer_id. | 61 // based on the renderer_id. |
57 if (partition_id.empty()) { | 62 if (partition_id.empty()) { |
58 InitializeResourceContext(browser_context_); | 63 InitializeResourceContext(browser_context_); |
59 } | 64 } |
60 | 65 |
61 return storage_partition; | 66 return storage_partition; |
62 } | 67 } |
63 | 68 |
64 void StoragePartitionImplMap::ForEach( | 69 void StoragePartitionImplMap::ForEach( |
65 const BrowserContext::StoragePartitionCallback& callback) { | 70 const BrowserContext::StoragePartitionCallback& callback) { |
66 for (std::map<std::string, StoragePartitionImpl*>::const_iterator it = | 71 for (std::map<std::string, StoragePartitionImpl*>::const_iterator it = |
67 partitions_.begin(); | 72 partitions_.begin(); |
68 it != partitions_.end(); | 73 it != partitions_.end(); |
69 ++it) { | 74 ++it) { |
70 callback.Run(it->first, it->second); | 75 callback.Run(it->first, it->second); |
71 } | 76 } |
72 } | 77 } |
73 | 78 |
74 void StoragePartitionImplMap::PostCreateInitialization( | 79 void StoragePartitionImplMap::PostCreateInitialization( |
75 StoragePartitionImpl* partition, | 80 StoragePartitionImpl* partition, |
76 const FilePath& partition_path) { | 81 const FilePath& partition_path, |
| 82 net::URLRequestContextGetter* request_context_getter) { |
77 // Check first to avoid memory leak in unittests. | 83 // Check first to avoid memory leak in unittests. |
78 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 84 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
79 BrowserThread::PostTask( | 85 BrowserThread::PostTask( |
80 BrowserThread::IO, FROM_HERE, | 86 BrowserThread::IO, FROM_HERE, |
81 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, | 87 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, |
82 partition->GetAppCacheService(), | 88 partition->GetAppCacheService(), |
83 browser_context_->IsOffTheRecord() ? FilePath() : | 89 browser_context_->IsOffTheRecord() ? FilePath() : |
84 partition_path.Append(kAppCacheDirname), | 90 partition_path.Append(kAppCacheDirname), |
85 // TODO(michaeln): This is not right, appcache will be | 91 browser_context_->GetResourceContext(), |
86 // using the cookies and cache of a the default | 92 make_scoped_refptr(request_context_getter), |
87 // partition when populating the cache. | |
88 // http://crbug.com/85121 | |
89 browser_context_->GetResourceContext(), | |
90 make_scoped_refptr( | 93 make_scoped_refptr( |
91 browser_context_->GetSpecialStoragePolicy()))); | 94 browser_context_->GetSpecialStoragePolicy()))); |
92 } | 95 } |
93 } | 96 } |
94 | 97 |
95 } // namespace content | 98 } // namespace content |
OLD | NEW |