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

Side by Side Diff: app/resource_bundle.cc

Issue 2865010: Load net-internals resources from resources.pak. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: mini installer 2 Created 10 years, 6 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 unified diff | Download patch
« no previous file with comments | « app/resource_bundle.h ('k') | base/data_pack.h » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/resource_bundle.h" 5 #include "app/resource_bundle.h"
6 6
7 #include "base/data_pack.h" 7 #include "base/data_pack.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_piece.h" 9 #include "base/string_piece.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), &bitmap)) { 98 if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), &bitmap)) {
99 NOTREACHED() << "Unable to decode theme image resource " << resource_id; 99 NOTREACHED() << "Unable to decode theme image resource " << resource_id;
100 return NULL; 100 return NULL;
101 } 101 }
102 102
103 return new SkBitmap(bitmap); 103 return new SkBitmap(bitmap);
104 } 104 }
105 105
106 RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( 106 RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes(
107 int resource_id) const { 107 int resource_id) const {
108 return LoadResourceBytes(resources_data_, resource_id); 108 RefCountedStaticMemory* bytes =
109 LoadResourceBytes(resources_data_, resource_id);
110
111 // Check all our additional data packs for the resources if it wasn't loaded
112 // from our main source.
113 for (std::vector<LoadedDataPack*>::const_iterator it = data_packs_.begin();
114 !bytes && it != data_packs_.end(); ++it) {
115 bytes = (*it)->GetStaticMemory(resource_id);
116 }
117
118 return bytes;
109 } 119 }
110 120
111 SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) { 121 SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) {
112 // Check to see if we already have the Skia image in the cache. 122 // Check to see if we already have the Skia image in the cache.
113 { 123 {
114 AutoLock lock_scope(lock_); 124 AutoLock lock_scope(lock_);
115 SkImageMap::const_iterator found = skia_images_.find(resource_id); 125 SkImageMap::const_iterator found = skia_images_.find(resource_id);
116 if (found != skia_images_.end()) 126 if (found != skia_images_.end())
117 return found->second; 127 return found->second;
118 } 128 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 case LargeFont: 201 case LargeFont:
192 return *large_font_; 202 return *large_font_;
193 default: 203 default:
194 return *base_font_; 204 return *base_font_;
195 } 205 }
196 } 206 }
197 207
198 // LoadedDataPack implementation 208 // LoadedDataPack implementation
199 ResourceBundle::LoadedDataPack::LoadedDataPack(const FilePath& path) 209 ResourceBundle::LoadedDataPack::LoadedDataPack(const FilePath& path)
200 : path_(path) { 210 : path_(path) {
201 // On unicies, we preload data packs so background updates don't cause us to 211 // Always preload the data packs so we can maintain constness.
202 // load the wrong data.
203 #if defined(OS_POSIX) && !defined(OS_MACOSX)
204 Load(); 212 Load();
205 #endif
206 } 213 }
207 214
208 void ResourceBundle::LoadedDataPack::Load() { 215 void ResourceBundle::LoadedDataPack::Load() {
209 DCHECK(!data_pack_.get()); 216 DCHECK(!data_pack_.get());
210 data_pack_.reset(new base::DataPack); 217 data_pack_.reset(new base::DataPack);
211 bool success = data_pack_->Load(path_); 218 bool success = data_pack_->Load(path_);
212 CHECK(success) << "Failed to load " << path_.value(); 219 CHECK(success) << "Failed to load " << path_.value();
213 } 220 }
214 221
215 bool ResourceBundle::LoadedDataPack::GetStringPiece(int resource_id, 222 bool ResourceBundle::LoadedDataPack::GetStringPiece(
216 base::StringPiece* data) { 223 int resource_id, base::StringPiece* data) const {
217 if (!data_pack_.get())
218 Load();
219 return data_pack_->GetStringPiece(static_cast<uint32>(resource_id), data); 224 return data_pack_->GetStringPiece(static_cast<uint32>(resource_id), data);
220 } 225 }
226
227 RefCountedStaticMemory* ResourceBundle::LoadedDataPack::GetStaticMemory(
228 int resource_id) const {
229 return data_pack_->GetStaticMemory(resource_id);
230 }
OLDNEW
« no previous file with comments | « app/resource_bundle.h ('k') | base/data_pack.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698