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

Side by Side Diff: chrome/browser/themes/browser_theme_pack.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: 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
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/themes/browser_theme_pack.h" 5 #include "chrome/browser/themes/browser_theme_pack.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // supposed to be changeable by the user. 93 // supposed to be changeable by the user.
94 const char* key; 94 const char* key;
95 }; 95 };
96 96
97 // IDR_* resource names change whenever new resources are added; use persistent 97 // IDR_* resource names change whenever new resources are added; use persistent
98 // IDs when storing to a cached pack. 98 // IDs when storing to a cached pack.
99 // 99 //
100 // TODO(erg): The cocoa port is the last user of the IDR_*_[HP] variants. These 100 // TODO(erg): The cocoa port is the last user of the IDR_*_[HP] variants. These
101 // should be removed once the cocoa port no longer uses them. 101 // should be removed once the cocoa port no longer uses them.
102 PersistingImagesTable kPersistingImages[] = { 102 PersistingImagesTable kPersistingImages[] = {
103 { PRS_THEME_FRAME, IDR_THEME_FRAME, 103 { PRS_THEME_FRAME, IDR_THEME_FRAME,
Sigurður Ásgeirsson 2014/11/25 01:37:01 it should be easy to mandate these be in-order and
104 "theme_frame" }, 104 "theme_frame" },
105 { PRS_THEME_FRAME_INACTIVE, IDR_THEME_FRAME_INACTIVE, 105 { PRS_THEME_FRAME_INACTIVE, IDR_THEME_FRAME_INACTIVE,
106 "theme_frame_inactive" }, 106 "theme_frame_inactive" },
107 { PRS_THEME_FRAME_INCOGNITO, IDR_THEME_FRAME_INCOGNITO, 107 { PRS_THEME_FRAME_INCOGNITO, IDR_THEME_FRAME_INCOGNITO,
108 "theme_frame_incognito" }, 108 "theme_frame_incognito" },
109 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, IDR_THEME_FRAME_INCOGNITO_INACTIVE, 109 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, IDR_THEME_FRAME_INCOGNITO_INACTIVE,
110 "theme_frame_incognito_inactive" }, 110 "theme_frame_incognito_inactive" },
111 { PRS_THEME_TOOLBAR, IDR_THEME_TOOLBAR, 111 { PRS_THEME_TOOLBAR, IDR_THEME_TOOLBAR,
112 "theme_toolbar" }, 112 "theme_toolbar" },
113 { PRS_THEME_TAB_BACKGROUND, IDR_THEME_TAB_BACKGROUND, 113 { PRS_THEME_TAB_BACKGROUND, IDR_THEME_TAB_BACKGROUND,
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 result->clear(); 786 result->clear();
787 for (size_t i = 0; i < kPersistingImagesLength; ++i) 787 for (size_t i = 0; i < kPersistingImagesLength; ++i)
788 result->insert(kPersistingImages[i].idr_id); 788 result->insert(kPersistingImages[i].idr_id);
789 789
790 #if defined(USE_ASH) && !defined(OS_CHROMEOS) 790 #if defined(USE_ASH) && !defined(OS_CHROMEOS)
791 for (size_t i = 0; i < kPersistingImagesDesktopAuraLength; ++i) 791 for (size_t i = 0; i < kPersistingImagesDesktopAuraLength; ++i)
792 result->insert(kPersistingImagesDesktopAura[i].idr_id); 792 result->insert(kPersistingImagesDesktopAura[i].idr_id);
793 #endif 793 #endif
794 } 794 }
795 795
796 // static
797 bool BrowserThemePack::FindThemeableImageIDRs(int id) {
798 for (size_t i = 0; i < kPersistingImagesLength; ++i)
799 if (kPersistingImages[i].idr_id == id)
800 return true;
801
802 #if defined(USE_ASH) && !defined(OS_CHROMEOS)
803 for (size_t i = 0; i < kPersistingImagesDesktopAuraLength; ++i)
804 if (kPersistingImagesDesktopAura[i].idr_id == id)
805 return true;
806 #endif
807
808 return false;
809 }
810
796 bool BrowserThemePack::WriteToDisk(const base::FilePath& path) const { 811 bool BrowserThemePack::WriteToDisk(const base::FilePath& path) const {
797 // Add resources for each of the property arrays. 812 // Add resources for each of the property arrays.
798 RawDataForWriting resources; 813 RawDataForWriting resources;
799 resources[kHeaderID] = base::StringPiece( 814 resources[kHeaderID] = base::StringPiece(
800 reinterpret_cast<const char*>(header_), sizeof(BrowserThemePackHeader)); 815 reinterpret_cast<const char*>(header_), sizeof(BrowserThemePackHeader));
801 resources[kTintsID] = base::StringPiece( 816 resources[kTintsID] = base::StringPiece(
802 reinterpret_cast<const char*>(tints_), 817 reinterpret_cast<const char*>(tints_),
803 sizeof(TintEntry[kTintTableLength])); 818 sizeof(TintEntry[kTintTableLength]));
804 resources[kColorsID] = base::StringPiece( 819 resources[kColorsID] = base::StringPiece(
805 reinterpret_cast<const char*>(colors_), 820 reinterpret_cast<const char*>(colors_),
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 false, 1644 false,
1630 &bitmap_data)) { 1645 &bitmap_data)) {
1631 NOTREACHED() << "Unable to encode theme image for prs_id=" 1646 NOTREACHED() << "Unable to encode theme image for prs_id="
1632 << prs_id << " for scale_factor=" << scale_factors_[i]; 1647 << prs_id << " for scale_factor=" << scale_factors_[i];
1633 break; 1648 break;
1634 } 1649 }
1635 image_memory_[scaled_raw_id] = 1650 image_memory_[scaled_raw_id] =
1636 base::RefCountedBytes::TakeVector(&bitmap_data); 1651 base::RefCountedBytes::TakeVector(&bitmap_data);
1637 } 1652 }
1638 } 1653 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698