summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-20 00:28:34 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-20 00:28:34 +0000
commit2dea04cdfc632bfe29d7ffb436827ea2726ec092 (patch)
tree519bcd708837a17fa5fb947451bc1e65e95443bf /net
parentc86288eec35b7718bdd01e7faefeb837b6bd8903 (diff)
downloadchromium_src-2dea04cdfc632bfe29d7ffb436827ea2726ec092.zip
chromium_src-2dea04cdfc632bfe29d7ffb436827ea2726ec092.tar.gz
chromium_src-2dea04cdfc632bfe29d7ffb436827ea2726ec092.tar.bz2
Make the net resource interface use StringPiece instead of std::string. This means we can point directly into the resource in the binary, instead of copying. This makes sense for the TLD data, which doesn't need to be copied around.
Review URL: http://codereview.chromium.org/11296 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5735 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/net_module.cc4
-rw-r--r--net/base/net_module.h5
-rw-r--r--net/base/net_util.cc5
-rw-r--r--net/base/registry_controlled_domain.cc2
-rw-r--r--net/url_request/url_request_unittest.cc3
5 files changed, 11 insertions, 8 deletions
diff --git a/net/base/net_module.cc b/net/base/net_module.cc
index d54a0a4..7c3f9c1 100644
--- a/net/base/net_module.cc
+++ b/net/base/net_module.cc
@@ -14,10 +14,10 @@ void NetModule::SetResourceProvider(ResourceProvider func) {
}
// static
-std::string NetModule::GetResource(int key) {
+StringPiece NetModule::GetResource(int key) {
// avoid thread safety issues by copying provider address to a local var
ResourceProvider func = resource_provider;
- return func ? func(key) : std::string();
+ return func ? func(key) : StringPiece();
}
} // namespace net
diff --git a/net/base/net_module.h b/net/base/net_module.h
index ef309ff..e527b9f 100644
--- a/net/base/net_module.h
+++ b/net/base/net_module.h
@@ -8,6 +8,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/string_piece.h"
namespace net {
@@ -20,7 +21,7 @@ namespace net {
//
class NetModule {
public:
- typedef std::string (*ResourceProvider)(int key);
+ typedef StringPiece (*ResourceProvider)(int key);
// Set the function to call when the net module needs resources
static void SetResourceProvider(ResourceProvider func);
@@ -28,7 +29,7 @@ class NetModule {
// Call the resource provider (if one exists) to get the specified resource.
// Returns an empty string if the resource does not exist or if there is no
// resource provider.
- static std::string GetResource(int key);
+ static StringPiece GetResource(int key);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(NetModule);
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 05419fb..1617d85 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -800,11 +800,12 @@ std::string CanonicalizeHost(const std::wstring& host, bool* is_ip_address) {
#ifdef OS_WIN
std::string GetDirectoryListingHeader(const std::string& title) {
- std::string result = NetModule::GetResource(IDR_DIR_HEADER_HTML);
- if (result.empty()) {
+ static const StringPiece header(NetModule::GetResource(IDR_DIR_HEADER_HTML));
+ if (header.empty()) {
NOTREACHED() << "expected resource not found";
}
+ std::string result(header.data(), header.size());
result.append("<script>start(");
string_escape::JavascriptDoubleQuote(title, true, &result);
result.append(");</script>\n");
diff --git a/net/base/registry_controlled_domain.cc b/net/base/registry_controlled_domain.cc
index 3f4f024..f98a3f3 100644
--- a/net/base/registry_controlled_domain.cc
+++ b/net/base/registry_controlled_domain.cc
@@ -296,7 +296,7 @@ void RegistryControlledDomainService::UseDomainData(const std::string& data) {
}
void RegistryControlledDomainService::Init() {
- domain_data_ = NetModule::GetResource(IDR_EFFECTIVE_TLD_NAMES);
+ domain_data_ = NetModule::GetResource(IDR_EFFECTIVE_TLD_NAMES).as_string();
if (domain_data_.empty()) {
// The resource file isn't present for some unit tests, for example. Fall
// back to a tiny, basic list of rules in that case.
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index b6720aa..9b560ae 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -16,6 +16,7 @@
#include "base/path_service.h"
#include "base/platform_test.h"
#include "base/process_util.h"
+#include "base/string_piece.h"
#include "base/string_util.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
@@ -52,7 +53,7 @@ class TestURLRequest : public URLRequest {
}
};
-std::string TestNetResourceProvider(int key) {
+StringPiece TestNetResourceProvider(int key) {
return "header";
}