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

Unified Diff: content/browser/loader/resource_requester_info.cc

Issue 2481093003: Introduce ResourceRequesterInfo to abstract the requester of resource request (Closed)
Patch Set: fix unittests Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/loader/resource_requester_info.cc
diff --git a/content/browser/loader/resource_requester_info.cc b/content/browser/loader/resource_requester_info.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8257b628466b97cb4dd590f8382a6029a561752a
--- /dev/null
+++ b/content/browser/loader/resource_requester_info.cc
@@ -0,0 +1,99 @@
+// Copyright 2016 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/loader/resource_requester_info.h"
+
+#include "base/memory/ptr_util.h"
+#include "content/browser/appcache/chrome_appcache_service.h"
+#include "content/browser/blob_storage/chrome_blob_storage_context.h"
+#include "content/browser/loader/resource_message_filter.h"
+#include "content/browser/service_worker/service_worker_context_wrapper.h"
+#include "content/public/browser/resource_context.h"
+#include "storage/browser/fileapi/file_system_context.h"
+
+namespace content {
+
+ResourceRequesterInfo::ResourceRequesterInfo(
+ RequesterType type,
+ int child_id,
+ ChromeAppCacheService* appcache_service,
+ ChromeBlobStorageContext* blob_storage_context,
+ storage::FileSystemContext* file_system_context,
+ ServiceWorkerContextWrapper* service_worker_context,
+ const GetContextsCallback& get_contexts_callback)
+ : type_(type),
+ child_id_(child_id),
+ appcache_service_(appcache_service),
+ blob_storage_context_(blob_storage_context),
+ file_system_context_(file_system_context),
+ service_worker_context_(service_worker_context),
+ get_contexts_callback_(get_contexts_callback) {}
+
+ResourceRequesterInfo::~ResourceRequesterInfo() {}
+
+std::unique_ptr<ResourceRequesterInfo> ResourceRequesterInfo::clone() const {
+ std::unique_ptr<ResourceRequesterInfo> info =
+ base::WrapUnique(new ResourceRequesterInfo(
+ type_, child_id_, appcache_service_.get(),
+ blob_storage_context_.get(), file_system_context_.get(),
+ service_worker_context_.get(), get_contexts_callback_));
+ if (type_ == RequesterType::RENDERER)
+ info->set_filter(filter_);
+ return info;
+}
+
+void ResourceRequesterInfo::set_filter(
+ base::WeakPtr<ResourceMessageFilter> filter) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(type_ == RequesterType::RENDERER);
mmenke 2016/11/17 16:27:20 include base/logging.h
mmenke 2016/11/17 16:27:20 DCHECK_EQ
horo 2016/11/17 17:50:27 Done.
horo 2016/11/17 17:50:27 Done.
+ filter_ = filter;
+}
+
+void ResourceRequesterInfo::GetContexts(
+ ResourceType resource_type,
+ ResourceContext** resource_context,
+ net::URLRequestContext** request_context) const {
+ get_contexts_callback_.Run(resource_type, resource_context, request_context);
+}
+
+std::unique_ptr<ResourceRequesterInfo> ResourceRequesterInfo::CreateForRenderer(
+ int child_id,
+ ChromeAppCacheService* appcache_service,
+ ChromeBlobStorageContext* blob_storage_context,
+ storage::FileSystemContext* file_system_context,
+ ServiceWorkerContextWrapper* service_worker_context,
+ const GetContextsCallback& get_contexts_callback) {
+ return base::WrapUnique(new ResourceRequesterInfo(
+ RequesterType::RENDERER, child_id, appcache_service, blob_storage_context,
+ file_system_context, service_worker_context, get_contexts_callback));
+}
+
+std::unique_ptr<ResourceRequesterInfo>
+ResourceRequesterInfo::CreateForRendererTesting(int child_id) {
+ return base::WrapUnique(new ResourceRequesterInfo(
+ RequesterType::RENDERER, child_id, nullptr /* appcache_service */,
+ nullptr /* blob_storage_context */, nullptr /* file_system_context */,
+ nullptr /*service_worker_context */, GetContextsCallback()));
+}
+
+std::unique_ptr<ResourceRequesterInfo>
+ResourceRequesterInfo::CreateForBrowserSideNavigation(
+ scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) {
+ return base::WrapUnique(new ResourceRequesterInfo(
+ RequesterType::BROWSER_SIDE_NAVIGATION, -1,
+ nullptr /* appcache_service */, nullptr /* blob_storage_context */,
+ nullptr /* file_system_context */, service_worker_context.get(),
+ GetContextsCallback()));
+}
+
+std::unique_ptr<ResourceRequesterInfo>
+ResourceRequesterInfo::CreateForDownloadOrPageSave(int child_id) {
+ return base::WrapUnique(new ResourceRequesterInfo(
+ RequesterType::DOWNLOAD_OR_PAGE_SAVE, child_id,
+ nullptr /* appcache_service */, nullptr /* blob_storage_context */,
+ nullptr /* file_system_context */, nullptr /*service_worker_context */,
+ GetContextsCallback()));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698