summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser_main.cc
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-19 23:44:24 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-19 23:44:24 +0000
commite4bac199faccb0b0e45673d21aa5dae0ea77a787 (patch)
treed3dd7f2422d41b15946002bf582b07f919475046 /chrome/browser/browser_main.cc
parentd22ecba3f4d67e25bd2ea1b04a1c954cc3758929 (diff)
downloadchromium_src-e4bac199faccb0b0e45673d21aa5dae0ea77a787.zip
chromium_src-e4bac199faccb0b0e45673d21aa5dae0ea77a787.tar.gz
chromium_src-e4bac199faccb0b0e45673d21aa5dae0ea77a787.tar.bz2
Cache the generated html for directory listings. This will allow the net resource provider system to return direct pointers into the resources instead of copying.
Review URL: http://codereview.chromium.org/11501 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5729 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_main.cc')
-rw-r--r--chrome/browser/browser_main.cc33
1 files changed, 26 insertions, 7 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 93aa8aa..91973ba 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -11,9 +11,11 @@
#include "base/file_util.h"
#include "base/gfx/vector_canvas.h"
#include "base/histogram.h"
+#include "base/lazy_instance.h"
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/registry.h"
+#include "base/string_piece.h"
#include "base/string_util.h"
#include "base/tracked_objects.h"
#include "base/win_util.h"
@@ -83,11 +85,13 @@ void HandleErrorTestParameters(const CommandLine& command_line) {
}
}
-// This is called indirectly by the network layer to access resources.
-std::string NetResourceProvider(int key) {
- const std::string& data_blob =
- ResourceBundle::GetSharedInstance().GetDataResource(key);
- if (IDR_DIR_HEADER_HTML == key) {
+// The net module doesn't have access to this HTML or the strings that need to
+// be localized. The Chrome locale will never change while we're running, so
+// it's safe to have a static string that we always return a pointer into.
+// This allows us to have the ResourceProvider return a pointer into the actual
+// resource (via a StringPiece), instead of always copying resources.
+struct LazyDirectoryListerCacher {
+ LazyDirectoryListerCacher() {
DictionaryValue value;
value.SetString(L"header",
l10n_util::GetString(IDS_DIRECTORY_LISTING_HEADER));
@@ -99,10 +103,25 @@ std::string NetResourceProvider(int key) {
l10n_util::GetString(IDS_DIRECTORY_LISTING_SIZE));
value.SetString(L"headerDateModified",
l10n_util::GetString(IDS_DIRECTORY_LISTING_DATE_MODIFIED));
- return jstemplate_builder::GetTemplateHtml(data_blob, &value, "t");
+ html_data = jstemplate_builder::GetTemplateHtml(
+ ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_DIR_HEADER_HTML),
+ &value,
+ "t");
}
- return data_blob;
+ std::string html_data;
+};
+
+base::LazyInstance<LazyDirectoryListerCacher> lazy_dir_lister(
+ base::LINKER_INITIALIZED);
+
+// This is called indirectly by the network layer to access resources.
+std::string NetResourceProvider(int key) {
+ if (IDR_DIR_HEADER_HTML == key)
+ return lazy_dir_lister.Pointer()->html_data;
+
+ return ResourceBundle::GetSharedInstance().GetDataResource(key);
}
// Displays a warning message if the user is running chrome on windows 2000.