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

Side by Side Diff: chrome/common/resource_bundle_mac.mm

Issue 28185: properly initialize resource manager on mac for unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/test/unit/chrome_test_suite.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) 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 "chrome/common/resource_bundle.h" 5 #include "chrome/common/resource_bundle.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/data_pack.h" 10 #include "base/data_pack.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/mac_util.h"
14 #include "base/path_service.h" 15 #include "base/path_service.h"
15 #include "base/string_piece.h" 16 #include "base/string_piece.h"
16 #include "base/string_util.h" 17 #include "base/string_util.h"
17 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/gfx/chrome_font.h" 19 #include "chrome/common/gfx/chrome_font.h"
19 #include "chrome/common/l10n_util.h" 20 #include "chrome/common/l10n_util.h"
20 21
22
21 ResourceBundle::~ResourceBundle() { 23 ResourceBundle::~ResourceBundle() {
22 FreeImages(); 24 FreeImages();
23 25
24 delete locale_resources_data_; 26 delete locale_resources_data_;
25 locale_resources_data_ = NULL; 27 locale_resources_data_ = NULL;
26 delete theme_data_; 28 delete theme_data_;
27 theme_data_ = NULL; 29 theme_data_ = NULL;
28 delete resources_data_; 30 delete resources_data_;
29 resources_data_ = NULL; 31 resources_data_ = NULL;
30 } 32 }
31 33
32 namespace { 34 namespace {
33 35
34 base::DataPack *LoadResourceDataPack(NSString *name) { 36 base::DataPack *LoadResourceDataPack(NSString *name) {
35 base::DataPack *resource_pack = NULL; 37 base::DataPack *resource_pack = NULL;
36 38
39 NSString * const pakExt = @"pak";
Mark Mentovai 2009/02/26 17:44:03 Never put space on both sides of the *.
40
41 // TODO(thomasvl): THIS SUCKS! We need to remove this gate. It's here
42 // because of the unittests, but we have no other way to find our resources.
43 if (!mac_util::AmIBundled()) {
44 FilePath path;
45 PathService::Get(base::DIR_EXE, &path);
46 path = path.AppendASCII("Chromium.app");
47 path = path.AppendASCII("Contents");
48 path = path.AppendASCII("Resources");
49 if ([name isEqual:@"locale"]) {
50 path = path.AppendASCII("English.lproj");
51 }
52 NSString *pakName = [name stringByAppendingPathExtension:pakExt];
53 path = path.Append([pakName fileSystemRepresentation]);
54 resource_pack = new base::DataPack;
55 bool success = resource_pack->Load(path);
56 DCHECK(success) << "failed to load chrome.pak";
Mark Mentovai 2009/02/27 06:07:59 Shoulda caught this before, but this shouldn't har
57 if (!success) {
58 delete resource_pack;
59 resource_pack = NULL;
60 }
61 return resource_pack;
62 }
63
37 NSString *resource_path = [[NSBundle mainBundle] pathForResource:name 64 NSString *resource_path = [[NSBundle mainBundle] pathForResource:name
38 ofType:@"pak"]; 65 ofType:pakExt];
39 if (resource_path) { 66 if (resource_path) {
40 FilePath resources_pak_path([resource_path fileSystemRepresentation]); 67 FilePath resources_pak_path([resource_path fileSystemRepresentation]);
41 resource_pack = new base::DataPack; 68 resource_pack = new base::DataPack;
42 bool success = resource_pack->Load(resources_pak_path); 69 bool success = resource_pack->Load(resources_pak_path);
43 DCHECK(success) << "failed to load chrome.pak"; 70 DCHECK(success) << "failed to load chrome.pak";
Mark Mentovai 2009/02/27 06:07:59 Ditto.
44 if (!success) { 71 if (!success) {
45 delete resource_pack; 72 delete resource_pack;
46 resource_pack = NULL; 73 resource_pack = NULL;
47 } 74 }
48 } 75 }
49 76
50 return resource_pack; 77 return resource_pack;
51 } 78 }
52 79
53 } // namespace 80 } // namespace
54 81
55 void ResourceBundle::LoadResources(const std::wstring& pref_locale) { 82 void ResourceBundle::LoadResources(const std::wstring& pref_locale) {
56 DCHECK(pref_locale.size() == 0) 83 DLOG_IF(WARNING, pref_locale.size() != 0)
57 << "ignoring requested locale in favore of NSBundle's selection"; 84 << "ignoring requested locale in favor of NSBundle's selection";
58 85
59 DCHECK(resources_data_ == NULL) << "resource data already loaded!"; 86 DCHECK(resources_data_ == NULL) << "resource data already loaded!";
60 resources_data_ = LoadResourceDataPack(@"chrome"); 87 resources_data_ = LoadResourceDataPack(@"chrome");
61 DCHECK(resources_data_) << "failed to load chrome.pak"; 88 DCHECK(resources_data_) << "failed to load chrome.pak";
62 89
63 DCHECK(locale_resources_data_ == NULL) << "locale data already loaded!"; 90 DCHECK(locale_resources_data_ == NULL) << "locale data already loaded!";
64 locale_resources_data_ = LoadResourceDataPack(@"locale"); 91 locale_resources_data_ = LoadResourceDataPack(@"locale");
65 DCHECK(locale_resources_data_) << "failed to load locale.pak"; 92 DCHECK(locale_resources_data_) << "failed to load locale.pak";
66 } 93 }
67 94
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 NOTREACHED() << "unable to find resource: " << message_id; 137 NOTREACHED() << "unable to find resource: " << message_id;
111 return std::wstring(); 138 return std::wstring();
112 } 139 }
113 } 140 }
114 141
115 // Data pack encodes strings as UTF16. 142 // Data pack encodes strings as UTF16.
116 string16 msg(reinterpret_cast<const char16*>(data.data()), 143 string16 msg(reinterpret_cast<const char16*>(data.data()),
117 data.length() / 2); 144 data.length() / 2);
118 return UTF16ToWide(msg); 145 return UTF16ToWide(msg);
119 } 146 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/unit/chrome_test_suite.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698