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

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

Issue 9425026: Remove getters for HTML5 related objects from the ResourceContext interface. Half of them weren't u… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 8 years, 10 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 "content/browser/chrome_blob_storage_context.h"
9 #include "content/browser/file_system/browser_file_system_helper.h" 8 #include "content/browser/file_system/browser_file_system_helper.h"
10 #include "content/browser/in_process_webkit/webkit_context.h" 9 #include "content/browser/in_process_webkit/webkit_context.h"
10 #include "content/browser/resource_context_impl.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/common/content_constants.h" 12 #include "content/public/common/content_constants.h"
13 #include "webkit/database/database_tracker.h" 13 #include "webkit/database/database_tracker.h"
14 #include "webkit/quota/quota_manager.h" 14 #include "webkit/quota/quota_manager.h"
15 15
16 using appcache::AppCacheService;
17 using base::UserDataAdapter;
16 using content::BrowserThread; 18 using content::BrowserThread;
17 using fileapi::FileSystemContext; 19 using fileapi::FileSystemContext;
18 using quota::QuotaManager; 20 using quota::QuotaManager;
19 using webkit_database::DatabaseTracker; 21 using webkit_database::DatabaseTracker;
20 22
23 // Key names on BrowserContext.
21 static const char* kAppCacheServicKeyName = "content_appcache_service_tracker"; 24 static const char* kAppCacheServicKeyName = "content_appcache_service_tracker";
22 static const char* kBlobStorageContextKeyName = "content_blob_storage_context";
23 static const char* kDatabaseTrackerKeyName = "content_database_tracker"; 25 static const char* kDatabaseTrackerKeyName = "content_database_tracker";
24 static const char* kFileSystemContextKeyName = "content_file_system_context"; 26 static const char* kFileSystemContextKeyName = "content_file_system_context";
25 static const char* kQuotaManagerKeyName = "content_quota_manager"; 27 static const char* kQuotaManagerKeyName = "content_quota_manager";
26 static const char* kWebKitContextKeyName = "content_webkit_context"; 28 static const char* kWebKitContextKeyName = "content_webkit_context";
27 29
28 namespace content { 30 namespace content {
29 31
30 // Adapter class that releases a refcounted object when the
31 // SupportsUserData::Data object is deleted.
32 template <typename T>
33 class UserDataAdapter : public base::SupportsUserData::Data {
34 public:
35 static T* Get(BrowserContext* context, const char* key) {
36 UserDataAdapter* data =
37 static_cast<UserDataAdapter*>(context->GetUserData(key));
38 return static_cast<T*>(data->object_.get());
39 }
40
41 UserDataAdapter(T* object) : object_(object) {}
42
43 private:
44 scoped_refptr<T> object_;
45
46 DISALLOW_COPY_AND_ASSIGN(UserDataAdapter);
47 };
48
49 void CreateQuotaManagerAndClients(BrowserContext* context) { 32 void CreateQuotaManagerAndClients(BrowserContext* context) {
50 if (context->GetUserData(kQuotaManagerKeyName)) { 33 if (context->GetUserData(kQuotaManagerKeyName)) {
51 DCHECK(context->GetUserData(kDatabaseTrackerKeyName)); 34 DCHECK(context->GetUserData(kDatabaseTrackerKeyName));
52 DCHECK(context->GetUserData(kFileSystemContextKeyName)); 35 DCHECK(context->GetUserData(kFileSystemContextKeyName));
53 DCHECK(context->GetUserData(kWebKitContextKeyName)); 36 DCHECK(context->GetUserData(kWebKitContextKeyName));
54 return; 37 return;
55 } 38 }
56 39
57 // All of the clients have to be created and registered with the 40 // All of the clients have to be created and registered with the
58 // QuotaManager prior to the QuotaManger being used. So we do them 41 // QuotaManager prior to the QuotaManger being used. So we do them
(...skipping 30 matching lines...) Expand all
89 BrowserThread::WEBKIT_DEPRECATED)); 72 BrowserThread::WEBKIT_DEPRECATED));
90 context->SetUserData(kWebKitContextKeyName, 73 context->SetUserData(kWebKitContextKeyName,
91 new UserDataAdapter<WebKitContext>(webkit_context)); 74 new UserDataAdapter<WebKitContext>(webkit_context));
92 75
93 scoped_refptr<ChromeAppCacheService> appcache_service = 76 scoped_refptr<ChromeAppCacheService> appcache_service =
94 new ChromeAppCacheService(quota_manager->proxy()); 77 new ChromeAppCacheService(quota_manager->proxy());
95 context->SetUserData( 78 context->SetUserData(
96 kAppCacheServicKeyName, 79 kAppCacheServicKeyName,
97 new UserDataAdapter<ChromeAppCacheService>(appcache_service)); 80 new UserDataAdapter<ChromeAppCacheService>(appcache_service));
98 81
82 InitializeResourceContext(context);
83
99 // Check first to avoid memory leak in unittests. 84 // Check first to avoid memory leak in unittests.
100 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { 85 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
101 BrowserThread::PostTask( 86 BrowserThread::PostTask(
102 BrowserThread::IO, FROM_HERE, 87 BrowserThread::IO, FROM_HERE,
103 base::Bind(&ChromeAppCacheService::InitializeOnIOThread, 88 base::Bind(&ChromeAppCacheService::InitializeOnIOThread,
104 appcache_service, 89 appcache_service,
105 context->IsOffTheRecord() ? FilePath() : 90 context->IsOffTheRecord() ? FilePath() :
106 context->GetPath().Append(content::kAppCacheDirname), 91 context->GetPath().Append(content::kAppCacheDirname),
107 context->GetResourceContext(), 92 context->GetResourceContext(),
108 make_scoped_refptr(context->GetSpecialStoragePolicy()))); 93 make_scoped_refptr(context->GetSpecialStoragePolicy())));
109 } 94 }
110 } 95 }
111 96
112 QuotaManager* BrowserContext::GetQuotaManager(BrowserContext* context) { 97 QuotaManager* BrowserContext::GetQuotaManager(BrowserContext* context) {
113 CreateQuotaManagerAndClients(context); 98 CreateQuotaManagerAndClients(context);
114 return UserDataAdapter<QuotaManager>::Get(context, kQuotaManagerKeyName); 99 return UserDataAdapter<QuotaManager>::Get(context, kQuotaManagerKeyName);
115 } 100 }
116 101
117 WebKitContext* BrowserContext::GetWebKitContext(BrowserContext* context) { 102 WebKitContext* BrowserContext::GetWebKitContext(BrowserContext* context) {
118 CreateQuotaManagerAndClients(context); 103 CreateQuotaManagerAndClients(context);
119 return UserDataAdapter<WebKitContext>::Get(context, kWebKitContextKeyName); 104 return UserDataAdapter<WebKitContext>::Get(context, kWebKitContextKeyName);
120 } 105 }
121 106
122 DatabaseTracker* BrowserContext::GetDatabaseTracker(BrowserContext* context) { 107 DatabaseTracker* BrowserContext::GetDatabaseTracker(BrowserContext* context) {
123 CreateQuotaManagerAndClients(context); 108 CreateQuotaManagerAndClients(context);
124 return UserDataAdapter<DatabaseTracker>::Get( 109 return UserDataAdapter<DatabaseTracker>::Get(
125 context, kDatabaseTrackerKeyName); 110 context, kDatabaseTrackerKeyName);
126 } 111 }
127 112
128 ChromeAppCacheService* BrowserContext::GetAppCacheService( 113 AppCacheService* BrowserContext::GetAppCacheService(
129 BrowserContext* browser_context) { 114 BrowserContext* browser_context) {
130 CreateQuotaManagerAndClients(browser_context); 115 CreateQuotaManagerAndClients(browser_context);
131 return UserDataAdapter<ChromeAppCacheService>::Get( 116 return UserDataAdapter<ChromeAppCacheService>::Get(
132 browser_context, kAppCacheServicKeyName); 117 browser_context, kAppCacheServicKeyName);
133 } 118 }
134 119
135 FileSystemContext* BrowserContext::GetFileSystemContext( 120 FileSystemContext* BrowserContext::GetFileSystemContext(
136 BrowserContext* browser_context) { 121 BrowserContext* browser_context) {
137 CreateQuotaManagerAndClients(browser_context); 122 CreateQuotaManagerAndClients(browser_context);
138 return UserDataAdapter<FileSystemContext>::Get( 123 return UserDataAdapter<FileSystemContext>::Get(
139 browser_context, kFileSystemContextKeyName); 124 browser_context, kFileSystemContextKeyName);
140 } 125 }
141 126
142 ChromeBlobStorageContext* BrowserContext::GetBlobStorageContext( 127 void BrowserContext::EnsureResourceContextInitialized(BrowserContext* context) {
143 BrowserContext* context) { 128 if (context->GetResourceContext()->GetUserData(kWebKitContextKeyName))
144 if (!context->GetUserData(kBlobStorageContextKeyName)) { 129 return;
145 scoped_refptr<ChromeBlobStorageContext> blob = 130 InitializeResourceContext(context);
146 new ChromeBlobStorageContext();
147 BrowserThread::PostTask(
148 BrowserThread::IO, FROM_HERE,
149 base::Bind(&ChromeBlobStorageContext::InitializeOnIOThread, blob));
150 context->SetUserData(kBlobStorageContextKeyName,
151 new UserDataAdapter<ChromeBlobStorageContext>(blob));
152 }
153
154 return UserDataAdapter<ChromeBlobStorageContext>::Get(
155 context, kBlobStorageContextKeyName);
156 } 131 }
157 132
158 BrowserContext::~BrowserContext() { 133 BrowserContext::~BrowserContext() {
159 if (GetUserData(kDatabaseTrackerKeyName) && 134 if (GetUserData(kDatabaseTrackerKeyName) &&
160 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { 135 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) {
161 BrowserThread::PostTask( 136 BrowserThread::PostTask(
162 BrowserThread::FILE, FROM_HERE, 137 BrowserThread::FILE, FROM_HERE,
163 base::Bind(&webkit_database::DatabaseTracker::Shutdown, 138 base::Bind(&webkit_database::DatabaseTracker::Shutdown,
164 GetDatabaseTracker(this))); 139 GetDatabaseTracker(this)));
165 } 140 }
166 } 141 }
167 142
168 } // namespace content 143 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/appcache/chrome_appcache_service_unittest.cc ('k') | content/browser/chrome_blob_storage_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698