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 1909773002: Convert //extensions/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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 "extensions/browser/web_ui_user_script_loader.h" 5 #include "extensions/browser/web_ui_user_script_loader.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "content/public/browser/browser_context.h" 11 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/render_process_host.h" 13 #include "content/public/browser/render_process_host.h"
14 #include "extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher.h" 14 #include "extensions/browser/guest_view/web_view/web_ui/web_ui_url_fetcher.h"
15 15
16 namespace { 16 namespace {
17 17
18 void SerializeOnFileThread( 18 void SerializeOnFileThread(
19 scoped_ptr<extensions::UserScriptList> user_scripts, 19 std::unique_ptr<extensions::UserScriptList> user_scripts,
20 extensions::UserScriptLoader::LoadScriptsCallback callback) { 20 extensions::UserScriptLoader::LoadScriptsCallback callback) {
21 scoped_ptr<base::SharedMemory> memory = 21 std::unique_ptr<base::SharedMemory> memory =
22 extensions::UserScriptLoader::Serialize(*user_scripts); 22 extensions::UserScriptLoader::Serialize(*user_scripts);
23 content::BrowserThread::PostTask( 23 content::BrowserThread::PostTask(
24 content::BrowserThread::UI, FROM_HERE, 24 content::BrowserThread::UI, FROM_HERE,
25 base::Bind(callback, base::Passed(&user_scripts), base::Passed(&memory))); 25 base::Bind(callback, base::Passed(&user_scripts), base::Passed(&memory)));
26 } 26 }
27 27
28 } // namespace 28 } // namespace
29 29
30 struct WebUIUserScriptLoader::UserScriptRenderInfo { 30 struct WebUIUserScriptLoader::UserScriptRenderInfo {
31 int render_process_id; 31 int render_process_id;
(...skipping 22 matching lines...) Expand all
54 UserScriptRenderInfo info(render_process_id, render_view_id); 54 UserScriptRenderInfo info(render_process_id, render_view_id);
55 for (const extensions::UserScript& script : scripts) { 55 for (const extensions::UserScript& script : scripts) {
56 script_render_info_map_.insert( 56 script_render_info_map_.insert(
57 std::pair<int, UserScriptRenderInfo>(script.id(), info)); 57 std::pair<int, UserScriptRenderInfo>(script.id(), info));
58 } 58 }
59 59
60 extensions::UserScriptLoader::AddScripts(scripts); 60 extensions::UserScriptLoader::AddScripts(scripts);
61 } 61 }
62 62
63 void WebUIUserScriptLoader::LoadScripts( 63 void WebUIUserScriptLoader::LoadScripts(
64 scoped_ptr<extensions::UserScriptList> user_scripts, 64 std::unique_ptr<extensions::UserScriptList> user_scripts,
65 const std::set<HostID>& changed_hosts, 65 const std::set<HostID>& changed_hosts,
66 const std::set<int>& added_script_ids, 66 const std::set<int>& added_script_ids,
67 LoadScriptsCallback callback) { 67 LoadScriptsCallback callback) {
68 user_scripts_cache_.swap(user_scripts); 68 user_scripts_cache_.swap(user_scripts);
69 scripts_loaded_callback_ = callback; 69 scripts_loaded_callback_ = callback;
70 70
71 // The total number of the tasks is used to trace whether all the fetches 71 // The total number of the tasks is used to trace whether all the fetches
72 // are complete. Therefore, we store all the fetcher pointers in |fetchers_| 72 // are complete. Therefore, we store all the fetcher pointers in |fetchers_|
73 // before we get theis number. Once we get the total number, start each 73 // before we get theis number. Once we get the total number, start each
74 // fetch tasks. 74 // fetch tasks.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 void WebUIUserScriptLoader::CreateWebUIURLFetchers( 107 void WebUIUserScriptLoader::CreateWebUIURLFetchers(
108 extensions::UserScript::FileList* script_files, 108 extensions::UserScript::FileList* script_files,
109 content::BrowserContext* browser_context, 109 content::BrowserContext* browser_context,
110 int render_process_id, 110 int render_process_id,
111 int render_view_id) { 111 int render_view_id) {
112 for (extensions::UserScript::File& file : *script_files) { 112 for (extensions::UserScript::File& file : *script_files) {
113 if (file.GetContent().empty()) { 113 if (file.GetContent().empty()) {
114 // The WebUIUserScriptLoader owns these WebUIURLFetchers. Once the 114 // The WebUIUserScriptLoader owns these WebUIURLFetchers. Once the
115 // loader is destroyed, all the fetchers will be destroyed. Therefore, 115 // loader is destroyed, all the fetchers will be destroyed. Therefore,
116 // we are sure it is safe to use base::Unretained(this) here. 116 // we are sure it is safe to use base::Unretained(this) here.
117 scoped_ptr<WebUIURLFetcher> fetcher(new WebUIURLFetcher( 117 std::unique_ptr<WebUIURLFetcher> fetcher(new WebUIURLFetcher(
118 browser_context, render_process_id, render_view_id, file.url(), 118 browser_context, render_process_id, render_view_id, file.url(),
119 base::Bind(&WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete, 119 base::Bind(&WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete,
120 base::Unretained(this), &file))); 120 base::Unretained(this), &file)));
121 fetchers_.push_back(std::move(fetcher)); 121 fetchers_.push_back(std::move(fetcher));
122 } 122 }
123 } 123 }
124 } 124 }
125 125
126 void WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete( 126 void WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete(
127 extensions::UserScript::File* script_file, 127 extensions::UserScript::File* script_file,
(...skipping 16 matching lines...) Expand all
144 } 144 }
145 } 145 }
146 146
147 void WebUIUserScriptLoader::OnWebUIURLFetchComplete() { 147 void WebUIUserScriptLoader::OnWebUIURLFetchComplete() {
148 content::BrowserThread::PostTask( 148 content::BrowserThread::PostTask(
149 content::BrowserThread::FILE, FROM_HERE, 149 content::BrowserThread::FILE, FROM_HERE,
150 base::Bind(&SerializeOnFileThread, base::Passed(&user_scripts_cache_), 150 base::Bind(&SerializeOnFileThread, base::Passed(&user_scripts_cache_),
151 scripts_loaded_callback_)); 151 scripts_loaded_callback_));
152 scripts_loaded_callback_.Reset(); 152 scripts_loaded_callback_.Reset();
153 } 153 }
OLDNEW
« no previous file with comments | « extensions/browser/web_ui_user_script_loader.h ('k') | extensions/shell/browser/shell_extensions_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698