Chromium Code Reviews| 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/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 static const char* kBlobStorageContextKeyName = "content_blob_storage_context"; | |
|
awong
2013/01/24 19:55:29
The static is redundant here since were in the ano
awong
2013/01/24 20:10:42
FYI, reading through c-style@, const char[] seems
| |
| 24 static const char* kHostZoomMapKeyName = "content_host_zoom_map"; | |
| 25 static 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 |
| OLD | NEW |