| 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 // Key names on ResourceContext. |
| 16 static const char* kBlobStorageContextKeyName = "content_blob_storage_context"; | 17 static const char* kBlobStorageContextKeyName = "content_blob_storage_context"; |
| 17 static const char* kHostZoomMapKeyName = "content_host_zoom_map"; | 18 static const char* kHostZoomMapKeyName = "content_host_zoom_map"; |
| 19 static const char* kURLDataManagerKeyName = "url_data_manager"; |
| 18 | 20 |
| 19 using base::UserDataAdapter; | 21 using base::UserDataAdapter; |
| 20 | 22 |
| 21 namespace content { | 23 namespace content { |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 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) {} |
| (...skipping 25 matching lines...) Expand all Loading... |
| 53 return UserDataAdapter<ChromeBlobStorageContext>::Get( | 55 return UserDataAdapter<ChromeBlobStorageContext>::Get( |
| 54 resource_context, kBlobStorageContextKeyName); | 56 resource_context, kBlobStorageContextKeyName); |
| 55 } | 57 } |
| 56 | 58 |
| 57 HostZoomMap* GetHostZoomMapForResourceContext(ResourceContext* context) { | 59 HostZoomMap* GetHostZoomMapForResourceContext(ResourceContext* context) { |
| 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 59 return static_cast<NonOwningZoomData*>( | 61 return static_cast<NonOwningZoomData*>( |
| 60 context->GetUserData(kHostZoomMapKeyName))->host_zoom_map(); | 62 context->GetUserData(kHostZoomMapKeyName))->host_zoom_map(); |
| 61 } | 63 } |
| 62 | 64 |
| 65 ChromeURLDataManagerBackend* GetURLDataManagerForResourceContext( |
| 66 ResourceContext* context) { |
| 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 68 if (!context->GetUserData(kURLDataManagerKeyName)) { |
| 69 context->SetUserData(kURLDataManagerKeyName, |
| 70 new ChromeURLDataManagerBackend()); |
| 71 } |
| 72 return static_cast<ChromeURLDataManagerBackend*>( |
| 73 context->GetUserData(kURLDataManagerKeyName)); |
| 74 } |
| 75 |
| 63 void InitializeResourceContext(BrowserContext* browser_context) { | 76 void InitializeResourceContext(BrowserContext* browser_context) { |
| 64 ResourceContext* resource_context = browser_context->GetResourceContext(); | 77 ResourceContext* resource_context = browser_context->GetResourceContext(); |
| 65 DCHECK(!resource_context->GetUserData(kHostZoomMapKeyName)); | 78 DCHECK(!resource_context->GetUserData(kHostZoomMapKeyName)); |
| 66 | 79 |
| 67 resource_context->SetUserData( | 80 resource_context->SetUserData( |
| 68 kBlobStorageContextKeyName, | 81 kBlobStorageContextKeyName, |
| 69 new UserDataAdapter<ChromeBlobStorageContext>( | 82 new UserDataAdapter<ChromeBlobStorageContext>( |
| 70 ChromeBlobStorageContext::GetFor(browser_context))); | 83 ChromeBlobStorageContext::GetFor(browser_context))); |
| 71 | 84 |
| 72 // This object is owned by the BrowserContext and not ResourceContext, so | 85 // This object is owned by the BrowserContext and not ResourceContext, so |
| 73 // store a non-owning pointer here. | 86 // store a non-owning pointer here. |
| 74 resource_context->SetUserData( | 87 resource_context->SetUserData( |
| 75 kHostZoomMapKeyName, | 88 kHostZoomMapKeyName, |
| 76 new NonOwningZoomData( | 89 new NonOwningZoomData( |
| 77 HostZoomMap::GetForBrowserContext(browser_context))); | 90 HostZoomMap::GetForBrowserContext(browser_context))); |
| 91 |
| 78 resource_context->DetachUserDataThread(); | 92 resource_context->DetachUserDataThread(); |
| 79 } | 93 } |
| 80 | 94 |
| 81 } // namespace content | 95 } // namespace content |
| OLD | NEW |