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

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

Issue 2096433002: Convert prefix search in UserScript code to use base::StartsWith() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/extension_user_script_loader.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 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
128 bool success, 128 bool success,
129 const std::string& data) { 129 const std::string& data) {
130 if (success) { 130 if (success) {
131 // Remove BOM from the content. 131 // Remove BOM from |data|.
132 std::string::size_type index = data.find(base::kUtf8ByteOrderMark); 132 if (base::StartsWith(data, base::kUtf8ByteOrderMark,
133 if (index == 0) 133 base::CompareCase::SENSITIVE)) {
134 script_file->set_content(data.substr(strlen(base::kUtf8ByteOrderMark))); 134 script_file->set_content(data.substr(strlen(base::kUtf8ByteOrderMark)));
135 else 135 } else {
136 script_file->set_content(data); 136 script_file->set_content(data);
137 }
137 } 138 }
138 139
139 ++complete_fetchers_; 140 ++complete_fetchers_;
140 if (complete_fetchers_ == fetchers_.size()) { 141 if (complete_fetchers_ == fetchers_.size()) {
141 complete_fetchers_ = 0; 142 complete_fetchers_ = 0;
142 OnWebUIURLFetchComplete(); 143 OnWebUIURLFetchComplete();
143 fetchers_.clear(); 144 fetchers_.clear();
144 } 145 }
145 } 146 }
146 147
147 void WebUIUserScriptLoader::OnWebUIURLFetchComplete() { 148 void WebUIUserScriptLoader::OnWebUIURLFetchComplete() {
148 content::BrowserThread::PostTask( 149 content::BrowserThread::PostTask(
149 content::BrowserThread::FILE, FROM_HERE, 150 content::BrowserThread::FILE, FROM_HERE,
150 base::Bind(&SerializeOnFileThread, base::Passed(&user_scripts_cache_), 151 base::Bind(&SerializeOnFileThread, base::Passed(&user_scripts_cache_),
151 scripts_loaded_callback_)); 152 scripts_loaded_callback_));
152 scripts_loaded_callback_.Reset(); 153 scripts_loaded_callback_.Reset();
153 } 154 }
OLDNEW
« no previous file with comments | « extensions/browser/extension_user_script_loader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698