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

Side by Side Diff: extensions/browser/web_ui_user_script_loader.cc

Issue 2898523002: Remove the usage of BrowserThread::FILE in web_ui_user_script_loader.cc (Closed)
Patch Set: 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
« no previous file with comments | « extensions/browser/user_script_loader.h ('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 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 "extensions/browser/web_ui_user_script_loader.h" 5 #include "extensions/browser/web_ui_user_script_loader.h"
6 6
7 #include <set>
8 #include <string>
7 #include <utility> 9 #include <utility>
8 10
9 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/sequenced_task_runner.h"
10 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/task_scheduler/post_task.h"
16 #include "base/threading/sequenced_task_runner_handle.h"
11 #include "content/public/browser/browser_context.h" 17 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
14 #include "extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher.h" 19 #include "extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher.h"
15 20
16 namespace { 21 namespace {
17 22
18 void SerializeOnFileThread( 23 void SerializeOnBlockingTask(
24 scoped_refptr<base::SequencedTaskRunner> task_runner,
19 std::unique_ptr<extensions::UserScriptList> user_scripts, 25 std::unique_ptr<extensions::UserScriptList> user_scripts,
20 extensions::UserScriptLoader::LoadScriptsCallback callback) { 26 extensions::UserScriptLoader::LoadScriptsCallback callback) {
21 std::unique_ptr<base::SharedMemory> memory = 27 std::unique_ptr<base::SharedMemory> memory =
22 extensions::UserScriptLoader::Serialize(*user_scripts); 28 extensions::UserScriptLoader::Serialize(*user_scripts);
23 content::BrowserThread::PostTask( 29
24 content::BrowserThread::UI, FROM_HERE, 30 task_runner->PostTask(
25 base::Bind(callback, base::Passed(&user_scripts), base::Passed(&memory))); 31 FROM_HERE, base::BindOnce(std::move(callback), std::move(user_scripts),
32 std::move(memory)));
26 } 33 }
27 34
28 } // namespace 35 } // namespace
29 36
30 struct WebUIUserScriptLoader::UserScriptRenderInfo { 37 struct WebUIUserScriptLoader::UserScriptRenderInfo {
31 int render_process_id; 38 int render_process_id;
32 int render_frame_id; 39 int render_frame_id;
33 40
34 UserScriptRenderInfo() : render_process_id(-1), render_frame_id(-1) {} 41 UserScriptRenderInfo() : render_process_id(-1), render_frame_id(-1) {}
35 42
(...skipping 25 matching lines...) Expand all
61 extensions::UserScriptLoader::AddScripts(std::move(scripts)); 68 extensions::UserScriptLoader::AddScripts(std::move(scripts));
62 } 69 }
63 70
64 void WebUIUserScriptLoader::LoadScripts( 71 void WebUIUserScriptLoader::LoadScripts(
65 std::unique_ptr<extensions::UserScriptList> user_scripts, 72 std::unique_ptr<extensions::UserScriptList> user_scripts,
66 const std::set<HostID>& changed_hosts, 73 const std::set<HostID>& changed_hosts,
67 const std::set<int>& added_script_ids, 74 const std::set<int>& added_script_ids,
68 LoadScriptsCallback callback) { 75 LoadScriptsCallback callback) {
69 DCHECK(!user_scripts_cache_) << "Loading scripts in flight."; 76 DCHECK(!user_scripts_cache_) << "Loading scripts in flight.";
70 user_scripts_cache_.swap(user_scripts); 77 user_scripts_cache_.swap(user_scripts);
71 scripts_loaded_callback_ = callback; 78 scripts_loaded_callback_ = std::move(callback);
72 79
73 // The total number of the tasks is used to trace whether all the fetches 80 // The total number of the tasks is used to trace whether all the fetches
74 // are complete. Therefore, we store all the fetcher pointers in |fetchers_| 81 // are complete. Therefore, we store all the fetcher pointers in |fetchers_|
75 // before we get theis number. Once we get the total number, start each 82 // before we get theis number. Once we get the total number, start each
76 // fetch tasks. 83 // fetch tasks.
77 DCHECK_EQ(0u, complete_fetchers_); 84 DCHECK_EQ(0u, complete_fetchers_);
78 85
79 for (const std::unique_ptr<extensions::UserScript>& script : 86 for (const std::unique_ptr<extensions::UserScript>& script :
80 *user_scripts_cache_) { 87 *user_scripts_cache_) {
81 if (added_script_ids.count(script->id()) == 0) 88 if (added_script_ids.count(script->id()) == 0)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 156
150 ++complete_fetchers_; 157 ++complete_fetchers_;
151 if (complete_fetchers_ == fetchers_.size()) { 158 if (complete_fetchers_ == fetchers_.size()) {
152 complete_fetchers_ = 0; 159 complete_fetchers_ = 0;
153 OnWebUIURLFetchComplete(); 160 OnWebUIURLFetchComplete();
154 fetchers_.clear(); 161 fetchers_.clear();
155 } 162 }
156 } 163 }
157 164
158 void WebUIUserScriptLoader::OnWebUIURLFetchComplete() { 165 void WebUIUserScriptLoader::OnWebUIURLFetchComplete() {
159 content::BrowserThread::PostTask( 166 base::PostTaskWithTraits(
160 content::BrowserThread::FILE, FROM_HERE, 167 FROM_HERE, {base::MayBlock()},
161 base::Bind(&SerializeOnFileThread, base::Passed(&user_scripts_cache_), 168 base::BindOnce(
162 scripts_loaded_callback_)); 169 &SerializeOnBlockingTask, base::SequencedTaskRunnerHandle::Get(),
163 scripts_loaded_callback_.Reset(); 170 std::move(user_scripts_cache_), std::move(scripts_loaded_callback_)));
164 user_scripts_cache_.reset();
165 } 171 }
OLDNEW
« no previous file with comments | « extensions/browser/user_script_loader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698