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

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

Issue 2231353002: Make FileReader return ownership of the string content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 4 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/web_ui_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 <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"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 base::Bind(&WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete, 120 base::Bind(&WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete,
121 base::Unretained(this), &file))); 121 base::Unretained(this), &file)));
122 fetchers_.push_back(std::move(fetcher)); 122 fetchers_.push_back(std::move(fetcher));
123 } 123 }
124 } 124 }
125 } 125 }
126 126
127 void WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete( 127 void WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete(
128 extensions::UserScript::File* script_file, 128 extensions::UserScript::File* script_file,
129 bool success, 129 bool success,
130 const std::string& data) { 130 std::unique_ptr<std::string> data) {
131 if (success) { 131 if (success) {
132 // Remove BOM from |data|. 132 // Remove BOM from |data|.
133 if (base::StartsWith(data, base::kUtf8ByteOrderMark, 133 if (base::StartsWith(*data, base::kUtf8ByteOrderMark,
134 base::CompareCase::SENSITIVE)) { 134 base::CompareCase::SENSITIVE)) {
135 script_file->set_content(data.substr(strlen(base::kUtf8ByteOrderMark))); 135 script_file->set_content(data->substr(strlen(base::kUtf8ByteOrderMark)));
136 } else { 136 } else {
137 script_file->set_content(data); 137 // TODO(lazyboy): Script files should take ownership of |data|, i.e. the
138 // content of the script.
139 script_file->set_content(*data);
138 } 140 }
139 } 141 }
140 142
141 ++complete_fetchers_; 143 ++complete_fetchers_;
142 if (complete_fetchers_ == fetchers_.size()) { 144 if (complete_fetchers_ == fetchers_.size()) {
143 complete_fetchers_ = 0; 145 complete_fetchers_ = 0;
144 OnWebUIURLFetchComplete(); 146 OnWebUIURLFetchComplete();
145 fetchers_.clear(); 147 fetchers_.clear();
146 } 148 }
147 } 149 }
148 150
149 void WebUIUserScriptLoader::OnWebUIURLFetchComplete() { 151 void WebUIUserScriptLoader::OnWebUIURLFetchComplete() {
150 content::BrowserThread::PostTask( 152 content::BrowserThread::PostTask(
151 content::BrowserThread::FILE, FROM_HERE, 153 content::BrowserThread::FILE, FROM_HERE,
152 base::Bind(&SerializeOnFileThread, base::Passed(&user_scripts_cache_), 154 base::Bind(&SerializeOnFileThread, base::Passed(&user_scripts_cache_),
153 scripts_loaded_callback_)); 155 scripts_loaded_callback_));
154 scripts_loaded_callback_.Reset(); 156 scripts_loaded_callback_.Reset();
155 } 157 }
OLDNEW
« no previous file with comments | « extensions/browser/web_ui_user_script_loader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698