0

Remove redundant mapping of net errors to strings.

The new list does not have the leading "net::ERR_", to slightly reduce
the size of net when compiled.  This reduces the size of libcronet.so
by about 8k, with symbols stripped.

Also add a function to get network error strings without the leading,
"net::" as a number of consumers were removing it with duplicated code.

This CL slight breaks NetLog loading functionality - loading old logs
in new versions  will result in error codes missing the leading "ERR_",
and the other direction results in error codes having an extra leading
"ERR_".

BUG=399025

Review URL: https://codereview.chromium.org/432553003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288065 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
mmenke@chromium.org
2014-08-07 16:12:06 +00:00
parent 7e29ff1b73
commit 3030374e34
16 changed files with 62 additions and 59 deletions

@ -87,13 +87,7 @@ void ToggleHelpBox(Browser* browser) {
// |error_code| on the current page.
bool WARN_UNUSED_RESULT IsDisplayingNetError(Browser* browser,
net::Error error_code) {
// Get the error as a string, and remove the leading "net::", which is not
// included on error pages.
std::string error_string(net::ErrorToString(error_code));
DCHECK(StartsWithASCII(error_string, "net::", true));
error_string.erase(0, 5);
return IsDisplayingText(browser, error_string);
return IsDisplayingText(browser, net::ErrorToShortString(error_code));
}
// Checks that the local error page is being displayed, without remotely

@ -762,11 +762,8 @@ void WebViewGuest::DidFailProvisionalLoad(
const GURL& validated_url,
int error_code,
const base::string16& error_description) {
// Translate the |error_code| into an error string.
std::string error_type(net::ErrorToString(error_code));
DCHECK(StartsWithASCII(error_type, "net::", true));
error_type.erase(0, 5);
LoadAbort(!render_frame_host->GetParent(), validated_url, error_type);
LoadAbort(!render_frame_host->GetParent(), validated_url,
net::ErrorToShortString(error_code));
}
void WebViewGuest::DidStartProvisionalLoadForFrame(
@ -969,10 +966,8 @@ void WebViewGuest::NavigateGuest(const std::string& src) {
!url.SchemeIs(url::kAboutScheme)) ||
url.SchemeIs(url::kJavaScriptScheme);
if (scheme_is_blocked || !url.is_valid()) {
std::string error_type(net::ErrorToString(net::ERR_ABORTED));
DCHECK(StartsWithASCII(error_type, "net::", true));
error_type.erase(0, 5);
LoadAbort(true /* is_top_level */, url, error_type);
LoadAbort(true /* is_top_level */, url,
net::ErrorToShortString(net::ERR_ABORTED));
return;
}

@ -348,10 +348,7 @@ function areValidConstants(receivedConstants) {
* @return {string} The name of the given error.
*/
function netErrorToString(netError) {
var str = getKeyWithValue(NetError, netError);
if (str == '?')
return str;
return 'ERR_' + str;
return getKeyWithValue(NetError, netError);
}
/**

@ -45,7 +45,7 @@ var SourceEntry = (function() {
if (netErrorCode) {
// Ignore error code caused by not finding an entry in the cache.
if (logEntry.type != EventType.HTTP_CACHE_OPEN_ENTRY ||
netErrorCode != NetError.FAILED) {
netErrorCode != NetError.ERR_FAILED) {
this.isError_ = true;
}
}

@ -579,11 +579,7 @@ void LocalizedError::GetStrings(int error_code,
base::string16 error_string;
if (error_domain == net::kErrorDomain) {
// Non-internationalized error string, for debugging Chrome itself.
std::string ascii_error_string = net::ErrorToString(error_code);
// Remove the leading "net::" from the returned string.
DCHECK(StartsWithASCII(ascii_error_string, "net::", true));
ascii_error_string.erase(0, 5);
error_string = base::ASCIIToUTF16(ascii_error_string);
error_string = base::ASCIIToUTF16(net::ErrorToShortString(error_code));
} else if (error_domain == chrome_common_net::kDnsProbeErrorDomain) {
std::string ascii_error_string =
chrome_common_net::DnsProbeStatusToString(error_code);

@ -215,7 +215,7 @@ TEST_F('NetInternalsTest', 'netInternalsDnsViewSuccess', function() {
NetInternalsTest.switchToView('dns');
var taskQueue = new NetInternalsTest.TaskQueue(true);
taskQueue.addTask(new AddCacheEntryTask(
'somewhere.com', '1.2.3.4', 0, false));
'somewhere.com', '1.2.3.4', 0, false));
taskQueue.addTask(new ClearCacheTask());
taskQueue.addTask(new WaitForEntryDestructionTask('somewhere.com'));
taskQueue.run(true);
@ -228,7 +228,7 @@ TEST_F('NetInternalsTest', 'netInternalsDnsViewFail', function() {
NetInternalsTest.switchToView('dns');
var taskQueue = new NetInternalsTest.TaskQueue(true);
taskQueue.addTask(new AddCacheEntryTask(
'nowhere.com', '', NetError.NAME_NOT_RESOLVED, false));
'nowhere.com', '', NetError.ERR_NAME_NOT_RESOLVED, false));
taskQueue.addTask(new ClearCacheTask());
taskQueue.addTask(new WaitForEntryDestructionTask('nowhere.com'));
taskQueue.run(true);
@ -241,7 +241,7 @@ TEST_F('NetInternalsTest', 'netInternalsDnsViewExpired', function() {
NetInternalsTest.switchToView('dns');
var taskQueue = new NetInternalsTest.TaskQueue(true);
taskQueue.addTask(new AddCacheEntryTask(
'somewhere.com', '1.2.3.4', 0, true));
'somewhere.com', '1.2.3.4', 0, true));
taskQueue.addTask(new ClearCacheTask());
taskQueue.addTask(new WaitForEntryDestructionTask('somewhere.com'));
taskQueue.run(true);
@ -255,9 +255,9 @@ TEST_F('NetInternalsTest', 'netInternalsDnsViewAddTwoTwice', function() {
var taskQueue = new NetInternalsTest.TaskQueue(true);
for (var i = 0; i < 2; ++i) {
taskQueue.addTask(new AddCacheEntryTask(
'somewhere.com', '1.2.3.4', 0, false));
'somewhere.com', '1.2.3.4', 0, false));
taskQueue.addTask(new AddCacheEntryTask(
'nowhere.com', '', NetError.NAME_NOT_RESOLVED, true));
'nowhere.com', '', NetError.ERR_NAME_NOT_RESOLVED, true));
taskQueue.addTask(new ClearCacheTask());
taskQueue.addTask(new WaitForEntryDestructionTask('somewhere.com'));
taskQueue.addTask(new WaitForEntryDestructionTask('nowhere.com'));
@ -275,7 +275,7 @@ TEST_F('NetInternalsTest', 'netInternalsDnsViewIncognitoClears', function() {
var taskQueue = new NetInternalsTest.TaskQueue(true);
taskQueue.addTask(new NetInternalsTest.CreateIncognitoBrowserTask());
taskQueue.addTask(new AddCacheEntryTask(
'somewhere.com', '1.2.3.4', 0, true));
'somewhere.com', '1.2.3.4', 0, true));
taskQueue.addTask(NetInternalsTest.getCloseIncognitoBrowserTask());
taskQueue.addTask(new WaitForEntryDestructionTask('somewhere.com'));
taskQueue.run(true);

@ -173,9 +173,9 @@ TEST_F('NetInternalsTest', 'netInternalsTestViewPassTwice', function() {
*/
TEST_F('NetInternalsTest', 'netInternalsTestViewFailTwice', function() {
var taskQueue = new NetInternalsTest.TaskQueue(true);
taskQueue.addTask(new RunTestSuiteTask(NetError.UNSAFE_PORT,
taskQueue.addTask(new RunTestSuiteTask(NetError.ERR_UNSAFE_PORT,
'http://127.0.0.1:7/'));
taskQueue.addTask(new RunTestSuiteTask(NetError.UNSAFE_PORT,
taskQueue.addTask(new RunTestSuiteTask(NetError.ERR_UNSAFE_PORT,
'http://127.0.0.1:7/'));
taskQueue.run();
});

@ -278,9 +278,10 @@ bool CertificateImporterImpl::ParseServerOrCaCertificate(
success = target_nssdb_->ImportCACerts(cert_list, trust, &failures);
if (!failures.empty()) {
std::string error_string = net::ErrorToString(failures[0].net_error);
ONC_LOG_ERROR(
base::StringPrintf("Error ( %s ) importing %s certificate",
net::ErrorToString(failures[0].net_error),
error_string.c_str(),
cert_type.c_str()));
return false;
}
@ -329,9 +330,10 @@ bool CertificateImporterImpl::ParseClientCertificate(
int import_result = target_nssdb_->ImportFromPKCS12(
module.get(), decoded_pkcs12, base::string16(), false, &imported_certs);
if (import_result != net::OK) {
std::string error_string = net::ErrorToString(import_result);
ONC_LOG_ERROR(
base::StringPrintf("Unable to import client certificate (error %s)",
net::ErrorToString(import_result)));
error_string.c_str()));
return false;
}

@ -252,10 +252,11 @@ static jstring GetErrorString(JNIEnv* env,
URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer);
int error_code = request->error_code();
char buffer[200];
std::string error_string = net::ErrorToString(error_code);
snprintf(buffer,
sizeof(buffer),
"System error: %s(%d)",
net::ErrorToString(error_code),
error_string.c_str(),
error_code);
return ConvertUTF8ToJavaString(env, buffer).Release();
}

@ -4,6 +4,7 @@
#include "content/child/socket_stream_dispatcher.h"
#include <string>
#include <vector>
#include "base/bind.h"
@ -46,7 +47,7 @@ class IPCWebSocketStreamHandleBridge : public WebSocketStreamHandleBridge {
void OnSentData(int amount_sent);
void OnReceivedData(const std::vector<char>& data);
void OnClosed();
void OnFailed(int error_code, const char* error_msg);
void OnFailed(int error_code, const std::string& error_msg);
private:
virtual ~IPCWebSocketStreamHandleBridge();
@ -163,7 +164,7 @@ void IPCWebSocketStreamHandleBridge::OnClosed() {
}
void IPCWebSocketStreamHandleBridge::OnFailed(int error_code,
const char* error_msg) {
const std::string& error_msg) {
DVLOG(1) << "Bridge #" << socket_id_ << " OnFailed (error_code=" << error_code
<< ")";
if (delegate_)

@ -221,7 +221,7 @@ void BluetoothSocketWin::DoConnect(
scoped_socket->AdoptConnectedSocket(socket_fd, net::IPEndPoint());
if (net_result != net::OK) {
error_callback.Run("Error connecting to socket: " +
std::string(net::ErrorToString(net_result)));
net::ErrorToString(net_result));
closesocket(socket_fd);
return;
}

@ -24,19 +24,36 @@ namespace net {
const char kErrorDomain[] = "net";
const char* ErrorToString(int error) {
if (error == 0)
return "net::OK";
std::string ErrorToString(int error) {
return "net::" + ErrorToShortString(error);
}
std::string ErrorToShortString(int error) {
if (error == 0)
return "OK";
const char* error_string;
switch (error) {
#define NET_ERROR(label, value) \
case ERR_ ## label: \
return "net::" STRINGIZE_NO_EXPANSION(ERR_ ## label);
error_string = # label; \
break;
#include "net/base/net_error_list.h"
#undef NET_ERROR
default:
return "net::<unknown>";
NOTREACHED();
error_string = "<unknown>";
}
return std::string("ERR_") + error_string;
}
bool IsCertificateError(int error) {
// Certificate errors are negative integers from net::ERR_CERT_BEGIN
// (inclusive) to net::ERR_CERT_END (exclusive) in *decreasing* order.
// ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN is currently an exception to this
// rule.
return (error <= ERR_CERT_BEGIN && error > ERR_CERT_END) ||
(error == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN);
}
std::vector<int> GetAllErrorCodesForUma() {

@ -5,6 +5,7 @@
#ifndef NET_BASE_NET_ERRORS_H__
#define NET_BASE_NET_ERRORS_H__
#include <string>
#include <vector>
#include "base/basictypes.h"
@ -30,17 +31,13 @@ enum Error {
};
// Returns a textual representation of the error code for logging purposes.
NET_EXPORT const char* ErrorToString(int error);
NET_EXPORT std::string ErrorToString(int error);
// Same as above, but leaves off the leading "net::".
NET_EXPORT std::string ErrorToShortString(int error);
// Returns true if |error| is a certificate error code.
inline bool IsCertificateError(int error) {
// Certificate errors are negative integers from net::ERR_CERT_BEGIN
// (inclusive) to net::ERR_CERT_END (exclusive) in *decreasing* order.
// ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN is currently an exception to this
// rule.
return (error <= ERR_CERT_BEGIN && error > ERR_CERT_END) ||
(error == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN);
}
NET_EXPORT bool IsCertificateError(int error);
// Map system error code to Error.
NET_EXPORT Error MapSystemError(int os_error);

@ -13,6 +13,7 @@
#include "base/values.h"
#include "net/base/address_family.h"
#include "net/base/load_states.h"
#include "net/base/net_errors.h"
#include "net/quic/quic_protocol.h"
#include "net/quic/quic_utils.h"
@ -120,7 +121,7 @@ base::DictionaryValue* NetLogLogger::GetConstants() {
base::DictionaryValue* dict = new base::DictionaryValue();
#define NET_ERROR(label, value) \
dict->SetInteger(# label, static_cast<int>(value));
dict->SetInteger(ErrorToShortString(value), static_cast<int>(value));
#include "net/base/net_error_list.h"
#undef NET_ERROR

@ -290,8 +290,9 @@ int ProofVerifierChromium::Job::DoVerifyCertComplete(int result) {
#endif
if (result != OK) {
std::string error_string = ErrorToString(result);
error_details_ = StringPrintf("Failed to verify certificate chain: %s",
ErrorToString(result));
error_string.c_str());
DLOG(WARNING) << error_details_;
}
@ -301,8 +302,8 @@ int ProofVerifierChromium::Job::DoVerifyCertComplete(int result) {
}
bool ProofVerifierChromium::Job::VerifySignature(const string& signed_data,
const string& signature,
const string& cert) {
const string& signature,
const string& cert) {
StringPiece spki;
if (!asn1::ExtractSPKIFromDERCert(cert, &spki)) {
DLOG(WARNING) << "ExtractSPKIFromDERCert failed";

@ -487,7 +487,8 @@ void GDig::OnResolveComplete(unsigned entry_index,
static_cast<int>(resolve_time.InMilliseconds()),
replay_log_[entry_index].domain_name.c_str(), val);
if (val != OK) {
printf("%s", ErrorToString(val));
std::string error_string = ErrorToString(val);
printf("%s", error_string.c_str());
} else {
for (size_t i = 0; i < address_list->size(); ++i) {
if (i != 0)