android_webview
apps
ash
base
breakpad
build
cc
chrome
chrome_frame
chromeos
cloud_print
components
content
app
browser
accessibility
android
appcache
aura
browser_plugin
device_orientation
devtools
dom_storage
download
fileapi
gamepad
geolocation
gpu
indexed_db
loader
media
net
renderer_host
resources
speech
ssl
streams
tracing
web_contents
webui
worker_host
zygote_host
DEPS
OWNERS
bookmarklet_browsertest.cc
browser_child_process_host_impl.cc
browser_child_process_host_impl.h
browser_context.cc
browser_ipc_logging.cc
browser_main.cc
browser_main.h
browser_main_loop.cc
browser_main_loop.h
browser_main_runner.cc
browser_process_sub_thread.cc
browser_process_sub_thread.h
browser_thread_impl.cc
browser_thread_impl.h
browser_thread_unittest.cc
browser_url_handler_impl.cc
browser_url_handler_impl.h
browser_url_handler_impl_unittest.cc
browsing_instance.cc
browsing_instance.h
byte_stream.cc
byte_stream.h
byte_stream_unittest.cc
cert_store_impl.cc
cert_store_impl.h
child_process_launcher.cc
child_process_launcher.h
child_process_security_policy_browsertest.cc
child_process_security_policy_impl.cc
child_process_security_policy_impl.h
child_process_security_policy_unittest.cc
cross_site_request_manager.cc
cross_site_request_manager.h
database_browsertest.cc
device_monitor_linux.cc
device_monitor_linux.h
device_monitor_mac.h
device_monitor_mac.mm
font_list_async.cc
gpu.sb
histogram_controller.cc
histogram_controller.h
histogram_internals_request_job.cc
histogram_internals_request_job.h
histogram_message_filter.cc
histogram_message_filter.h
histogram_subscriber.h
histogram_synchronizer.cc
histogram_synchronizer.h
host_zoom_map_impl.cc
host_zoom_map_impl.h
host_zoom_map_impl_unittest.cc
mach_broker_mac.h
mach_broker_mac.mm
mach_broker_mac_unittest.cc
media_devices_monitor.cc
mime_registry_message_filter.cc
mime_registry_message_filter.h
notification_service_impl.cc
notification_service_impl.h
notification_service_impl_unittest.cc
pepper_flash_settings_helper_impl.cc
pepper_flash_settings_helper_impl.h
plugin_browsertest.cc
plugin_data_remover_impl.cc
plugin_data_remover_impl.h
plugin_data_remover_impl_browsertest.cc
plugin_loader_posix.cc
plugin_loader_posix.h
plugin_loader_posix_unittest.cc
plugin_process_host.cc
plugin_process_host.h
plugin_process_host_mac.cc
plugin_service_impl.cc
plugin_service_impl.h
plugin_service_impl_browsertest.cc
power_monitor_message_broadcaster.cc
power_monitor_message_broadcaster.h
power_monitor_message_broadcaster_unittest.cc
power_save_blocker_android.cc
power_save_blocker_android.h
power_save_blocker_chromeos.cc
power_save_blocker_impl.cc
power_save_blocker_impl.h
power_save_blocker_mac.cc
power_save_blocker_ozone.cc
power_save_blocker_win.cc
power_save_blocker_x11.cc
ppapi_plugin_process_host.cc
ppapi_plugin_process_host.h
profiler_controller_impl.cc
profiler_controller_impl.h
profiler_message_filter.cc
profiler_message_filter.h
quota_dispatcher_host.cc
quota_dispatcher_host.h
resolve_proxy_msg_helper.cc
resolve_proxy_msg_helper.h
resolve_proxy_msg_helper_unittest.cc
resource_context_impl.cc
resource_context_impl.h
safe_util_win.cc
safe_util_win.h
security_exploit_browsertest.cc
session_history_browsertest.cc
site_instance_impl.cc
site_instance_impl.h
site_instance_impl_unittest.cc
site_per_process_browsertest.cc
startup_task_runner.cc
startup_task_runner.h
startup_task_runner_unittest.cc
storage_partition_impl.cc
storage_partition_impl.h
storage_partition_impl_map.cc
storage_partition_impl_map.h
storage_partition_impl_map_unittest.cc
storage_partition_impl_unittest.cc
system_message_window_win.cc
system_message_window_win.h
system_message_window_win_unittest.cc
tcmalloc_internals_request_job.cc
tcmalloc_internals_request_job.h
udev_linux.cc
udev_linux.h
user_metrics.cc
utility_process_host_impl.cc
utility_process_host_impl.h
webkit_browsertest.cc
worker.sb
child
common
gpu
plugin
port
ppapi_plugin
public
renderer
shell
test
utility
worker
zygote
DEPS
OWNERS
content.gyp
content_app.gypi
content_browser.gypi
content_browsertests.isolate
content_child.gypi
content_common.gypi
content_gpu.gypi
content_jni.gypi
content_plugin.gypi
content_ppapi_plugin.gypi
content_renderer.gypi
content_resources.grd
content_resources.gyp
content_shell.gypi
content_tests.gypi
content_unittests.isolate
content_utility.gypi
content_worker.gypi
courgette
crypto
dbus
device
extensions
google_apis
google_update
gpu
ios
ipc
jingle
media
native_client_sdk
net
ppapi
printing
remoting
rlz
sandbox
sdch
skia
sql
sync
testing
third_party
tools
ui
url
webkit
win8
.DEPS.git
.gitignore
.gitmodules
.gn
AUTHORS
Android.mk
DEPS
LICENSE
LICENSE.chromium_os
OWNERS
PRESUBMIT.py
PRESUBMIT_test.py
WATCHLISTS
codereview.settings
update_verification.py

This fixes the memory leaks introduced by the original CL. BUG=171585 Review URL: https://chromiumcodereview.appspot.com/12637006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187777 0039d316-1c4b-4281-b951-d872f2087c98
113 lines
3.8 KiB
C++
113 lines
3.8 KiB
C++
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "content/browser/resource_context_impl.h"
|
|
|
|
#include "base/logging.h"
|
|
#include "content/browser/fileapi/chrome_blob_storage_context.h"
|
|
#include "content/browser/host_zoom_map_impl.h"
|
|
#include "content/browser/loader/resource_dispatcher_host_impl.h"
|
|
#include "content/browser/loader/resource_request_info_impl.h"
|
|
#include "content/browser/streams/stream_context.h"
|
|
#include "content/browser/webui/url_data_manager_backend.h"
|
|
#include "content/public/browser/browser_context.h"
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
using base::UserDataAdapter;
|
|
|
|
namespace content {
|
|
|
|
namespace {
|
|
|
|
// Key names on ResourceContext.
|
|
const char kBlobStorageContextKeyName[] = "content_blob_storage_context";
|
|
const char kHostZoomMapKeyName[] = "content_host_zoom_map";
|
|
const char kStreamContextKeyName[] = "content_stream_context";
|
|
const char kURLDataManagerBackendKeyName[] = "url_data_manager_backend";
|
|
|
|
class NonOwningZoomData : public base::SupportsUserData::Data {
|
|
public:
|
|
explicit NonOwningZoomData(HostZoomMap* hzm) : host_zoom_map_(hzm) {}
|
|
HostZoomMap* host_zoom_map() { return host_zoom_map_; }
|
|
|
|
private:
|
|
HostZoomMap* host_zoom_map_;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
ResourceContext::ResourceContext() {
|
|
if (ResourceDispatcherHostImpl::Get())
|
|
ResourceDispatcherHostImpl::Get()->AddResourceContext(this);
|
|
}
|
|
|
|
ResourceContext::~ResourceContext() {
|
|
ResourceDispatcherHostImpl* rdhi = ResourceDispatcherHostImpl::Get();
|
|
if (rdhi) {
|
|
rdhi->CancelRequestsForContext(this);
|
|
rdhi->RemoveResourceContext(this);
|
|
}
|
|
|
|
// In some tests this object is destructed on UI thread.
|
|
DetachUserDataThread();
|
|
}
|
|
|
|
ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext(
|
|
ResourceContext* resource_context) {
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
|
return UserDataAdapter<ChromeBlobStorageContext>::Get(
|
|
resource_context, kBlobStorageContextKeyName);
|
|
}
|
|
|
|
StreamContext* GetStreamContextForResourceContext(
|
|
ResourceContext* resource_context) {
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
|
return UserDataAdapter<StreamContext>::Get(
|
|
resource_context, kStreamContextKeyName);
|
|
}
|
|
|
|
HostZoomMap* GetHostZoomMapForResourceContext(ResourceContext* context) {
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
|
return static_cast<NonOwningZoomData*>(
|
|
context->GetUserData(kHostZoomMapKeyName))->host_zoom_map();
|
|
}
|
|
|
|
URLDataManagerBackend* GetURLDataManagerForResourceContext(
|
|
ResourceContext* context) {
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
|
if (!context->GetUserData(kURLDataManagerBackendKeyName)) {
|
|
context->SetUserData(kURLDataManagerBackendKeyName,
|
|
new URLDataManagerBackend());
|
|
}
|
|
return static_cast<URLDataManagerBackend*>(
|
|
context->GetUserData(kURLDataManagerBackendKeyName));
|
|
}
|
|
|
|
void InitializeResourceContext(BrowserContext* browser_context) {
|
|
ResourceContext* resource_context = browser_context->GetResourceContext();
|
|
DCHECK(!resource_context->GetUserData(kHostZoomMapKeyName));
|
|
|
|
resource_context->SetUserData(
|
|
kBlobStorageContextKeyName,
|
|
new UserDataAdapter<ChromeBlobStorageContext>(
|
|
ChromeBlobStorageContext::GetFor(browser_context)));
|
|
|
|
resource_context->SetUserData(
|
|
kStreamContextKeyName,
|
|
new UserDataAdapter<StreamContext>(
|
|
StreamContext::GetFor(browser_context)));
|
|
|
|
// This object is owned by the BrowserContext and not ResourceContext, so
|
|
// store a non-owning pointer here.
|
|
resource_context->SetUserData(
|
|
kHostZoomMapKeyName,
|
|
new NonOwningZoomData(
|
|
HostZoomMap::GetForBrowserContext(browser_context)));
|
|
|
|
resource_context->DetachUserDataThread();
|
|
}
|
|
|
|
} // namespace content
|