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

Side by Side Diff: content/browser/loader/cross_site_resource_handler_browsertest.cc

Issue 1542743002: [RDHI] Refactored blocked_loaders_map_ to key by render frame route id (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: just comments / minor restructuring (trybots previous) Created 4 years, 12 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/callback.h" 5 #include "base/callback.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "content/browser/frame_host/render_frame_host_impl.h" 10 #include "content/browser/frame_host/render_frame_host_impl.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 private: 90 private:
91 // A ResourceThrottle which defers the request at WillStartRequest time until 91 // A ResourceThrottle which defers the request at WillStartRequest time until
92 // a test-supplied callback completes. Notifies |tracker| when the request is 92 // a test-supplied callback completes. Notifies |tracker| when the request is
93 // destroyed. 93 // destroyed.
94 class CallbackRunningResourceThrottle : public ResourceThrottle { 94 class CallbackRunningResourceThrottle : public ResourceThrottle {
95 public: 95 public:
96 CallbackRunningResourceThrottle(net::URLRequest* request, 96 CallbackRunningResourceThrottle(net::URLRequest* request,
97 TestResourceDispatcherHostDelegate* tracker, 97 TestResourceDispatcherHostDelegate* tracker,
98 const RequestDeferredHook& run_on_start) 98 const RequestDeferredHook& run_on_start)
99 : request_(request), 99 : resumed_(false),
100 request_(request),
100 tracker_(tracker), 101 tracker_(tracker),
101 run_on_start_(run_on_start), 102 run_on_start_(run_on_start),
102 weak_factory_(this) {} 103 weak_factory_(this) {}
103 104
104 void WillStartRequest(bool* defer) override { 105 void WillStartRequest(bool* defer) override {
105 *defer = true; 106 *defer = true;
106 base::Closure resume_request_on_io_thread = base::Bind( 107 base::Closure resume_request_on_io_thread = base::Bind(
107 base::IgnoreResult(&BrowserThread::PostTask), BrowserThread::IO, 108 base::IgnoreResult(&BrowserThread::PostTask), BrowserThread::IO,
108 FROM_HERE, base::Bind(&CallbackRunningResourceThrottle::Resume, 109 FROM_HERE, base::Bind(&CallbackRunningResourceThrottle::Resume,
109 weak_factory_.GetWeakPtr())); 110 weak_factory_.GetWeakPtr()));
110 BrowserThread::PostTask( 111 BrowserThread::PostTask(
111 BrowserThread::UI, FROM_HERE, 112 BrowserThread::UI, FROM_HERE,
112 base::Bind(run_on_start_, resume_request_on_io_thread)); 113 base::Bind(run_on_start_, resume_request_on_io_thread));
113 } 114 }
114 115
115 ~CallbackRunningResourceThrottle() override { 116 ~CallbackRunningResourceThrottle() override {
116 // If the request is deleted without being cancelled, its status will 117 // If the request is deleted without being cancelled, its status will
117 // indicate it succeeded, so have to check if the request is still pending 118 // indicate it succeeded, so have to check if the request is still pending
118 // as well. 119 // as well. If the request never even started, the throttle will never
120 // resume it. Check this condition as well to allow for early
121 // cancellation.
119 tracker_->OnTrackedRequestDestroyed(!request_->is_pending() && 122 tracker_->OnTrackedRequestDestroyed(!request_->is_pending() &&
120 request_->status().is_success()); 123 request_->status().is_success() &&
124 resumed_);
121 } 125 }
122 126
123 // ResourceThrottle implementation: 127 // ResourceThrottle implementation:
124 const char* GetNameForLogging() const override { 128 const char* GetNameForLogging() const override {
125 return "CallbackRunningResourceThrottle"; 129 return "CallbackRunningResourceThrottle";
126 } 130 }
127 131
128 private: 132 private:
129 void Resume() { controller()->Resume(); } 133 void Resume() {
134 resumed_ = true;
135 controller()->Resume();
136 }
137
138 bool resumed_;
130 net::URLRequest* request_; 139 net::URLRequest* request_;
131 TestResourceDispatcherHostDelegate* tracker_; 140 TestResourceDispatcherHostDelegate* tracker_;
132 RequestDeferredHook run_on_start_; 141 RequestDeferredHook run_on_start_;
133 base::WeakPtrFactory<CallbackRunningResourceThrottle> weak_factory_; 142 base::WeakPtrFactory<CallbackRunningResourceThrottle> weak_factory_;
134 143
135 DISALLOW_COPY_AND_ASSIGN(CallbackRunningResourceThrottle); 144 DISALLOW_COPY_AND_ASSIGN(CallbackRunningResourceThrottle);
136 }; 145 };
137 146
138 void SetTrackedURLOnIOThread(const GURL& tracked_url, 147 void SetTrackedURLOnIOThread(const GURL& tracked_url,
139 const RequestDeferredHook& run_on_start, 148 const RequestDeferredHook& run_on_start,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 base::StringPrintf("document.getElementById('child-0').src='%s'", 277 base::StringPrintf("document.getElementById('child-0').src='%s'",
269 target_resource.spec().c_str()))); 278 target_resource.spec().c_str())));
270 279
271 // Wait for the scenario to play out. If this returns false, it means the 280 // Wait for the scenario to play out. If this returns false, it means the
272 // request did not succeed, which is good in this case. 281 // request did not succeed, which is good in this case.
273 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted()) 282 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted())
274 << "Request should have been cancelled before reaching the renderer."; 283 << "Request should have been cancelled before reaching the renderer.";
275 } 284 }
276 285
277 } // namespace content 286 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698