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

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

Issue 12049052: Move core url data manager classes to content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 7 years, 11 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
« no previous file with comments | « content/browser/resource_context_impl.h ('k') | content/browser/storage_partition_impl_map.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/browser/resource_context_impl.h" 5 #include "content/browser/resource_context_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/fileapi/chrome_blob_storage_context.h" 8 #include "content/browser/fileapi/chrome_blob_storage_context.h"
9 #include "content/browser/host_zoom_map_impl.h" 9 #include "content/browser/host_zoom_map_impl.h"
10 #include "content/browser/loader/resource_dispatcher_host_impl.h" 10 #include "content/browser/loader/resource_dispatcher_host_impl.h"
11 #include "content/browser/loader/resource_request_info_impl.h" 11 #include "content/browser/loader/resource_request_info_impl.h"
12 #include "content/browser/webui/url_data_manager_backend.h"
12 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 15
15 // Key names on ResourceContext.
16 static const char* kBlobStorageContextKeyName = "content_blob_storage_context";
17 static const char* kHostZoomMapKeyName = "content_host_zoom_map";
18
19 using base::UserDataAdapter; 16 using base::UserDataAdapter;
20 17
21 namespace content { 18 namespace content {
22 19
23 namespace { 20 namespace {
24 21
22 // Key names on ResourceContext.
23 const char kBlobStorageContextKeyName[] = "content_blob_storage_context";
24 const char kHostZoomMapKeyName[] = "content_host_zoom_map";
25 const char kURLDataManagerBackendKeyName[] = "url_data_manager_backend";
26
25 class NonOwningZoomData : public base::SupportsUserData::Data { 27 class NonOwningZoomData : public base::SupportsUserData::Data {
26 public: 28 public:
27 explicit NonOwningZoomData(HostZoomMap* hzm) : host_zoom_map_(hzm) {} 29 explicit NonOwningZoomData(HostZoomMap* hzm) : host_zoom_map_(hzm) {}
28 HostZoomMap* host_zoom_map() { return host_zoom_map_; } 30 HostZoomMap* host_zoom_map() { return host_zoom_map_; }
29 31
30 private: 32 private:
31 HostZoomMap* host_zoom_map_; 33 HostZoomMap* host_zoom_map_;
32 }; 34 };
33 35
34 } // namespace 36 } // namespace
35 37
36 38
37 ResourceContext::ResourceContext() { 39 ResourceContext::ResourceContext() {
38 if (ResourceDispatcherHostImpl::Get()) 40 if (ResourceDispatcherHostImpl::Get())
39 ResourceDispatcherHostImpl::Get()->AddResourceContext(this); 41 ResourceDispatcherHostImpl::Get()->AddResourceContext(this);
40 } 42 }
41 43
42 ResourceContext::~ResourceContext() { 44 ResourceContext::~ResourceContext() {
43 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get(); 45 ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get();
44 if (rdhi) { 46 if (rdhi) {
45 rdhi->CancelRequestsForContext(this); 47 rdhi->CancelRequestsForContext(this);
46 rdhi->RemoveResourceContext(this); 48 rdhi->RemoveResourceContext(this);
47 } 49 }
50
51 // In some tests this object is destructed on UI thread.
52 DetachUserDataThread();
48 } 53 }
49 54
50 ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext( 55 ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext(
51 ResourceContext* resource_context) { 56 ResourceContext* resource_context) {
52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
53 return UserDataAdapter<ChromeBlobStorageContext>::Get( 58 return UserDataAdapter<ChromeBlobStorageContext>::Get(
54 resource_context, kBlobStorageContextKeyName); 59 resource_context, kBlobStorageContextKeyName);
55 } 60 }
56 61
57 HostZoomMap* GetHostZoomMapForResourceContext(ResourceContext* context) { 62 HostZoomMap* GetHostZoomMapForResourceContext(ResourceContext* context) {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
59 return static_cast<NonOwningZoomData*>( 64 return static_cast<NonOwningZoomData*>(
60 context->GetUserData(kHostZoomMapKeyName))->host_zoom_map(); 65 context->GetUserData(kHostZoomMapKeyName))->host_zoom_map();
61 } 66 }
62 67
68 ChromeURLDataManagerBackend* GetURLDataManagerForResourceContext(
69 ResourceContext* context) {
70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
71 if (!context->GetUserData(kURLDataManagerBackendKeyName)) {
72 context->SetUserData(kURLDataManagerBackendKeyName,
73 new ChromeURLDataManagerBackend());
74 }
75 return static_cast<ChromeURLDataManagerBackend*>(
76 context->GetUserData(kURLDataManagerBackendKeyName));
77 }
78
63 void InitializeResourceContext(BrowserContext* browser_context) { 79 void InitializeResourceContext(BrowserContext* browser_context) {
64 ResourceContext* resource_context = browser_context->GetResourceContext(); 80 ResourceContext* resource_context = browser_context->GetResourceContext();
65 DCHECK(!resource_context->GetUserData(kHostZoomMapKeyName)); 81 DCHECK(!resource_context->GetUserData(kHostZoomMapKeyName));
66 82
67 resource_context->SetUserData( 83 resource_context->SetUserData(
68 kBlobStorageContextKeyName, 84 kBlobStorageContextKeyName,
69 new UserDataAdapter<ChromeBlobStorageContext>( 85 new UserDataAdapter<ChromeBlobStorageContext>(
70 ChromeBlobStorageContext::GetFor(browser_context))); 86 ChromeBlobStorageContext::GetFor(browser_context)));
71 87
72 // This object is owned by the BrowserContext and not ResourceContext, so 88 // This object is owned by the BrowserContext and not ResourceContext, so
73 // store a non-owning pointer here. 89 // store a non-owning pointer here.
74 resource_context->SetUserData( 90 resource_context->SetUserData(
75 kHostZoomMapKeyName, 91 kHostZoomMapKeyName,
76 new NonOwningZoomData( 92 new NonOwningZoomData(
77 HostZoomMap::GetForBrowserContext(browser_context))); 93 HostZoomMap::GetForBrowserContext(browser_context)));
94
78 resource_context->DetachUserDataThread(); 95 resource_context->DetachUserDataThread();
79 } 96 }
80 97
81 } // namespace content 98 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/resource_context_impl.h ('k') | content/browser/storage_partition_impl_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698