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

Unified Diff: chrome/browser/ui/webui/theme_source.cc

Issue 2381093002: Move GetNewTabCSS() caching off the startup path. (Closed)
Patch Set: Remove unneeded include. Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/theme_source.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/theme_source.cc
diff --git a/chrome/browser/ui/webui/theme_source.cc b/chrome/browser/ui/webui/theme_source.cc
index 8e5de32c452c9535570c46d3c463ab3d632b134e..4234c4cf97971684fa5336e6b85b4177671c83c4 100644
--- a/chrome/browser/ui/webui/theme_source.cc
+++ b/chrome/browser/ui/webui/theme_source.cc
@@ -62,18 +62,22 @@ void ProcessResourceOnUIThread(int resource_id,
scale, data);
}
+base::RefCountedMemory* GetNewTabCSSOnUIThread(Profile* profile) {
Evan Stade 2016/10/03 20:16:59 nit: style guide says NewTabCssOnUiThread
Alexei Svitkine (slow) 2016/10/03 21:02:45 Done - changed the other function in this file too
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+
+ NTPResourceCache::WindowType type =
+ NTPResourceCache::GetWindowType(profile, nullptr);
+ return NTPResourceCacheFactory::GetForProfile(profile)->GetNewTabCSS(type);
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
// ThemeSource, public:
ThemeSource::ThemeSource(Profile* profile)
- : profile_(profile->GetOriginalProfile()) {
- // NB: it's important that this is |profile| and not |profile_|.
- NTPResourceCache::WindowType win_type =
- NTPResourceCache::GetWindowType(profile, nullptr);
- css_bytes_ =
- NTPResourceCacheFactory::GetForProfile(profile)->GetNewTabCSS(win_type);
+ : profile_(profile),
+ original_profile_(profile->GetOriginalProfile()) {
Evan Stade 2016/10/03 20:16:59 why not just inline profile_->GetOriginalProfile w
Alexei Svitkine (slow) 2016/10/03 21:02:45 Done.
}
ThemeSource::~ThemeSource() {
@@ -95,7 +99,11 @@ void ThemeSource::StartDataRequest(
if (IsNewTabCssPath(parsed_path)) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
- callback.Run(css_bytes_.get());
+ // NB: it's important that this is |profile_| and not |original_profile_|.
+ content::BrowserThread::PostTaskAndReplyWithResult(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&GetNewTabCSSOnUIThread, profile_),
+ callback);
return;
}
@@ -175,12 +183,6 @@ base::MessageLoop* ThemeSource::MessageLoopForRequestPath(
content::URLDataSource::MessageLoopForRequestPath(path) : nullptr;
}
-bool ThemeSource::ShouldReplaceExistingSource() const {
- // We currently get the css_bytes_ in the ThemeSource constructor, so we need
- // to recreate the source itself when a theme changes.
- return true;
-}
-
bool ThemeSource::ShouldServiceRequest(const net::URLRequest* request) const {
return request->url().SchemeIs(chrome::kChromeSearchScheme) ?
InstantIOContext::ShouldServiceRequest(request) :
@@ -198,7 +200,7 @@ void ThemeSource::SendThemeBitmap(
if (BrowserThemePack::IsPersistentImageID(resource_id)) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
scoped_refptr<base::RefCountedMemory> image_data(
- ThemeService::GetThemeProviderForProfile(profile_).GetRawData(
+ ThemeService::GetThemeProviderForProfile(original_profile_).GetRawData(
resource_id, scale_factor));
callback.Run(image_data.get());
} else {
@@ -216,7 +218,7 @@ void ThemeSource::SendThemeImage(
if (BrowserThemePack::IsPersistentImageID(resource_id)) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
const ui::ThemeProvider& tp =
- ThemeService::GetThemeProviderForProfile(profile_);
+ ThemeService::GetThemeProviderForProfile(original_profile_);
ProcessImageOnUIThread(*tp.GetImageSkiaNamed(resource_id), scale, data);
callback.Run(data.get());
} else {
« no previous file with comments | « chrome/browser/ui/webui/theme_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698