Skip to content

Commit

Permalink
Cleanup: Pass std::string as const reference from components/
Browse files Browse the repository at this point in the history
Passing std::string by reference can prevent extra copying of object.

BUG=367418
TEST=
R=blundell@chromium.org,jochen@chromium.org,sdefresne@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#351023}
  • Loading branch information
k15tfu authored and Commit bot committed Sep 28, 2015
1 parent 96e79b2 commit 939799a
Show file tree
Hide file tree
Showing 34 changed files with 63 additions and 60 deletions.
2 changes: 1 addition & 1 deletion components/cdm/renderer/widevine_key_systems.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using media::SupportedCodecs;
namespace cdm {

// Return |name|'s parent key system.
static std::string GetDirectParentName(std::string name) {
static std::string GetDirectParentName(const std::string& name) {
size_t last_period = name.find_last_of('.');
DCHECK_GT(last_period, 0u);
return name.substr(0u, last_period);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ class GetSTHResponseHandler : public net::URLRequestInterceptor {
return job;
}

void set_response_body(std::string response_body) {
void set_response_body(const std::string& response_body) {
response_body_ = response_body;
}

void set_response_headers(std::string response_headers) {
void set_response_headers(const std::string& response_headers) {
response_headers_ = response_headers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class DataReductionProxyProtocolTest : public testing::Test {
}

// Returns the key to the |ProxyRetryInfoMap|.
std::string GetProxyKey(std::string proxy) {
std::string GetProxyKey(const std::string& proxy) {
net::ProxyServer proxy_server = net::ProxyServer::FromURI(
proxy, net::ProxyServer::SCHEME_HTTP);
if (!proxy_server.is_valid())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ TEST_F(DataReductionProxyConfigTest,
CheckSecureProxyCheckOnIPChange("OK", SUCCEEDED_PROXY_ENABLED, false, false);
}

std::string GetRetryMapKeyFromOrigin(std::string origin) {
std::string GetRetryMapKeyFromOrigin(const std::string& origin) {
// The retry map has the scheme prefix for https but not for http.
return origin;
}
Expand Down
6 changes: 4 additions & 2 deletions components/dom_distiller/core/dom_distiller_store_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ class FakeSyncChangeProcessor : public syncer::SyncChangeProcessor {
EntryMap* model_;
};

ArticleEntry CreateEntry(std::string entry_id, std::string page_url1,
std::string page_url2, std::string page_url3) {
ArticleEntry CreateEntry(const std::string& entry_id,
const std::string& page_url1,
const std::string& page_url2,
const std::string& page_url3) {
ArticleEntry entry;
entry.set_entry_id(entry_id);
if (!page_url1.empty()) {
Expand Down
4 changes: 2 additions & 2 deletions components/dom_distiller/core/url_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ TEST(DomDistillerUrlUtilsTest, TestGetValueForKeyInUrlPathQuery) {
EXPECT_EQ("foo", GetValueForKeyInUrlPathQuery(valid_url_two_keys, "key"));
}

std::string ThroughDistiller(std::string url) {
std::string ThroughDistiller(const std::string& url) {
return GetOriginalUrlFromDistillerUrl(
GetDistillerViewUrlFromUrl(kDomDistillerScheme, GURL(url))).spec();
}

std::string GetOriginalUrlFromDistillerUrl(std::string url) {
std::string GetOriginalUrlFromDistillerUrl(const std::string& url) {
return GetOriginalUrlFromDistillerUrl(GURL(url)).spec();
}

Expand Down
4 changes: 2 additions & 2 deletions components/gcm_driver/gcm_account_tracker_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ namespace {
const char kAccountId1[] = "account_1";
const char kAccountId2[] = "account_2";

std::string AccountKeyToObfuscatedId(const std::string email) {
std::string AccountKeyToObfuscatedId(const std::string& email) {
return "obfid-" + email;
}

std::string GetValidTokenInfoResponse(const std::string account_key) {
std::string GetValidTokenInfoResponse(const std::string& account_key) {
return std::string("{ \"id\": \"") + AccountKeyToObfuscatedId(account_key) +
"\" }";
}
Expand Down
3 changes: 1 addition & 2 deletions components/invalidation/impl/gcm_network_channel_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ class GCMNetworkChannelTest
last_invalidator_state_ = invalidator_state;
}

void OnIncomingMessage(std::string incoming_message) {
}
void OnIncomingMessage(std::string /* incoming_message */) {}

GCMNetworkChannel* network_channel() {
return gcm_network_channel_.get();
Expand Down
2 changes: 1 addition & 1 deletion components/metrics/cloned_install_detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void ClonedInstallDetector::CheckForClonedInstall(
}

void ClonedInstallDetector::SaveMachineId(PrefService* local_state,
std::string raw_id) {
const std::string& raw_id) {
if (raw_id.empty()) {
LogMachineIdState(ID_GENERATION_FAILED);
local_state->ClearPref(prefs::kMetricsMachineId);
Expand Down
2 changes: 1 addition & 1 deletion components/metrics/cloned_install_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ClonedInstallDetector {
// Converts raw_id into a 24-bit hash and stores the hash in |local_state|.
// |raw_id| is not a const ref because it's passed from a cross-thread post
// task.
void SaveMachineId(PrefService* local_state, std::string raw_id);
void SaveMachineId(PrefService* local_state, const std::string& raw_id);

scoped_refptr<MachineIdProvider> raw_id_provider_;
base::WeakPtrFactory<ClonedInstallDetector> weak_ptr_factory_;
Expand Down
2 changes: 1 addition & 1 deletion components/network_hints/renderer/dns_prefetch_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class DnsQueue {
// Returns true for success, false for failure (nothing written).
PushResult Push(const char* source, const size_t length);

PushResult Push(std::string source) {
PushResult Push(const std::string& source) {
return Push(source.c_str(), source.length());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,8 @@ class LoginDatabaseMigrationTest : public testing::TestWithParam<int> {
// Returns an empty vector on failure. Otherwise returns values in the column
// |column_name| of the logins table. The order of the
// returned rows is well-defined.
template <class T> std::vector<T> GetValues(std::string column_name) {
template <class T>
std::vector<T> GetValues(const std::string& column_name) {
sql::Connection db;
std::vector<T> results;
if (!db.Open(database_path_))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void BluetoothLowEnergyConnectionFinder::RestartDiscoverySessionWhenReady() {
}

BluetoothDevice* BluetoothLowEnergyConnectionFinder::GetDevice(
std::string device_address) {
const std::string& device_address) {
// It's not possible to simply use
// |adapter_->GetDevice(GetRemoteDeviceAddress())| to find the device with MAC
// address |GetRemoteDeviceAddress()|. For paired devices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class BluetoothLowEnergyConnectionFinder
void InvokeCallbackAsync();

// Returns the device with |device_address|.
device::BluetoothDevice* GetDevice(std::string device_address);
device::BluetoothDevice* GetDevice(const std::string& device_address);

// The remote BLE device being searched. It maybe empty, in this case the
// remote device should advertise |remote_service_uuid_| and
Expand Down
3 changes: 2 additions & 1 deletion components/search_engines/default_search_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ void SetPolicy(user_prefs::TestingPrefServiceSyncable* prefs,
prefs->SetManagedPref(kDefaultSearchProviderData, entry.release());
}

scoped_ptr<TemplateURLData> GenerateDummyTemplateURLData(std::string type) {
scoped_ptr<TemplateURLData> GenerateDummyTemplateURLData(
const std::string& type) {
scoped_ptr<TemplateURLData> data(new TemplateURLData());
data->SetShortName(base::UTF8ToUTF16(std::string(type).append("name")));
data->SetKeyword(base::UTF8ToUTF16(std::string(type).append("key")));
Expand Down
9 changes: 4 additions & 5 deletions components/search_engines/template_url_parser_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using base::ASCIIToUTF16;
// occurrence of value_str_ in its value.
class ParamFilterImpl : public TemplateURLParser::ParameterFilter {
public:
ParamFilterImpl(std::string name_str, std::string value_str);
ParamFilterImpl(const std::string& name_str, const std::string& value_str);
~ParamFilterImpl() override;

bool KeepParameter(const std::string& key, const std::string& value) override;
Expand All @@ -32,10 +32,9 @@ class ParamFilterImpl : public TemplateURLParser::ParameterFilter {
DISALLOW_COPY_AND_ASSIGN(ParamFilterImpl);
};

ParamFilterImpl::ParamFilterImpl(std::string name_str, std::string value_str)
: name_str_(name_str),
value_str_(value_str) {
}
ParamFilterImpl::ParamFilterImpl(const std::string& name_str,
const std::string& value_str)
: name_str_(name_str), value_str_(value_str) {}

ParamFilterImpl::~ParamFilterImpl() {
}
Expand Down
5 changes: 3 additions & 2 deletions components/signin/core/browser/about_signin_internals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,12 @@ void AboutSigninInternals::OnTokenRemoved(
NotifyObservers();
}

void AboutSigninInternals::OnRefreshTokenReceived(std::string status) {
void AboutSigninInternals::OnRefreshTokenReceived(const std::string& status) {
NotifySigninValueChanged(REFRESH_TOKEN_RECEIVED, status);
}

void AboutSigninInternals::OnAuthenticationResultReceived(std::string status) {
void AboutSigninInternals::OnAuthenticationResultReceived(
const std::string& status) {
NotifySigninValueChanged(AUTHENTICATION_RESULT_RECEIVED, status);
}

Expand Down
4 changes: 2 additions & 2 deletions components/signin/core/browser/about_signin_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class AboutSigninInternals

void Initialize(SigninClient* client);

void OnRefreshTokenReceived(std::string status);
void OnAuthenticationResultReceived(std::string status);
void OnRefreshTokenReceived(const std::string& status);
void OnAuthenticationResultReceived(const std::string& status);

// KeyedService implementation.
void Shutdown() override;
Expand Down
2 changes: 1 addition & 1 deletion components/signin/core/browser/account_fetcher_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void AccountFetcherService::EnableNetworkFetches() {
// If there are accounts in |pending_user_info_fetches_|, they were deemed
// invalid after being loaded from prefs and need to be fetched now instead of
// waiting after the timer.
for (std::string account_id : pending_user_info_fetches_)
for (const std::string& account_id : pending_user_info_fetches_)
StartFetchingUserInfo(account_id);
pending_user_info_fetches_.clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,31 @@ enum TrackingEventType {
REMOVED,
};

std::string AccountIdToEmail(const std::string account_id) {
std::string AccountIdToEmail(const std::string& account_id) {
return account_id + "@gmail.com";
}

std::string AccountIdToGaiaId(const std::string account_id) {
std::string AccountIdToGaiaId(const std::string& account_id) {
return "gaia-" + account_id;
}

std::string AccountIdToFullName(const std::string account_id) {
std::string AccountIdToFullName(const std::string& account_id) {
return "full-name-" + account_id;
}

std::string AccountIdToGivenName(const std::string account_id) {
std::string AccountIdToGivenName(const std::string& account_id) {
return "given-name-" + account_id;
}

std::string AccountIdToLocale(const std::string account_id) {
std::string AccountIdToLocale(const std::string& account_id) {
return "locale-" + account_id;
}

std::string AccountIdToPictureURL(const std::string account_id) {
std::string AccountIdToPictureURL(const std::string& account_id) {
return "picture_url-" + account_id;
}

void CheckAccountDetails(const std::string account_id,
void CheckAccountDetails(const std::string& account_id,
const AccountInfo& info) {
EXPECT_EQ(account_id, info.account_id);
EXPECT_EQ(AccountIdToGaiaId(account_id), info.gaia);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ State GetProcessState() {
return state;
}

bool CheckFlag(std::string command_switch, State min_state) {
bool CheckFlag(const std::string& command_switch, State min_state) {
// Individiual flag settings take precedence.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(command_switch))
return true;
Expand Down
2 changes: 1 addition & 1 deletion components/sync_driver/device_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ base::DictionaryValue* DeviceInfo::ToValue() {
return value;
}

void DeviceInfo::set_public_id(std::string id) {
void DeviceInfo::set_public_id(const std::string& id) {
public_id_ = id;
}

Expand Down
2 changes: 1 addition & 1 deletion components/sync_driver/device_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class DeviceInfo {
// not unique enough so the user can be tracked. Exposing |guid|
// would lead to a stable unique id for a device which can potentially
// be used for tracking.
void set_public_id(std::string id);
void set_public_id(const std::string& id);

// Converts the |DeviceInfo| values to a JS friendly DictionaryValue,
// which extension APIs can expose to third party apps.
Expand Down
4 changes: 2 additions & 2 deletions components/sync_driver/tab_node_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const int TabNodePool::kInvalidTabNodeID = -1;
TabNodePool::~TabNodePool() {}

// Static
std::string TabNodePool::TabIdToTag(
const std::string machine_tag, int tab_node_id) {
std::string TabNodePool::TabIdToTag(const std::string& machine_tag,
int tab_node_id) {
return base::StringPrintf("%s %d", machine_tag.c_str(), tab_node_id);
}

Expand Down
2 changes: 1 addition & 1 deletion components/sync_driver/tab_node_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class TabNodePool {
static const int kInvalidTabNodeID;

// Build a sync tag from tab_node_id.
static std::string TabIdToTag(const std::string machine_tag,
static std::string TabIdToTag(const std::string& machine_tag,
int tab_node_id);

// Returns the tab_node_id for the next free tab node. If none are available,
Expand Down
12 changes: 6 additions & 6 deletions components/test_runner/test_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
void SetXSSAuditorEnabled(bool enabled);
void SetAllowUniversalAccessFromFileURLs(bool allow);
void SetAllowFileAccessFromFileURLs(bool allow);
void OverridePreference(const std::string key, v8::Local<v8::Value> value);
void OverridePreference(const std::string& key, v8::Local<v8::Value> value);
void SetAcceptLanguages(const std::string& accept_languages);
void SetPluginsEnabled(bool enabled);
void DumpEditingCallbacks();
Expand Down Expand Up @@ -292,7 +292,7 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
void CopyImageAtAndCapturePixelsAsyncThen(int x,
int y,
v8::Local<v8::Function> callback);
void SetCustomTextOutput(std::string output);
void SetCustomTextOutput(const std::string& output);
void SetViewSourceForFrame(const std::string& name, bool enabled);
void SetBluetoothMockDataSet(const std::string& dataset_name);
void SetBluetoothManualChooser();
Expand Down Expand Up @@ -1054,7 +1054,7 @@ void TestRunnerBindings::SetAllowFileAccessFromFileURLs(bool allow) {
runner_->SetAllowFileAccessFromFileURLs(allow);
}

void TestRunnerBindings::OverridePreference(const std::string key,
void TestRunnerBindings::OverridePreference(const std::string& key,
v8::Local<v8::Value> value) {
if (runner_)
runner_->OverridePreference(key, value);
Expand Down Expand Up @@ -1450,7 +1450,7 @@ void TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen(
runner_->CopyImageAtAndCapturePixelsAsyncThen(x, y, callback);
}

void TestRunnerBindings::SetCustomTextOutput(std::string output) {
void TestRunnerBindings::SetCustomTextOutput(const std::string& output) {
runner_->setCustomTextOutput(output);
}

Expand Down Expand Up @@ -1784,7 +1784,7 @@ std::string TestRunner::customDumpText() const {
return custom_text_output_;
}

void TestRunner::setCustomTextOutput(std::string text) {
void TestRunner::setCustomTextOutput(const std::string& text) {
custom_text_output_ = text;
has_custom_text_output_ = true;
}
Expand Down Expand Up @@ -2554,7 +2554,7 @@ void TestRunner::SetAllowFileAccessFromFileURLs(bool allow) {
delegate_->ApplyPreferences();
}

void TestRunner::OverridePreference(const std::string key,
void TestRunner::OverridePreference(const std::string& key,
v8::Local<v8::Value> value) {
TestPreferences* prefs = delegate_->Preferences();
if (key == "WebKitDefaultFontSize") {
Expand Down
4 changes: 2 additions & 2 deletions components/test_runner/test_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class TestRunner : public WebTestRunner,
void ClearDevToolsLocalStorage();
void setShouldDumpAsText(bool);
void setShouldDumpAsMarkup(bool);
void setCustomTextOutput(std::string text);
void setCustomTextOutput(const std::string& text);
void setShouldGeneratePixelResults(bool);
void setShouldDumpFrameLoadCallbacks(bool);
void setShouldDumpPingLoaderCallbacks(bool);
Expand Down Expand Up @@ -329,7 +329,7 @@ class TestRunner : public WebTestRunner,
void SetXSSAuditorEnabled(bool enabled);
void SetAllowUniversalAccessFromFileURLs(bool allow);
void SetAllowFileAccessFromFileURLs(bool allow);
void OverridePreference(const std::string key, v8::Local<v8::Value> value);
void OverridePreference(const std::string& key, v8::Local<v8::Value> value);

// Modify accept_languages in RendererPreferences.
void SetAcceptLanguages(const std::string& accept_languages);
Expand Down
2 changes: 1 addition & 1 deletion components/tracing/trace_config_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TraceConfigFile::TraceConfigFile()
TraceConfigFile::~TraceConfigFile() {
}

bool TraceConfigFile::ParseTraceConfigFileContent(std::string content) {
bool TraceConfigFile::ParseTraceConfigFileContent(const std::string& content) {
scoped_ptr<base::Value> value(base::JSONReader::Read(content));
if (!value || !value->IsType(base::Value::TYPE_DICTIONARY))
return false;
Expand Down
2 changes: 1 addition & 1 deletion components/tracing/trace_config_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class TRACING_EXPORT TraceConfigFile {
TraceConfigFile();
~TraceConfigFile();

bool ParseTraceConfigFileContent(std::string content);
bool ParseTraceConfigFileContent(const std::string& content);

bool is_enabled_;
base::trace_event::TraceConfig trace_config_;
Expand Down
Loading

0 comments on commit 939799a

Please sign in to comment.