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

Side by Side Diff: chrome/browser/search/instant_io_context.cc

Issue 2856093004: Generalize content::URLDataSource so that it can be used by the network service. (Closed)
Patch Set: review comments Created 3 years, 7 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/search/instant_io_context.h" 5 #include "chrome/browser/search/instant_io_context.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/resource_context.h" 9 #include "content/public/browser/resource_context.h"
10 #include "content/public/browser/resource_request_info.h"
11 #include "net/url_request/url_request.h" 10 #include "net/url_request/url_request.h"
12 #include "url/gurl.h" 11 #include "url/gurl.h"
13 12
14 using content::BrowserThread; 13 using content::BrowserThread;
15 14
16 namespace { 15 namespace {
17 16
18 // Retrieves the Instant data from the |context|'s named user-data. 17 // Retrieves the Instant data from the |context|'s named user-data.
19 InstantIOContext* GetDataForResourceContext( 18 InstantIOContext* GetDataForResourceContext(
20 content::ResourceContext* context) { 19 content::ResourceContext* context) {
21 DCHECK_CURRENTLY_ON(BrowserThread::IO); 20 DCHECK_CURRENTLY_ON(BrowserThread::IO);
22 return base::UserDataAdapter<InstantIOContext>::Get( 21 return base::UserDataAdapter<InstantIOContext>::Get(
23 context, InstantIOContext::kInstantIOContextKeyName); 22 context, InstantIOContext::kInstantIOContextKeyName);
24 } 23 }
25 24
26 InstantIOContext* GetDataForRequest(const net::URLRequest* request) {
27 const content::ResourceRequestInfo* info =
28 content::ResourceRequestInfo::ForRequest(request);
29 if (!info)
30 return NULL;
31
32 return GetDataForResourceContext(info->GetContext());
33 }
34
35 } // namespace 25 } // namespace
36 26
37 const char InstantIOContext::kInstantIOContextKeyName[] = "instant_io_context"; 27 const char InstantIOContext::kInstantIOContextKeyName[] = "instant_io_context";
38 28
39 InstantIOContext::InstantIOContext() { 29 InstantIOContext::InstantIOContext() {
40 // The InstantIOContext is created on the UI thread but is accessed 30 // The InstantIOContext is created on the UI thread but is accessed
41 // on the IO thread. 31 // on the IO thread.
42 DCHECK_CURRENTLY_ON(BrowserThread::UI); 32 DCHECK_CURRENTLY_ON(BrowserThread::UI);
43 } 33 }
44 34
(...skipping 26 matching lines...) Expand all
71 } 61 }
72 62
73 // static 63 // static
74 void InstantIOContext::ClearInstantProcessesOnIO( 64 void InstantIOContext::ClearInstantProcessesOnIO(
75 scoped_refptr<InstantIOContext> instant_io_context) { 65 scoped_refptr<InstantIOContext> instant_io_context) {
76 DCHECK_CURRENTLY_ON(BrowserThread::IO); 66 DCHECK_CURRENTLY_ON(BrowserThread::IO);
77 instant_io_context->process_ids_.clear(); 67 instant_io_context->process_ids_.clear();
78 } 68 }
79 69
80 // static 70 // static
81 bool InstantIOContext::ShouldServiceRequest(const net::URLRequest* request) { 71 bool InstantIOContext::ShouldServiceRequest(
82 const content::ResourceRequestInfo* info = 72 const GURL& url,
83 content::ResourceRequestInfo::ForRequest(request); 73 content::ResourceContext* resource_context,
84 if (!info) 74 int render_process_id) {
75 if (!resource_context)
85 return false; 76 return false;
86 77
87 InstantIOContext* instant_io_context = GetDataForRequest(request); 78 InstantIOContext* instant_io_context =
79 GetDataForResourceContext(resource_context);
88 if (!instant_io_context) 80 if (!instant_io_context)
89 return false; 81 return false;
90 82
91 int process_id = -1;
92 int render_frame_id = -1;
93 info->GetAssociatedRenderFrame(&process_id, &render_frame_id);
94 // For PlzNavigate, the process_id for the navigation request will be -1. If 83 // For PlzNavigate, the process_id for the navigation request will be -1. If
95 // so, allow this request since it's not going to another renderer. 84 // so, allow this request since it's not going to another renderer.
96 if (process_id == -1 || instant_io_context->IsInstantProcess(process_id)) 85 return render_process_id == -1 ||
97 return true; 86 instant_io_context->IsInstantProcess(render_process_id);
98 return false;
99 } 87 }
100 88
101 bool InstantIOContext::IsInstantProcess(int process_id) const { 89 bool InstantIOContext::IsInstantProcess(int process_id) const {
102 DCHECK_CURRENTLY_ON(BrowserThread::IO); 90 DCHECK_CURRENTLY_ON(BrowserThread::IO);
103 return process_ids_.find(process_id) != process_ids_.end(); 91 return process_ids_.find(process_id) != process_ids_.end();
104 } 92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698