summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-15 07:23:59 +0000
committertony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-15 07:23:59 +0000
commite1cb0e9d4c4eb173d9ee99d9ba3cf5fbc3d38b6a (patch)
tree52421316ad00b2a4717c3952953ea643454a6b2f /app
parent4344db043bab42ea807a0f7f2cab386d23ab3607 (diff)
downloadchromium_src-e1cb0e9d4c4eb173d9ee99d9ba3cf5fbc3d38b6a.zip
chromium_src-e1cb0e9d4c4eb173d9ee99d9ba3cf5fbc3d38b6a.tar.gz
chromium_src-e1cb0e9d4c4eb173d9ee99d9ba3cf5fbc3d38b6a.tar.bz2
Load resources.pak, which should be located next to the chrome
binary. resources.pak will contain all the files we currently have in the resources subdirectory (it currently only has net-internals files). On Linux, this is an eager load (before the zygote), but on Mac and Win, this is lazily loaded as needed. This isn't being used yet, just adding the necessary plumbing for now. BUG=42770 Review URL: http://codereview.chromium.org/2755006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49772 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r--app/resource_bundle.cc32
-rw-r--r--app/resource_bundle.h27
-rw-r--r--app/resource_bundle_posix.cc8
-rw-r--r--app/resource_bundle_win.cc11
4 files changed, 76 insertions, 2 deletions
diff --git a/app/resource_bundle.cc b/app/resource_bundle.cc
index 9288341..dcf7fa8 100644
--- a/app/resource_bundle.cc
+++ b/app/resource_bundle.cc
@@ -4,8 +4,10 @@
#include "app/resource_bundle.h"
+#include "base/data_pack.h"
#include "base/logging.h"
#include "base/string_piece.h"
+#include "build/build_config.h"
#include "gfx/codec/png_codec.h"
#include "gfx/font.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -52,6 +54,12 @@ std::string ResourceBundle::ReloadSharedInstance(
}
/* static */
+void ResourceBundle::AddDataPackToSharedInstance(const FilePath& path) {
+ DCHECK(g_shared_instance_ != NULL) << "ResourceBundle not initialized";
+ g_shared_instance_->data_packs_.push_back(new LoadedDataPack(path));
+}
+
+/* static */
void ResourceBundle::CleanupSharedInstance() {
if (g_shared_instance_) {
delete g_shared_instance_;
@@ -186,3 +194,27 @@ const gfx::Font& ResourceBundle::GetFont(FontStyle style) {
return *base_font_;
}
}
+
+// LoadedDataPack implementation
+ResourceBundle::LoadedDataPack::LoadedDataPack(const FilePath& path)
+ : path_(path) {
+ // On unicies, we preload data packs so background updates don't cause us to
+ // load the wrong data.
+#if defined(OS_POSIX) && !defined(OS_MACOSX)
+ Load();
+#endif
+}
+
+void ResourceBundle::LoadedDataPack::Load() {
+ DCHECK(!data_pack_.get());
+ data_pack_.reset(new base::DataPack);
+ bool success = data_pack_->Load(path_);
+ CHECK(success) << "Failed to load " << path_.value();
+}
+
+bool ResourceBundle::LoadedDataPack::GetStringPiece(int resource_id,
+ base::StringPiece* data) {
+ if (!data_pack_.get())
+ Load();
+ return data_pack_->GetStringPiece(static_cast<uint32>(resource_id), data);
+}
diff --git a/app/resource_bundle.h b/app/resource_bundle.h
index f4cff17..3a3e617 100644
--- a/app/resource_bundle.h
+++ b/app/resource_bundle.h
@@ -13,6 +13,7 @@
#include <map>
#include <string>
+#include <vector>
#include "base/basictypes.h"
#include "base/file_path.h"
@@ -21,11 +22,9 @@
#include "base/scoped_ptr.h"
#include "base/string16.h"
-#if defined(USE_BASE_DATA_PACK)
namespace base {
class DataPack;
}
-#endif
#if defined(USE_X11)
typedef struct _GdkPixbuf GdkPixbuf;
#endif
@@ -78,6 +77,12 @@ class ResourceBundle {
// the UI thread.
static std::string ReloadSharedInstance(const std::wstring& pref_locale);
+ // Registers additional data pack files with the global ResourceBundle. When
+ // looking for a DataResource, we will search these files after searching the
+ // main module. This method is not thread safe! You should call it
+ // immediately after calling InitSharedInstance.
+ static void AddDataPackToSharedInstance(const FilePath& path);
+
// Delete the ResourceBundle for this process if it exists.
static void CleanupSharedInstance();
@@ -151,6 +156,21 @@ class ResourceBundle {
static const SkColor toolbar_separator_color;
private:
+ // Helper class for managing data packs.
+ class LoadedDataPack {
+ public:
+ LoadedDataPack(const FilePath& path);
+ bool GetStringPiece(int resource_id, base::StringPiece* data);
+
+ private:
+ void Load();
+
+ scoped_ptr<base::DataPack> data_pack_;
+ FilePath path_;
+
+ DISALLOW_COPY_AND_ASSIGN(LoadedDataPack);
+ };
+
// We define a DataHandle typedef to abstract across how data is stored
// across platforms.
#if defined(OS_WIN)
@@ -217,6 +237,9 @@ class ResourceBundle {
DataHandle resources_data_;
DataHandle locale_resources_data_;
+ // References to extra data packs loaded via AddDataPackToSharedInstance.
+ std::vector<LoadedDataPack*> data_packs_;
+
// Cached images. The ResourceBundle caches all retrieved bitmaps and keeps
// ownership of the pointers.
typedef std::map<int, SkBitmap*> SkImageMap;
diff --git a/app/resource_bundle_posix.cc b/app/resource_bundle_posix.cc
index 1246087..f8d5333 100644
--- a/app/resource_bundle_posix.cc
+++ b/app/resource_bundle_posix.cc
@@ -7,6 +7,7 @@
#include "app/l10n_util.h"
#include "base/data_pack.h"
#include "base/logging.h"
+#include "base/stl_util-inl.h"
#include "base/string16.h"
#include "base/string_piece.h"
#include "gfx/font.h"
@@ -31,6 +32,8 @@ ResourceBundle::~ResourceBundle() {
FreeGdkPixBufs();
#endif
UnloadLocaleResources();
+ STLDeleteContainerPointers(data_packs_.begin(),
+ data_packs_.end());
delete resources_data_;
resources_data_ = NULL;
}
@@ -52,6 +55,11 @@ base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) {
base::StringPiece data;
if (!resources_data_->GetStringPiece(resource_id, &data)) {
if (!locale_resources_data_->GetStringPiece(resource_id, &data)) {
+ for (size_t i = 0; i < data_packs_.size(); ++i) {
+ if (data_packs_[i]->GetStringPiece(resource_id, &data))
+ return data;
+ }
+
return base::StringPiece();
}
}
diff --git a/app/resource_bundle_win.cc b/app/resource_bundle_win.cc
index 6161e71..38040dd 100644
--- a/app/resource_bundle_win.cc
+++ b/app/resource_bundle_win.cc
@@ -8,11 +8,13 @@
#include "app/app_paths.h"
#include "app/l10n_util.h"
+#include "base/data_pack.h"
#include "base/debug_util.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/resource_util.h"
+#include "base/stl_util-inl.h"
#include "base/string_piece.h"
#include "base/win_util.h"
#include "gfx/font.h"
@@ -32,6 +34,8 @@ DWORD GetDataDllLoadFlags() {
ResourceBundle::~ResourceBundle() {
FreeImages();
UnloadLocaleResources();
+ STLDeleteContainerPointers(data_packs_.begin(),
+ data_packs_.end());
resources_data_ = NULL;
}
@@ -113,6 +117,13 @@ base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) {
&data_size)) {
return base::StringPiece(static_cast<const char*>(data_ptr), data_size);
}
+
+ base::StringPiece data;
+ for (size_t i = 0; i < data_packs_.size(); ++i) {
+ if (data_packs_[i]->GetStringPiece(resource_id, &data))
+ return data;
+ }
+
return base::StringPiece();
}