| OLD | NEW |
| 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" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 SendThemeBitmap(callback, resource_id, scale); | 154 SendThemeBitmap(callback, resource_id, scale); |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 std::string ThemeSource::GetMimeType(const std::string& path) const { | 158 std::string ThemeSource::GetMimeType(const std::string& path) const { |
| 159 std::string parsed_path; | 159 std::string parsed_path; |
| 160 webui::ParsePathAndScale(GetThemeUrl(path), &parsed_path, nullptr); | 160 webui::ParsePathAndScale(GetThemeUrl(path), &parsed_path, nullptr); |
| 161 return IsNewTabCssPath(parsed_path) ? "text/css" : "image/png"; | 161 return IsNewTabCssPath(parsed_path) ? "text/css" : "image/png"; |
| 162 } | 162 } |
| 163 | 163 |
| 164 base::MessageLoop* ThemeSource::MessageLoopForRequestPath( | 164 scoped_refptr<base::SingleThreadTaskRunner> |
| 165 const std::string& path) const { | 165 ThemeSource::TaskRunnerForRequestPath(const std::string& path) const { |
| 166 std::string parsed_path; | 166 std::string parsed_path; |
| 167 webui::ParsePathAndScale(GetThemeUrl(path), &parsed_path, nullptr); | 167 webui::ParsePathAndScale(GetThemeUrl(path), &parsed_path, nullptr); |
| 168 | 168 |
| 169 if (IsNewTabCssPath(parsed_path)) { | 169 if (IsNewTabCssPath(parsed_path)) { |
| 170 // We generated and cached this when we initialized the object. We don't | 170 // We generated and cached this when we initialized the object. We don't |
| 171 // have to go back to the UI thread to send the data. | 171 // have to go back to the UI thread to send the data. |
| 172 return nullptr; | 172 return nullptr; |
| 173 } | 173 } |
| 174 | 174 |
| 175 // If it's not a themeable image, we don't need to go to the UI thread. | 175 // If it's not a themeable image, we don't need to go to the UI thread. |
| 176 int resource_id = ResourcesUtil::GetThemeResourceId(parsed_path); | 176 int resource_id = ResourcesUtil::GetThemeResourceId(parsed_path); |
| 177 return BrowserThemePack::IsPersistentImageID(resource_id) ? | 177 return BrowserThemePack::IsPersistentImageID(resource_id) |
| 178 content::URLDataSource::MessageLoopForRequestPath(path) : nullptr; | 178 ? content::URLDataSource::TaskRunnerForRequestPath(path) |
| 179 : nullptr; |
| 179 } | 180 } |
| 180 | 181 |
| 181 bool ThemeSource::ShouldServiceRequest(const net::URLRequest* request) const { | 182 bool ThemeSource::ShouldServiceRequest(const net::URLRequest* request) const { |
| 182 return request->url().SchemeIs(chrome::kChromeSearchScheme) ? | 183 return request->url().SchemeIs(chrome::kChromeSearchScheme) ? |
| 183 InstantIOContext::ShouldServiceRequest(request) : | 184 InstantIOContext::ShouldServiceRequest(request) : |
| 184 URLDataSource::ShouldServiceRequest(request); | 185 URLDataSource::ShouldServiceRequest(request); |
| 185 } | 186 } |
| 186 | 187 |
| 187 //////////////////////////////////////////////////////////////////////////////// | 188 //////////////////////////////////////////////////////////////////////////////// |
| 188 // ThemeSource, private: | 189 // ThemeSource, private: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 219 } else { | 220 } else { |
| 220 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 221 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 221 // Fetching image data in ResourceBundle should happen on the UI thread. See | 222 // Fetching image data in ResourceBundle should happen on the UI thread. See |
| 222 // crbug.com/449277 | 223 // crbug.com/449277 |
| 223 content::BrowserThread::PostTaskAndReply( | 224 content::BrowserThread::PostTaskAndReply( |
| 224 content::BrowserThread::UI, FROM_HERE, | 225 content::BrowserThread::UI, FROM_HERE, |
| 225 base::Bind(&ProcessResourceOnUiThread, resource_id, scale, data), | 226 base::Bind(&ProcessResourceOnUiThread, resource_id, scale, data), |
| 226 base::Bind(callback, data)); | 227 base::Bind(callback, data)); |
| 227 } | 228 } |
| 228 } | 229 } |
| OLD | NEW |