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

Side by Side Diff: extensions/renderer/script_injection_manager.cc

Issue 2640903005: Use loading task queue in ScriptInjectionManager
Patch Set: Created 3 years, 11 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
« no previous file with comments | « content/renderer/render_frame_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/renderer/script_injection_manager.h" 5 #include "extensions/renderer/script_injection_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 base::Bind(&ScriptInjectionManager::RFOHelper::StartInjectScripts, 177 base::Bind(&ScriptInjectionManager::RFOHelper::StartInjectScripts,
178 weak_factory_.GetWeakPtr(), UserScript::DOCUMENT_END)); 178 weak_factory_.GetWeakPtr(), UserScript::DOCUMENT_END));
179 179
180 // We try to run idle in two places: here and DidFinishLoad. 180 // We try to run idle in two places: here and DidFinishLoad.
181 // DidFinishDocumentLoad() corresponds to completing the document's load, 181 // DidFinishDocumentLoad() corresponds to completing the document's load,
182 // whereas DidFinishLoad corresponds to completing the document and all 182 // whereas DidFinishLoad corresponds to completing the document and all
183 // subresources' load. We don't want to hold up script injection for a 183 // subresources' load. We don't want to hold up script injection for a
184 // particularly slow subresource, so we set a delayed task from here - but if 184 // particularly slow subresource, so we set a delayed task from here - but if
185 // we finish everything before that point (i.e., DidFinishLoad() is 185 // we finish everything before that point (i.e., DidFinishLoad() is
186 // triggered), then there's no reason to keep waiting. 186 // triggered), then there's no reason to keep waiting.
187 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 187 render_frame()->GetLoadingTaskRunner()->PostDelayedTask(
188 FROM_HERE, 188 FROM_HERE,
189 base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle, 189 base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle,
190 weak_factory_.GetWeakPtr()), 190 weak_factory_.GetWeakPtr()),
191 base::TimeDelta::FromMilliseconds(kScriptIdleTimeoutInMs)); 191 base::TimeDelta::FromMilliseconds(kScriptIdleTimeoutInMs));
192 } 192 }
193 193
194 void ScriptInjectionManager::RFOHelper::DidFinishLoad() { 194 void ScriptInjectionManager::RFOHelper::DidFinishLoad() {
195 DCHECK(content::RenderThread::Get()); 195 DCHECK(content::RenderThread::Get());
196 // Ensure that we don't block any UI progress by running scripts. 196 // Ensure that we don't block any UI progress by running scripts.
197 base::ThreadTaskRunnerHandle::Get()->PostTask( 197 render_frame()->GetLoadingTaskRunner()->PostTask(
198 FROM_HERE, 198 FROM_HERE,
199 base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle, 199 base::Bind(&ScriptInjectionManager::RFOHelper::RunIdle,
200 weak_factory_.GetWeakPtr())); 200 weak_factory_.GetWeakPtr()));
201 } 201 }
202 202
203 void ScriptInjectionManager::RFOHelper::FrameDetached() { 203 void ScriptInjectionManager::RFOHelper::FrameDetached() {
204 // The frame is closing - invalidate. 204 // The frame is closing - invalidate.
205 InvalidateAndResetFrame(); 205 InvalidateAndResetFrame();
206 } 206 }
207 207
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 ScriptsRunInfo scripts_run_info(injection->render_frame(), 514 ScriptsRunInfo scripts_run_info(injection->render_frame(),
515 UserScript::RUN_DEFERRED); 515 UserScript::RUN_DEFERRED);
516 ScriptInjection::InjectionResult res = injection->OnPermissionGranted( 516 ScriptInjection::InjectionResult res = injection->OnPermissionGranted(
517 &scripts_run_info); 517 &scripts_run_info);
518 if (res == ScriptInjection::INJECTION_BLOCKED) 518 if (res == ScriptInjection::INJECTION_BLOCKED)
519 running_injections_.push_back(std::move(injection)); 519 running_injections_.push_back(std::move(injection));
520 scripts_run_info.LogRun(activity_logging_enabled_); 520 scripts_run_info.LogRun(activity_logging_enabled_);
521 } 521 }
522 522
523 } // namespace extensions 523 } // namespace extensions
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698