diff options
-rw-r--r-- | app/resource_bundle.cc | 2 | ||||
-rw-r--r-- | app/resource_bundle.h | 2 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.cc | 7 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.h | 5 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_theme_source.cc | 21 |
5 files changed, 28 insertions, 9 deletions
diff --git a/app/resource_bundle.cc b/app/resource_bundle.cc index 2b60c78..e3174d8 100644 --- a/app/resource_bundle.cc +++ b/app/resource_bundle.cc @@ -87,7 +87,7 @@ std::string ResourceBundle::GetDataResource(int resource_id) { } RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( - int resource_id) { + int resource_id) const { return LoadResourceBytes(resources_data_, resource_id); } diff --git a/app/resource_bundle.h b/app/resource_bundle.h index e608ccd..5c3afb2 100644 --- a/app/resource_bundle.h +++ b/app/resource_bundle.h @@ -87,7 +87,7 @@ class ResourceBundle { // Loads the raw bytes of a data resource into |bytes|, // without doing any processing or interpretation of // the resource. Returns whether we successfully read the resource. - RefCountedStaticMemory* LoadDataResourceBytes(int resource_id); + RefCountedStaticMemory* LoadDataResourceBytes(int resource_id) const; // Return the contents of a file in a string given the resource id. // This will copy the data from the resource and return it as a string. diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc index 7f598a7..6bc9e97 100644 --- a/chrome/browser/browser_theme_provider.cc +++ b/chrome/browser/browser_theme_provider.cc @@ -223,7 +223,6 @@ bool HasThemeableImage(int themeable_image_id) { } - class WriteImagesToDiskTask : public Task { public: WriteImagesToDiskTask( @@ -270,10 +269,16 @@ class WriteImagesToDiskTask : public Task { } // namespace +bool BrowserThemeProvider::IsThemeableImage(int resource_id) { + return HasThemeableImage(resource_id); +} + BrowserThemeProvider::BrowserThemeProvider() : rb_(ResourceBundle::GetSharedInstance()), profile_(NULL), process_images_(false) { + // Initialize the themeable image map so we can use it on other threads. + HasThemeableImage(0); resource_names_[IDR_THEME_FRAME] = "theme_frame"; resource_names_[IDR_THEME_FRAME_INACTIVE] = "theme_frame_inactive"; resource_names_[IDR_THEME_FRAME_OVERLAY] = "theme_frame_overlay"; diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h index 228cf53..04117b4 100644 --- a/chrome/browser/browser_theme_provider.h +++ b/chrome/browser/browser_theme_provider.h @@ -104,7 +104,10 @@ class BrowserThemeProvider : public NonThreadSafe, static const char* kDefaultThemeID; - public: + // Returns true if the image is themeable. Safe to call on any thread. + static bool IsThemeableImage(int resource_id); + + BrowserThemeProvider(); virtual ~BrowserThemeProvider(); diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.cc b/chrome/browser/dom_ui/dom_ui_theme_source.cc index 3640c40..9fa4f25 100644 --- a/chrome/browser/dom_ui/dom_ui_theme_source.cc +++ b/chrome/browser/dom_ui/dom_ui_theme_source.cc @@ -79,6 +79,11 @@ MessageLoop* DOMUIThemeSource::MessageLoopForRequestPath( return NULL; } + // If it's not a themeable image, we don't need to go to the UI thread. + int resource_id = ThemeResourcesUtil::GetId(uncached_path); + if (!BrowserThemeProvider::IsThemeableImage(resource_id)) + return NULL; + return DataSource::MessageLoopForRequestPath(path); } @@ -86,10 +91,16 @@ MessageLoop* DOMUIThemeSource::MessageLoopForRequestPath( // DOMUIThemeSource, private: void DOMUIThemeSource::SendThemeBitmap(int request_id, int resource_id) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - ThemeProvider* tp = profile_->GetThemeProvider(); - DCHECK(tp); + if (BrowserThemeProvider::IsThemeableImage(resource_id)) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + ThemeProvider* tp = profile_->GetThemeProvider(); + DCHECK(tp); - scoped_refptr<RefCountedMemory> image_data(tp->GetRawData(resource_id)); - SendResponse(request_id, image_data); + scoped_refptr<RefCountedMemory> image_data(tp->GetRawData(resource_id)); + SendResponse(request_id, image_data); + } else { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + SendResponse(request_id, rb.LoadDataResourceBytes(resource_id)); + } } |