Index: content/browser/webui/shared_resources_data_source.cc |
diff --git a/content/browser/webui/shared_resources_data_source.cc b/content/browser/webui/shared_resources_data_source.cc |
index 03721b0c5e1d1d024c234d0ea0cc90f7f2c5a47a..ae9bd9d1b436a0c9c1002640f1fba899206e13fe 100644 |
--- a/content/browser/webui/shared_resources_data_source.cc |
+++ b/content/browser/webui/shared_resources_data_source.cc |
@@ -6,12 +6,14 @@ |
#include <stddef.h> |
+#include "base/bind.h" |
#include "base/containers/hash_tables.h" |
#include "base/files/file_path.h" |
#include "base/logging.h" |
#include "base/memory/ref_counted_memory.h" |
#include "base/strings/string_piece.h" |
#include "base/strings/string_util.h" |
+#include "content/public/browser/browser_thread.h" |
#include "content/public/common/content_client.h" |
#include "content/public/common/url_constants.h" |
#include "ui/base/layout.h" |
@@ -69,6 +71,20 @@ const ResourcesMap& GetResourcesMap() { |
return *resources_map; |
} |
+scoped_refptr<base::RefCountedMemory> GetResourceBytesOnUIThread(int idr) { |
+ if (idr == IDR_WEBUI_CSS_TEXT_DEFAULTS) { |
+ std::string css = webui::GetWebUiCssTextDefaults(); |
+ return base::RefCountedString::TakeString(&css); |
+ } |
+ |
+ if (idr == IDR_WEBUI_CSS_TEXT_DEFAULTS_MD) { |
+ std::string css = webui::GetWebUiCssTextDefaultsMd(); |
+ return base::RefCountedString::TakeString(&css); |
+ } |
+ |
+ return GetContentClient()->GetDataResourceBytes(idr); |
+} |
+ |
} // namespace |
SharedResourcesDataSource::SharedResourcesDataSource() { |
@@ -89,19 +105,10 @@ void SharedResourcesDataSource::StartDataRequest( |
auto it = resources_map.find(path); |
int idr = (it != resources_map.end()) ? it->second : -1; |
DCHECK_NE(-1, idr) << " path: " << path; |
- scoped_refptr<base::RefCountedMemory> bytes; |
- |
- if (idr == IDR_WEBUI_CSS_TEXT_DEFAULTS) { |
- std::string css = webui::GetWebUiCssTextDefaults(); |
- bytes = base::RefCountedString::TakeString(&css); |
- } else if (idr == IDR_WEBUI_CSS_TEXT_DEFAULTS_MD) { |
- std::string css = webui::GetWebUiCssTextDefaultsMd(); |
- bytes = base::RefCountedString::TakeString(&css); |
- } else { |
- bytes = GetContentClient()->GetDataResourceBytes(idr); |
- } |
- callback.Run(bytes.get()); |
+ BrowserThread::PostTaskAndReplyWithResult( |
+ BrowserThread::UI, FROM_HERE, |
+ base::Bind(&GetResourceBytesOnUIThread, idr), callback); |
} |
std::string SharedResourcesDataSource::GetMimeType( |