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

Side by Side Diff: content/browser/browser_context.cc

Issue 10878041: Remove silly uses of ResourceContext that unnecessarily violate the Law of Demeter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: only the IO thread may grab the controller. Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "content/browser/download/download_manager_impl.h" 11 #include "content/browser/download/download_manager_impl.h"
12 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" 12 #include "content/browser/in_process_webkit/indexed_db_context_impl.h"
13 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" 13 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
14 #include "content/public/browser/resource_context.h" 14 #include "content/public/browser/resource_context.h"
15 #include "content/browser/storage_partition_impl.h" 15 #include "content/browser/storage_partition_impl.h"
16 #include "content/browser/storage_partition_impl_map.h" 16 #include "content/browser/storage_partition_impl_map.h"
17 #include "content/common/child_process_host_impl.h" 17 #include "content/common/child_process_host_impl.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/content_browser_client.h" 19 #include "content/public/browser/content_browser_client.h"
20 #include "net/base/server_bound_cert_service.h" 20 #include "net/base/server_bound_cert_service.h"
21 #include "net/base/server_bound_cert_store.h" 21 #include "net/base/server_bound_cert_store.h"
22 #include "net/cookies/cookie_monster.h" 22 #include "net/cookies/cookie_monster.h"
23 #include "net/cookies/cookie_store.h" 23 #include "net/cookies/cookie_store.h"
24 #include "net/url_request/url_request_context.h" 24 #include "net/url_request/url_request_context.h"
25 #include "net/url_request/url_request_context_getter.h"
25 26
26 using base::UserDataAdapter; 27 using base::UserDataAdapter;
27 28
28 // Key names on BrowserContext. 29 // Key names on BrowserContext.
29 static const char* kDownloadManagerKeyName = "download_manager"; 30 static const char* kDownloadManagerKeyName = "download_manager";
30 static const char* kStorageParitionMapKeyName = "content_storage_partition_map"; 31 static const char* kStorageParitionMapKeyName = "content_storage_partition_map";
31 32
32 namespace content { 33 namespace content {
33 34
34 namespace { 35 namespace {
(...skipping 12 matching lines...) Expand all
47 return partition_map->Get(partition_id); 48 return partition_map->Get(partition_id);
48 } 49 }
49 50
50 // Run |callback| on each DOMStorageContextImpl in |browser_context|. 51 // Run |callback| on each DOMStorageContextImpl in |browser_context|.
51 void PurgeDOMStorageContextInPartition(const std::string& id, 52 void PurgeDOMStorageContextInPartition(const std::string& id,
52 StoragePartition* storage_partition) { 53 StoragePartition* storage_partition) {
53 static_cast<StoragePartitionImpl*>(storage_partition)-> 54 static_cast<StoragePartitionImpl*>(storage_partition)->
54 GetDOMStorageContext()->PurgeMemory(); 55 GetDOMStorageContext()->PurgeMemory();
55 } 56 }
56 57
57 void SaveSessionStateOnIOThread(ResourceContext* resource_context) { 58 void SaveSessionStateOnIOThread(
58 resource_context->GetRequestContext()->cookie_store()->GetCookieMonster()-> 59 const scoped_refptr<net::URLRequestContextGetter>& context_getter,
60 appcache::AppCacheService* appcache_service) {
61 net::URLRequestContext* context = context_getter->GetURLRequestContext();
62 context->cookie_store()->GetCookieMonster()->
59 SetForceKeepSessionState(); 63 SetForceKeepSessionState();
60 resource_context->GetRequestContext()->server_bound_cert_service()-> 64 context->server_bound_cert_service()->GetCertStore()->
61 GetCertStore()->SetForceKeepSessionState(); 65 SetForceKeepSessionState();
62 ResourceContext::GetAppCacheService(resource_context)-> 66 appcache_service->set_force_keep_session_state();
63 set_force_keep_session_state();
64 } 67 }
65 68
66 void SaveSessionStateOnWebkitThread( 69 void SaveSessionStateOnWebkitThread(
67 scoped_refptr<IndexedDBContextImpl> indexed_db_context) { 70 scoped_refptr<IndexedDBContextImpl> indexed_db_context) {
68 indexed_db_context->SetForceKeepSessionState(); 71 indexed_db_context->SetForceKeepSessionState();
69 } 72 }
70 73
71 void PurgeMemoryOnIOThread(ResourceContext* resource_context) { 74 void PurgeMemoryOnIOThread(appcache::AppCacheService* appcache_service) {
72 ResourceContext::GetAppCacheService(resource_context)->PurgeMemory(); 75 appcache_service->PurgeMemory();
73 } 76 }
74 77
75 } // namespace 78 } // namespace
76 79
77 DownloadManager* BrowserContext::GetDownloadManager( 80 DownloadManager* BrowserContext::GetDownloadManager(
78 BrowserContext* context) { 81 BrowserContext* context) {
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
80 if (!context->GetUserData(kDownloadManagerKeyName)) { 83 if (!context->GetUserData(kDownloadManagerKeyName)) {
81 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); 84 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
82 DCHECK(rdh); 85 DCHECK(rdh);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // See http://crbug.com/115678. 174 // See http://crbug.com/115678.
172 GetDefaultStoragePartition(context); 175 GetDefaultStoragePartition(context);
173 } 176 }
174 177
175 void BrowserContext::SaveSessionState(BrowserContext* browser_context) { 178 void BrowserContext::SaveSessionState(BrowserContext* browser_context) {
176 GetDatabaseTracker(browser_context)->SetForceKeepSessionState(); 179 GetDatabaseTracker(browser_context)->SetForceKeepSessionState();
177 180
178 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { 181 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
179 BrowserThread::PostTask( 182 BrowserThread::PostTask(
180 BrowserThread::IO, FROM_HERE, 183 BrowserThread::IO, FROM_HERE,
181 base::Bind(&SaveSessionStateOnIOThread, 184 base::Bind(
182 browser_context->GetResourceContext())); 185 &SaveSessionStateOnIOThread,
186 make_scoped_refptr(browser_context->GetRequestContext()),
187 BrowserContext::GetDefaultStoragePartition(browser_context)->
188 GetAppCacheService()));
183 } 189 }
184 190
185 DOMStorageContextImpl* dom_storage_context_impl = 191 DOMStorageContextImpl* dom_storage_context_impl =
186 static_cast<DOMStorageContextImpl*>( 192 static_cast<DOMStorageContextImpl*>(
187 GetDefaultStoragePartition(browser_context)->GetDOMStorageContext()); 193 GetDefaultStoragePartition(browser_context)->GetDOMStorageContext());
188 dom_storage_context_impl->SetForceKeepSessionState(); 194 dom_storage_context_impl->SetForceKeepSessionState();
189 195
190 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) { 196 if (BrowserThread::IsMessageLoopValid(BrowserThread::WEBKIT_DEPRECATED)) {
191 IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>( 197 IndexedDBContextImpl* indexed_db = static_cast<IndexedDBContextImpl*>(
192 GetIndexedDBContext(browser_context)); 198 GetIndexedDBContext(browser_context));
193 BrowserThread::PostTask( 199 BrowserThread::PostTask(
194 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, 200 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
195 base::Bind(&SaveSessionStateOnWebkitThread, 201 base::Bind(&SaveSessionStateOnWebkitThread,
196 make_scoped_refptr(indexed_db))); 202 make_scoped_refptr(indexed_db)));
197 } 203 }
198 } 204 }
199 205
200 void BrowserContext::PurgeMemory(BrowserContext* browser_context) { 206 void BrowserContext::PurgeMemory(BrowserContext* browser_context) {
201 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { 207 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
202 BrowserThread::PostTask( 208 BrowserThread::PostTask(
203 BrowserThread::IO, FROM_HERE, 209 BrowserThread::IO, FROM_HERE,
204 base::Bind(&PurgeMemoryOnIOThread, 210 base::Bind(
205 browser_context->GetResourceContext())); 211 &PurgeMemoryOnIOThread,
212 BrowserContext::GetDefaultStoragePartition(browser_context)->
213 GetAppCacheService()));
206 } 214 }
207 215
208 ForEachStoragePartition(browser_context, 216 ForEachStoragePartition(browser_context,
209 base::Bind(&PurgeDOMStorageContextInPartition)); 217 base::Bind(&PurgeDOMStorageContextInPartition));
210 } 218 }
211 219
212 BrowserContext::~BrowserContext() { 220 BrowserContext::~BrowserContext() {
213 if (GetUserData(kDownloadManagerKeyName)) 221 if (GetUserData(kDownloadManagerKeyName))
214 GetDownloadManager(this)->Shutdown(); 222 GetDownloadManager(this)->Shutdown();
215 } 223 }
216 224
217 } // namespace content 225 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698