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

Side by Side Diff: app/resource_bundle_linux.cc

Issue 338027: Modify DataPacks so they can return RefCountedStaticMemory objects. (Closed)
Patch Set: Rewrite GetStaticMemory Created 11 years, 1 month 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 | « no previous file | app/resource_bundle_mac.mm » ('j') | base/data_pack.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "app/app_paths.h" 9 #include "app/app_paths.h"
10 #include "app/gfx/font.h" 10 #include "app/gfx/font.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 theme_data_path = theme_data_path.Append(FILE_PATH_LITERAL("default.pak")); 114 theme_data_path = theme_data_path.Append(FILE_PATH_LITERAL("default.pak"));
115 theme_data_ = new base::DataPack; 115 theme_data_ = new base::DataPack;
116 bool success = theme_data_->Load(theme_data_path); 116 bool success = theme_data_->Load(theme_data_path);
117 DCHECK(success) << "failed to load theme data"; 117 DCHECK(success) << "failed to load theme data";
118 } 118 }
119 119
120 // static 120 // static
121 RefCountedStaticMemory* ResourceBundle::LoadResourceBytes( 121 RefCountedStaticMemory* ResourceBundle::LoadResourceBytes(
122 DataHandle module, int resource_id) { 122 DataHandle module, int resource_id) {
123 DCHECK(module); 123 DCHECK(module);
124 base::StringPiece bytes; 124 return module->GetStaticMemory(resource_id);
125 if (!module->Get(resource_id, &bytes))
126 return NULL;
127
128 return new RefCountedStaticMemory(
129 reinterpret_cast<const unsigned char*>(bytes.data()), bytes.length());
130 } 125 }
131 126
132 base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) { 127 base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) {
133 DCHECK(resources_data_); 128 DCHECK(resources_data_);
134 base::StringPiece data; 129 base::StringPiece data;
135 if (!resources_data_->Get(resource_id, &data)) 130 if (!resources_data_->GetStringPiece(resource_id, &data))
136 return base::StringPiece(); 131 return base::StringPiece();
137 return data; 132 return data;
138 } 133 }
139 134
140 string16 ResourceBundle::GetLocalizedString(int message_id) { 135 string16 ResourceBundle::GetLocalizedString(int message_id) {
141 // If for some reason we were unable to load a resource dll, return an empty 136 // If for some reason we were unable to load a resource dll, return an empty
142 // string (better than crashing). 137 // string (better than crashing).
143 if (!locale_resources_data_) { 138 if (!locale_resources_data_) {
144 LOG(WARNING) << "locale resources are not loaded"; 139 LOG(WARNING) << "locale resources are not loaded";
145 return string16(); 140 return string16();
146 } 141 }
147 142
148 base::StringPiece data; 143 base::StringPiece data;
149 if (!locale_resources_data_->Get(message_id, &data)) { 144 if (!locale_resources_data_->GetStringPiece(message_id, &data)) {
150 // Fall back on the main data pack (shouldn't be any strings here except in 145 // Fall back on the main data pack (shouldn't be any strings here except in
151 // unittests). 146 // unittests).
152 data = GetRawDataResource(message_id); 147 data = GetRawDataResource(message_id);
153 if (data.empty()) { 148 if (data.empty()) {
154 NOTREACHED() << "unable to find resource: " << message_id; 149 NOTREACHED() << "unable to find resource: " << message_id;
155 return string16(); 150 return string16();
156 } 151 }
157 } 152 }
158 153
159 // Data pack encodes strings as UTF16. 154 // Data pack encodes strings as UTF16.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 208 }
214 } 209 }
215 210
216 GdkPixbuf* ResourceBundle::GetPixbufNamed(int resource_id) { 211 GdkPixbuf* ResourceBundle::GetPixbufNamed(int resource_id) {
217 return GetPixbufImpl(resource_id, false); 212 return GetPixbufImpl(resource_id, false);
218 } 213 }
219 214
220 GdkPixbuf* ResourceBundle::GetRTLEnabledPixbufNamed(int resource_id) { 215 GdkPixbuf* ResourceBundle::GetRTLEnabledPixbufNamed(int resource_id) {
221 return GetPixbufImpl(resource_id, true); 216 return GetPixbufImpl(resource_id, true);
222 } 217 }
OLDNEW
« no previous file with comments | « no previous file | app/resource_bundle_mac.mm » ('j') | base/data_pack.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698