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 #if !defined(OS_IOS) | 7 #if !defined(OS_IOS) |
8 #include "content/browser/download/download_manager_impl.h" | 8 #include "content/browser/download/download_manager_impl.h" |
9 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 9 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
10 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 10 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 | 28 |
29 using base::UserDataAdapter; | 29 using base::UserDataAdapter; |
30 | 30 |
31 namespace content { | 31 namespace content { |
32 | 32 |
33 // Only ~BrowserContext() is needed on iOS. | 33 // Only ~BrowserContext() is needed on iOS. |
34 #if !defined(OS_IOS) | 34 #if !defined(OS_IOS) |
35 namespace { | 35 namespace { |
36 | 36 |
37 // Key names on BrowserContext. | 37 // Key names on BrowserContext. |
38 const char kDownloadManagerKeyName[] = "download_manager"; | 38 const char *KeyNames[] { "download_manager", "content_storage_partition_map" |
davidben
2015/08/14 20:24:39
Style: * hugs the type
davidben
2015/08/14 20:24:39
Style: kKeyNames
| |
39 const char kStorageParitionMapKeyName[] = "content_storage_partition_map"; | 39 #if defined(OS_CHROMEOS) |
40 , "mount_points" | |
davidben
2015/08/14 20:24:39
No reason to do the comma like this. Trailing comm
| |
41 #endif // defined(OS_CHROMEOS) | |
42 }; | |
43 enum KeyNameIndex { DOWNLOAD_MANAGER, STORAGE_PARTITION, MOUNT_POINTS }; | |
40 | 44 |
41 #if defined(OS_CHROMEOS) | |
42 const char kMountPointsKey[] = "mount_points"; | |
43 #endif // defined(OS_CHROMEOS) | |
44 | 45 |
45 StoragePartitionImplMap* GetStoragePartitionMap( | 46 StoragePartitionImplMap* GetStoragePartitionMap( |
46 BrowserContext* browser_context) { | 47 BrowserContext* browser_context) { |
47 StoragePartitionImplMap* partition_map = | 48 StoragePartitionImplMap* partition_map = |
48 static_cast<StoragePartitionImplMap*>( | 49 static_cast<StoragePartitionImplMap*>( |
49 browser_context->GetUserData(kStorageParitionMapKeyName)); | 50 browser_context->GetUserData(KeyNames[STORAGE_PARTITION])); |
50 if (!partition_map) { | 51 if (!partition_map) { |
51 partition_map = new StoragePartitionImplMap(browser_context); | 52 partition_map = new StoragePartitionImplMap(browser_context); |
52 browser_context->SetUserData(kStorageParitionMapKeyName, partition_map); | 53 browser_context->SetUserData(KeyNames[STORAGE_PARTITION], partition_map); |
53 } | 54 } |
54 return partition_map; | 55 return partition_map; |
55 } | 56 } |
56 | 57 |
57 StoragePartition* GetStoragePartitionFromConfig( | 58 StoragePartition* GetStoragePartitionFromConfig( |
58 BrowserContext* browser_context, | 59 BrowserContext* browser_context, |
59 const std::string& partition_domain, | 60 const std::string& partition_domain, |
60 const std::string& partition_name, | 61 const std::string& partition_name, |
61 bool in_memory) { | 62 bool in_memory) { |
62 StoragePartitionImplMap* partition_map = | 63 StoragePartitionImplMap* partition_map = |
(...skipping 25 matching lines...) Expand all Loading... | |
88 ServiceWorkerContextWrapper* wrapper = | 89 ServiceWorkerContextWrapper* wrapper = |
89 static_cast<ServiceWorkerContextWrapper*>( | 90 static_cast<ServiceWorkerContextWrapper*>( |
90 partition->GetServiceWorkerContext()); | 91 partition->GetServiceWorkerContext()); |
91 wrapper->process_manager()->Shutdown(); | 92 wrapper->process_manager()->Shutdown(); |
92 } | 93 } |
93 | 94 |
94 void SetDownloadManager(BrowserContext* context, | 95 void SetDownloadManager(BrowserContext* context, |
95 content::DownloadManager* download_manager) { | 96 content::DownloadManager* download_manager) { |
96 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 97 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
97 DCHECK(download_manager); | 98 DCHECK(download_manager); |
98 context->SetUserData(kDownloadManagerKeyName, download_manager); | 99 context->SetUserData(KeyNames[DOWNLOAD_MANAGER], download_manager); |
99 } | 100 } |
100 | 101 |
101 } // namespace | 102 } // namespace |
102 | 103 |
103 // static | 104 // static |
104 void BrowserContext::AsyncObliterateStoragePartition( | 105 void BrowserContext::AsyncObliterateStoragePartition( |
105 BrowserContext* browser_context, | 106 BrowserContext* browser_context, |
106 const GURL& site, | 107 const GURL& site, |
107 const base::Closure& on_gc_required) { | 108 const base::Closure& on_gc_required) { |
108 GetStoragePartitionMap(browser_context)->AsyncObliterate(site, | 109 GetStoragePartitionMap(browser_context)->AsyncObliterate(site, |
109 on_gc_required); | 110 on_gc_required); |
110 } | 111 } |
111 | 112 |
112 // static | 113 // static |
113 void BrowserContext::GarbageCollectStoragePartitions( | 114 void BrowserContext::GarbageCollectStoragePartitions( |
114 BrowserContext* browser_context, | 115 BrowserContext* browser_context, |
115 scoped_ptr<base::hash_set<base::FilePath> > active_paths, | 116 scoped_ptr<base::hash_set<base::FilePath> > active_paths, |
116 const base::Closure& done) { | 117 const base::Closure& done) { |
117 GetStoragePartitionMap(browser_context)->GarbageCollect( | 118 GetStoragePartitionMap(browser_context)->GarbageCollect( |
118 active_paths.Pass(), done); | 119 active_paths.Pass(), done); |
119 } | 120 } |
120 | 121 |
121 DownloadManager* BrowserContext::GetDownloadManager( | 122 DownloadManager* BrowserContext::GetDownloadManager( |
122 BrowserContext* context) { | 123 BrowserContext* context) { |
123 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 124 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
124 if (!context->GetUserData(kDownloadManagerKeyName)) { | 125 if (!context->GetUserData(KeyNames[DOWNLOAD_MANAGER])) { |
125 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | 126 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
126 DCHECK(rdh); | 127 DCHECK(rdh); |
127 DownloadManager* download_manager = | 128 DownloadManager* download_manager = |
128 new DownloadManagerImpl( | 129 new DownloadManagerImpl( |
129 GetContentClient()->browser()->GetNetLog(), context); | 130 GetContentClient()->browser()->GetNetLog(), context); |
130 | 131 |
131 SetDownloadManager(context, download_manager); | 132 SetDownloadManager(context, download_manager); |
132 download_manager->SetDelegate(context->GetDownloadManagerDelegate()); | 133 download_manager->SetDelegate(context->GetDownloadManagerDelegate()); |
133 } | 134 } |
134 | 135 |
135 return static_cast<DownloadManager*>( | 136 return static_cast<DownloadManager*>( |
136 context->GetUserData(kDownloadManagerKeyName)); | 137 context->GetUserData(KeyNames[DOWNLOAD_MANAGER])); |
137 } | 138 } |
138 | 139 |
139 // static | 140 // static |
140 storage::ExternalMountPoints* BrowserContext::GetMountPoints( | 141 storage::ExternalMountPoints* BrowserContext::GetMountPoints( |
141 BrowserContext* context) { | 142 BrowserContext* context) { |
142 // Ensure that these methods are called on the UI thread, except for | 143 // Ensure that these methods are called on the UI thread, except for |
143 // unittests where a UI thread might not have been created. | 144 // unittests where a UI thread might not have been created. |
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
145 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); | 146 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); |
146 | 147 |
147 #if defined(OS_CHROMEOS) | 148 #if defined(OS_CHROMEOS) |
148 if (!context->GetUserData(kMountPointsKey)) { | 149 if (!context->GetUserData(KeyNames[MOUNT_POINTS])) { |
149 scoped_refptr<storage::ExternalMountPoints> mount_points = | 150 scoped_refptr<storage::ExternalMountPoints> mount_points = |
150 storage::ExternalMountPoints::CreateRefCounted(); | 151 storage::ExternalMountPoints::CreateRefCounted(); |
151 context->SetUserData( | 152 context->SetUserData( |
152 kMountPointsKey, | 153 KeyNames[MOUNT_POINTS], |
153 new UserDataAdapter<storage::ExternalMountPoints>(mount_points.get())); | 154 new UserDataAdapter<storage::ExternalMountPoints>(mount_points.get())); |
154 } | 155 } |
155 | 156 |
156 return UserDataAdapter<storage::ExternalMountPoints>::Get(context, | 157 return UserDataAdapter<storage::ExternalMountPoints>::Get(context, |
157 kMountPointsKey); | 158 KeyNames[MOUNT_POINT S]); |
davidben
2015/08/14 20:24:39
Style: 80 column limit.
| |
158 #else | 159 #else |
159 return NULL; | 160 return NULL; |
160 #endif | 161 #endif |
161 } | 162 } |
162 | 163 |
163 StoragePartition* BrowserContext::GetStoragePartition( | 164 StoragePartition* BrowserContext::GetStoragePartition( |
164 BrowserContext* browser_context, | 165 BrowserContext* browser_context, |
165 SiteInstance* site_instance) { | 166 SiteInstance* site_instance) { |
166 std::string partition_domain; | 167 std::string partition_domain; |
167 std::string partition_name; | 168 std::string partition_name; |
(...skipping 24 matching lines...) Expand all Loading... | |
192 | 193 |
193 return GetStoragePartitionFromConfig( | 194 return GetStoragePartitionFromConfig( |
194 browser_context, partition_domain, partition_name, in_memory); | 195 browser_context, partition_domain, partition_name, in_memory); |
195 } | 196 } |
196 | 197 |
197 void BrowserContext::ForEachStoragePartition( | 198 void BrowserContext::ForEachStoragePartition( |
198 BrowserContext* browser_context, | 199 BrowserContext* browser_context, |
199 const StoragePartitionCallback& callback) { | 200 const StoragePartitionCallback& callback) { |
200 StoragePartitionImplMap* partition_map = | 201 StoragePartitionImplMap* partition_map = |
201 static_cast<StoragePartitionImplMap*>( | 202 static_cast<StoragePartitionImplMap*>( |
202 browser_context->GetUserData(kStorageParitionMapKeyName)); | 203 browser_context->GetUserData(KeyNames[STORAGE_PARTITION])); |
203 if (!partition_map) | 204 if (!partition_map) |
204 return; | 205 return; |
205 | 206 |
206 partition_map->ForEach(callback); | 207 partition_map->ForEach(callback); |
207 } | 208 } |
208 | 209 |
209 StoragePartition* BrowserContext::GetDefaultStoragePartition( | 210 StoragePartition* BrowserContext::GetDefaultStoragePartition( |
210 BrowserContext* browser_context) { | 211 BrowserContext* browser_context) { |
211 return GetStoragePartition(browser_context, NULL); | 212 return GetStoragePartition(browser_context, NULL); |
212 } | 213 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 void BrowserContext::SetDownloadManagerForTesting( | 316 void BrowserContext::SetDownloadManagerForTesting( |
316 BrowserContext* browser_context, | 317 BrowserContext* browser_context, |
317 DownloadManager* download_manager) { | 318 DownloadManager* download_manager) { |
318 SetDownloadManager(browser_context, download_manager); | 319 SetDownloadManager(browser_context, download_manager); |
319 } | 320 } |
320 | 321 |
321 #endif // !OS_IOS | 322 #endif // !OS_IOS |
322 | 323 |
323 BrowserContext::~BrowserContext() { | 324 BrowserContext::~BrowserContext() { |
324 #if !defined(OS_IOS) | 325 #if !defined(OS_IOS) |
325 if (GetUserData(kDownloadManagerKeyName)) | 326 if (GetUserData(KeyNames[DOWNLOAD_MANAGER])) |
326 GetDownloadManager(this)->Shutdown(); | 327 GetDownloadManager(this)->Shutdown(); |
327 #endif | 328 #endif |
328 } | 329 } |
329 | 330 |
330 } // namespace content | 331 } // namespace content |
OLD | NEW |