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
3// found in the LICENSE file.
4
5#include "content/browser/loader/resource_message_filter.h"
6
7#include "content/browser/appcache/chrome_appcache_service.h"
8#include "content/browser/fileapi/chrome_blob_storage_context.h"
9#include "content/browser/loader/resource_dispatcher_host_impl.h"
10#include "content/browser/service_worker/service_worker_context_wrapper.h"
11#include "content/common/resource_messages.h"
12#include "content/public/browser/resource_context.h"
13#include "storage/browser/fileapi/file_system_context.h"
14
15namespace content {
16
17ResourceMessageFilter::ResourceMessageFilter(
18    int child_id,
19    int process_type,
20    ChromeAppCacheService* appcache_service,
21    ChromeBlobStorageContext* blob_storage_context,
22    storage::FileSystemContext* file_system_context,
23    ServiceWorkerContextWrapper* service_worker_context,
24    const GetContextsCallback& get_contexts_callback)
25    : BrowserMessageFilter(ResourceMsgStart),
26      child_id_(child_id),
27      process_type_(process_type),
28      appcache_service_(appcache_service),
29      blob_storage_context_(blob_storage_context),
30      file_system_context_(file_system_context),
31      service_worker_context_(service_worker_context),
32      get_contexts_callback_(get_contexts_callback),
33      weak_ptr_factory_(this) {
34}
35
36ResourceMessageFilter::~ResourceMessageFilter() {
37}
38
39void ResourceMessageFilter::OnChannelClosing() {
40  // Unhook us from all pending network requests so they don't get sent to a
41  // deleted object.
42  ResourceDispatcherHostImpl::Get()->CancelRequestsForProcess(child_id_);
43}
44
45bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message) {
46  return ResourceDispatcherHostImpl::Get()->OnMessageReceived(message, this);
47}
48
49void ResourceMessageFilter::GetContexts(
50    const ResourceHostMsg_Request& request,
51    ResourceContext** resource_context,
52    net::URLRequestContext** request_context) {
53  return get_contexts_callback_.Run(request, resource_context, request_context);
54}
55
56base::WeakPtr<ResourceMessageFilter> ResourceMessageFilter::GetWeakPtr() {
57  return weak_ptr_factory_.GetWeakPtr();
58}
59
60}  // namespace content
61