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

Side by Side Diff: chrome/browser/ui/webui/theme_source.cc

Issue 747013003: Various optimizations to reduce the number of temporary allocations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added back calls to c_str that were removed by mistake. Created 6 years 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 | « chrome/browser/ui/prefs/prefs_tab_helper.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/webui/theme_source.h" 5 #include "chrome/browser/ui/webui/theme_source.h"
6 6
7 #include "base/memory/ref_counted_memory.h" 7 #include "base/memory/ref_counted_memory.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/resources_util.h" 11 #include "chrome/browser/resources_util.h"
12 #include "chrome/browser/search/instant_io_context.h" 12 #include "chrome/browser/search/instant_io_context.h"
13 #include "chrome/browser/themes/browser_theme_pack.h"
13 #include "chrome/browser/themes/theme_properties.h" 14 #include "chrome/browser/themes/theme_properties.h"
14 #include "chrome/browser/themes/theme_service.h" 15 #include "chrome/browser/themes/theme_service.h"
15 #include "chrome/browser/themes/theme_service_factory.h" 16 #include "chrome/browser/themes/theme_service_factory.h"
16 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" 17 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
17 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" 18 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
18 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "net/url_request/url_request.h" 21 #include "net/url_request/url_request.h"
21 #include "ui/base/layout.h" 22 #include "ui/base/layout.h"
22 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 107
107 if (uncached_path == kNewTabCSSPath || 108 if (uncached_path == kNewTabCSSPath ||
108 uncached_path == kNewIncognitoTabCSSPath) { 109 uncached_path == kNewIncognitoTabCSSPath) {
109 // We generated and cached this when we initialized the object. We don't 110 // We generated and cached this when we initialized the object. We don't
110 // have to go back to the UI thread to send the data. 111 // have to go back to the UI thread to send the data.
111 return NULL; 112 return NULL;
112 } 113 }
113 114
114 // If it's not a themeable image, we don't need to go to the UI thread. 115 // If it's not a themeable image, we don't need to go to the UI thread.
115 int resource_id = ResourcesUtil::GetThemeResourceId(uncached_path); 116 int resource_id = ResourcesUtil::GetThemeResourceId(uncached_path);
116 if (!ThemeProperties::IsThemeableImage(resource_id)) 117 if (!BrowserThemePack::IsPersistentImageID(resource_id))
117 return NULL; 118 return NULL;
118 119
119 return content::URLDataSource::MessageLoopForRequestPath(path); 120 return content::URLDataSource::MessageLoopForRequestPath(path);
120 } 121 }
121 122
122 bool ThemeSource::ShouldReplaceExistingSource() const { 123 bool ThemeSource::ShouldReplaceExistingSource() const {
123 // We currently get the css_bytes_ in the ThemeSource constructor, so we need 124 // We currently get the css_bytes_ in the ThemeSource constructor, so we need
124 // to recreate the source itself when a theme changes. 125 // to recreate the source itself when a theme changes.
125 return true; 126 return true;
126 } 127 }
127 128
128 bool ThemeSource::ShouldServiceRequest(const net::URLRequest* request) const { 129 bool ThemeSource::ShouldServiceRequest(const net::URLRequest* request) const {
129 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) 130 if (request->url().SchemeIs(chrome::kChromeSearchScheme))
130 return InstantIOContext::ShouldServiceRequest(request); 131 return InstantIOContext::ShouldServiceRequest(request);
131 return URLDataSource::ShouldServiceRequest(request); 132 return URLDataSource::ShouldServiceRequest(request);
132 } 133 }
133 134
134 //////////////////////////////////////////////////////////////////////////////// 135 ////////////////////////////////////////////////////////////////////////////////
135 // ThemeSource, private: 136 // ThemeSource, private:
136 137
137 void ThemeSource::SendThemeBitmap( 138 void ThemeSource::SendThemeBitmap(
138 const content::URLDataSource::GotDataCallback& callback, 139 const content::URLDataSource::GotDataCallback& callback,
139 int resource_id, 140 int resource_id,
140 float scale_factor) { 141 float scale_factor) {
141 ui::ScaleFactor resource_scale_factor = 142 ui::ScaleFactor resource_scale_factor =
142 ui::GetSupportedScaleFactor(scale_factor); 143 ui::GetSupportedScaleFactor(scale_factor);
143 if (ThemeProperties::IsThemeableImage(resource_id)) { 144 if (BrowserThemePack::IsPersistentImageID(resource_id)) {
144 DCHECK_CURRENTLY_ON(BrowserThread::UI); 145 DCHECK_CURRENTLY_ON(BrowserThread::UI);
145 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_); 146 ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
146 DCHECK(tp); 147 DCHECK(tp);
147 148
148 scoped_refptr<base::RefCountedMemory> image_data( 149 scoped_refptr<base::RefCountedMemory> image_data(
149 tp->GetRawData(resource_id, resource_scale_factor)); 150 tp->GetRawData(resource_id, resource_scale_factor));
150 callback.Run(image_data.get()); 151 callback.Run(image_data.get());
151 } else { 152 } else {
152 DCHECK_CURRENTLY_ON(BrowserThread::IO); 153 DCHECK_CURRENTLY_ON(BrowserThread::IO);
153 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 154 const ResourceBundle& rb = ResourceBundle::GetSharedInstance();
154 callback.Run( 155 callback.Run(
155 rb.LoadDataResourceBytesForScale(resource_id, resource_scale_factor)); 156 rb.LoadDataResourceBytesForScale(resource_id, resource_scale_factor));
156 } 157 }
157 } 158 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/prefs/prefs_tab_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698