Chromium Code Reviews| Index: content/browser/webui/web_ui_data_source_impl.cc |
| diff --git a/content/browser/webui/web_ui_data_source_impl.cc b/content/browser/webui/web_ui_data_source_impl.cc |
| index 2d6d24a916d5f43ec1a34d25881678357dd0c934..7907fa202ec850628f081123f0b7ecdf1b69530e 100644 |
| --- a/content/browser/webui/web_ui_data_source_impl.cc |
| +++ b/content/browser/webui/web_ui_data_source_impl.cc |
| @@ -212,6 +212,22 @@ void WebUIDataSourceImpl::DisableI18nAndUseGzipForAllPaths() { |
| use_gzip_for_all_paths_ = true; |
| } |
| +void WebUIDataSourceImpl::FinalizeReplacements() { |
|
Dan Beam
2016/12/03 02:25:28
nit: EnsureLoadTimeDataDefaultsAdded() ?
dschuyler
2016/12/03 02:44:57
Done.
|
| + // After this function is called, make no further changes to |replacements_|. |
| + if (!add_load_time_data_defaults_) |
| + return; |
| + |
| + add_load_time_data_defaults_ = false; |
| + std::string locale = GetContentClient()->browser()->GetApplicationLocale(); |
| + base::DictionaryValue defaults; |
| + webui::SetLoadTimeDataDefaults(locale, &defaults); |
| + AddLocalizedStrings(defaults); |
| +} |
| + |
| +const ui::TemplateReplacements* WebUIDataSourceImpl::GetReplacements() const { |
| + return &replacements_; |
| +} |
| + |
| std::string WebUIDataSourceImpl::GetSource() const { |
| return source_name_; |
| } |
| @@ -247,13 +263,10 @@ void WebUIDataSourceImpl::StartDataRequest( |
| return; |
| } |
| - if (add_load_time_data_defaults_) { |
| - std::string locale = GetContentClient()->browser()->GetApplicationLocale(); |
| - base::DictionaryValue defaults; |
| - webui::SetLoadTimeDataDefaults(locale, &defaults); |
| - AddLocalizedStrings(defaults); |
| - add_load_time_data_defaults_ = false; |
| - } |
| + // The replacements are initiallized in the main thread and then used in the |
| + // IO thread. The map is safe to read from multiple threads as long as no |
| + // futher changes are made to it. |
| + FinalizeReplacements(); |
| if (!json_path_.empty() && path == json_path_) { |
| SendLocalizedStringsAsJSON(callback); |
| @@ -270,18 +283,6 @@ void WebUIDataSourceImpl::StartDataRequest( |
| DCHECK_NE(resource_id, -1); |
| scoped_refptr<base::RefCountedMemory> response( |
| GetContentClient()->GetDataResourceBytes(resource_id)); |
| - |
| - // TODO(dschuyler): improve filtering of which resource to run template |
| - // expansion upon. TODO(dbeam): make a streaming filter that works on gzipped |
| - // content. |
| - if (response.get() && GetMimeType(path) == "text/html" && |
| - !source()->IsGzipped(path)) { |
| - std::string replaced = ui::ReplaceTemplateExpressions( |
| - base::StringPiece(response->front_as<char>(), response->size()), |
| - replacements_); |
| - response = base::RefCountedString::TakeString(&replaced); |
| - } |
| - |
| callback.Run(response.get()); |
| } |