diff options
author | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-23 03:51:41 +0000 |
---|---|---|
committer | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-23 03:51:41 +0000 |
commit | 6d1db74e78ec273a01ea98c80f0b5cd7a1ca84e9 (patch) | |
tree | d835b44f8164021a7d6c05f079289d3846463848 /chrome/service | |
parent | cc2331c2216436ab71e39d31b872b3f48f741635 (diff) | |
download | chromium_src-6d1db74e78ec273a01ea98c80f0b5cd7a1ca84e9.zip chromium_src-6d1db74e78ec273a01ea98c80f0b5cd7a1ca84e9.tar.gz chromium_src-6d1db74e78ec273a01ea98c80f0b5cd7a1ca84e9.tar.bz2 |
Removed unnecessary returning by reference to simplify code.
BUG=137129
Review URL: https://chromiumcodereview.appspot.com/10958052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@158200 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/service')
-rw-r--r-- | chrome/service/cloud_print/cloud_print_proxy.cc | 24 | ||||
-rw-r--r-- | chrome/service/cloud_print/connector_settings.cc | 23 | ||||
-rw-r--r-- | chrome/service/service_process.cc | 20 | ||||
-rw-r--r-- | chrome/service/service_process_prefs.cc | 45 | ||||
-rw-r--r-- | chrome/service/service_process_prefs.h | 18 | ||||
-rw-r--r-- | chrome/service/service_process_prefs_unittest.cc | 8 |
6 files changed, 72 insertions, 66 deletions
diff --git a/chrome/service/cloud_print/cloud_print_proxy.cc b/chrome/service/cloud_print/cloud_print_proxy.cc index 416eddb1..b6eff89 100644 --- a/chrome/service/cloud_print/cloud_print_proxy.cc +++ b/chrome/service/cloud_print/cloud_print_proxy.cc @@ -90,13 +90,11 @@ void CloudPrintProxy::EnableForUser(const std::string& lsid) { DCHECK(backend_.get()); // Read persisted robot credentials because we may decide to reuse it if the // passed in LSID belongs the same user. - std::string robot_refresh_token; - service_prefs_->GetString(prefs::kCloudPrintRobotRefreshToken, - &robot_refresh_token); - std::string robot_email; - service_prefs_->GetString(prefs::kCloudPrintRobotEmail, - &robot_email); - service_prefs_->GetString(prefs::kCloudPrintEmail, &user_email_); + std::string robot_refresh_token = + service_prefs_->GetString(prefs::kCloudPrintRobotRefreshToken, ""); + std::string robot_email = + service_prefs_->GetString(prefs::kCloudPrintRobotEmail, ""); + user_email_ = service_prefs_->GetString(prefs::kCloudPrintEmail, user_email_); // If we have been passed in an LSID, we want to use this to authenticate. // Else we will try and retrieve the last used auth tokens from prefs. @@ -110,9 +108,8 @@ void CloudPrintProxy::EnableForUser(const std::string& lsid) { backend_->InitializeWithRobotToken(robot_refresh_token, robot_email); } else { // Finally see if we have persisted user credentials (legacy case). - std::string cloud_print_token; - service_prefs_->GetString(prefs::kCloudPrintAuthToken, - &cloud_print_token); + std::string cloud_print_token = + service_prefs_->GetString(prefs::kCloudPrintAuthToken, ""); DCHECK(!cloud_print_token.empty()); backend_->InitializeWithToken(cloud_print_token); } @@ -146,8 +143,8 @@ bool CloudPrintProxy::CreateBackend() { // By default we don't poll for jobs when we lose XMPP connection. But this // behavior can be overridden by a preference. - bool enable_job_poll = false; - service_prefs_->GetBoolean(prefs::kCloudPrintEnableJobPoll, &enable_job_poll); + bool enable_job_poll = + service_prefs_->GetBoolean(prefs::kCloudPrintEnableJobPoll, false); gaia::OAuthClientInfo oauth_client_info; oauth_client_info.client_id = @@ -156,7 +153,6 @@ bool CloudPrintProxy::CreateBackend() { google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_CLOUD_PRINT); backend_.reset(new CloudPrintProxyBackend(this, settings_, oauth_client_info, enable_job_poll)); - return true; } @@ -191,7 +187,7 @@ void CloudPrintProxy::GetProxyInfo(cloud_print::CloudPrintProxyInfo* info) { // If the Cloud Print service is not enabled, we may need to read the old // value of proxy_id from prefs. if (info->proxy_id.empty()) - service_prefs_->GetString(prefs::kCloudPrintProxyId, &info->proxy_id); + info->proxy_id = service_prefs_->GetString(prefs::kCloudPrintProxyId, ""); } void CloudPrintProxy::CheckCloudPrintProxyPolicy() { diff --git a/chrome/service/cloud_print/connector_settings.cc b/chrome/service/cloud_print/connector_settings.cc index 667dd5b..f400914 100644 --- a/chrome/service/cloud_print/connector_settings.cc +++ b/chrome/service/cloud_print/connector_settings.cc @@ -17,7 +17,8 @@ const char kDeleteOnEnumFail[] = "delete_on_enum_fail"; } // namespace -ConnectorSettings::ConnectorSettings() : delete_on_enum_fail_(false) { +ConnectorSettings::ConnectorSettings() + : delete_on_enum_fail_(false) { } ConnectorSettings::~ConnectorSettings() { @@ -26,7 +27,7 @@ ConnectorSettings::~ConnectorSettings() { void ConnectorSettings::InitFrom(ServiceProcessPrefs* prefs) { CopyFrom(ConnectorSettings()); - prefs->GetString(prefs::kCloudPrintProxyId, &proxy_id_); + proxy_id_ = prefs->GetString(prefs::kCloudPrintProxyId, ""); if (proxy_id_.empty()) { proxy_id_ = cloud_print::PrintSystem::GenerateProxyId(); prefs->SetString(prefs::kCloudPrintProxyId, proxy_id_); @@ -34,24 +35,22 @@ void ConnectorSettings::InitFrom(ServiceProcessPrefs* prefs) { } // Getting print system specific settings from the preferences. - const base::DictionaryValue* print_system_settings = NULL; - prefs->GetDictionary(prefs::kCloudPrintPrintSystemSettings, - &print_system_settings); + const base::DictionaryValue* print_system_settings = + prefs->GetDictionary(prefs::kCloudPrintPrintSystemSettings); if (print_system_settings) { print_system_settings_.reset(print_system_settings->DeepCopy()); - // TODO(vitalybuka) : Consider to move option from print_system_settings. + // TODO(vitalybuka) : Consider to rename and move out option from + // print_system_settings. print_system_settings_->GetBoolean(kDeleteOnEnumFail, &delete_on_enum_fail_); } // Check if there is an override for the cloud print server URL. - std::string cloud_print_server_url_str; - prefs->GetString(prefs::kCloudPrintServiceURL, - &cloud_print_server_url_str); - if (cloud_print_server_url_str.empty()) { - cloud_print_server_url_str = kDefaultCloudPrintServerUrl; + server_url_ = GURL(prefs->GetString(prefs::kCloudPrintServiceURL, "")); + DCHECK(server_url_.is_empty() || server_url_.is_valid()); + if (server_url_.is_empty() || !server_url_.is_valid()) { + server_url_ = GURL(kDefaultCloudPrintServerUrl); } - server_url_ = GURL(cloud_print_server_url_str.c_str()); DCHECK(server_url_.is_valid()); } diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc index d585f30..21d8334 100644 --- a/chrome/service/service_process.cc +++ b/chrome/service/service_process.cc @@ -175,7 +175,7 @@ bool ServiceProcess::Initialize(MessageLoopForUI* message_loop, } else { // If no command-line value was specified, read the last used locale from // the prefs. - service_prefs_->GetString(prefs::kApplicationLocale, &locale); + locale = service_prefs_->GetString(prefs::kApplicationLocale, ""); // If no locale was specified anywhere, use the default one. if (locale.empty()) locale = kDefaultServiceProcessLocale; @@ -185,23 +185,13 @@ bool ServiceProcess::Initialize(MessageLoopForUI* message_loop, PrepareRestartOnCrashEnviroment(command_line); // Enable Cloud Print if needed. First check the command-line. - bool cloud_print_proxy_enabled = - command_line.HasSwitch(switches::kEnableCloudPrintProxy); - if (!cloud_print_proxy_enabled) { - // Then check if the cloud print proxy was previously enabled. - service_prefs_->GetBoolean(prefs::kCloudPrintProxyEnabled, - &cloud_print_proxy_enabled); - } - - if (cloud_print_proxy_enabled) { + // Then check if the cloud print proxy was previously enabled. + if (command_line.HasSwitch(switches::kEnableCloudPrintProxy) || + service_prefs_->GetBoolean(prefs::kCloudPrintProxyEnabled, false)) { GetCloudPrintProxy()->EnableForUser(lsid); } // Enable Virtual Printer Driver if needed. - bool virtual_printer_driver_enabled = false; - service_prefs_->GetBoolean(prefs::kVirtualPrinterDriverEnabled, - &virtual_printer_driver_enabled); - - if (virtual_printer_driver_enabled) { + if (service_prefs_->GetBoolean(prefs::kVirtualPrinterDriverEnabled, false)) { // Register the fact that there is at least one // service needing the process. OnServiceEnabled(); diff --git a/chrome/service/service_process_prefs.cc b/chrome/service/service_process_prefs.cc index b925e2b..e1aca1a1 100644 --- a/chrome/service/service_process_prefs.cc +++ b/chrome/service/service_process_prefs.cc @@ -22,11 +22,16 @@ void ServiceProcessPrefs::WritePrefs() { prefs_->CommitPendingWrite(); } -void ServiceProcessPrefs::GetString(const std::string& key, - std::string* result) const { +std::string ServiceProcessPrefs::GetString( + const std::string& key, + const std::string& default_value) const { const Value* value; - if (prefs_->GetValue(key, &value) == PersistentPrefStore::READ_OK) - value->GetAsString(result); + std::string result; + if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK || + !value->GetAsString(&result)) { + return default_value; + } + return result; } void ServiceProcessPrefs::SetString(const std::string& key, @@ -34,28 +39,44 @@ void ServiceProcessPrefs::SetString(const std::string& key, prefs_->SetValue(key, Value::CreateStringValue(value)); } -void ServiceProcessPrefs::GetBoolean(const std::string& key, - bool* result) const { +bool ServiceProcessPrefs::GetBoolean(const std::string& key, + bool default_value) const { const Value* value; - if (prefs_->GetValue(key, &value) == PersistentPrefStore::READ_OK) - value->GetAsBoolean(result); + bool result = false; + if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK || + !value->GetAsBoolean(&result)) { + return default_value; + } + return result; } void ServiceProcessPrefs::SetBoolean(const std::string& key, bool value) { prefs_->SetValue(key, Value::CreateBooleanValue(value)); } -void ServiceProcessPrefs::GetDictionary(const std::string& key, - const DictionaryValue** result) const { +const DictionaryValue* ServiceProcessPrefs::GetDictionary( + const std::string& key) const { const Value* value; if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK || !value->IsType(Value::TYPE_DICTIONARY)) { - return; + return NULL; } - *result = static_cast<const DictionaryValue*>(value); + return static_cast<const DictionaryValue*>(value); +} + +const base::ListValue* ServiceProcessPrefs::GetList( + const std::string& key) const { + const Value* value; + if (prefs_->GetValue(key, &value) != PersistentPrefStore::READ_OK || + !value->IsType(Value::TYPE_LIST)) { + return NULL; + } + + return static_cast<const ListValue*>(value); } void ServiceProcessPrefs::RemovePref(const std::string& key) { prefs_->RemoveValue(key); } + diff --git a/chrome/service/service_process_prefs.h b/chrome/service/service_process_prefs.h index 74a674d..d03fda9 100644 --- a/chrome/service/service_process_prefs.h +++ b/chrome/service/service_process_prefs.h @@ -11,6 +11,7 @@ namespace base { class DictionaryValue; +class ListValue; } // Manages persistent preferences for the service process. This is basically a @@ -29,21 +30,24 @@ class ServiceProcessPrefs { // Write the data to the backing file. void WritePrefs(); - // Get a string preference for |key| and store it in |result|. - void GetString(const std::string& key, std::string* result) const; + // Returns a string preference for |key|. + std::string GetString(const std::string& key, + const std::string& default_value) const; // Set a string |value| for |key|. void SetString(const std::string& key, const std::string& value); - // Get a boolean preference for |key| and store it in |result|. - void GetBoolean(const std::string& key, bool* result) const; + // Returns a boolean preference for |key|. + bool GetBoolean(const std::string& key, bool default_value) const; // Set a boolean |value| for |key|. void SetBoolean(const std::string& key, bool value); - // Get a dictionary preference for |key| and store it in |result|. - void GetDictionary(const std::string& key, - const base::DictionaryValue** result) const; + // Returns a dictionary preference for |key|. + const base::DictionaryValue* GetDictionary(const std::string& key) const; + + // Returns a list for |key|. + const base::ListValue* GetList(const std::string& key) const; // Removes the pref specified by |key|. void RemovePref(const std::string& key); diff --git a/chrome/service/service_process_prefs_unittest.cc b/chrome/service/service_process_prefs_unittest.cc index 67ac5da..0268395 100644 --- a/chrome/service/service_process_prefs_unittest.cc +++ b/chrome/service/service_process_prefs_unittest.cc @@ -40,11 +40,7 @@ TEST_F(ServiceProcessPrefsTest, RetrievePrefs) { prefs_->SetBoolean("testb", false); // overwrite prefs_->SetString("tests", ""); // overwrite prefs_->ReadPrefs(); - bool testb; - prefs_->GetBoolean("testb", &testb); - EXPECT_EQ(testb, true); - std::string tests; - prefs_->GetString("tests", &tests); - EXPECT_EQ(tests, "testvalue"); + EXPECT_EQ(prefs_->GetBoolean("testb", false), true); + EXPECT_EQ(prefs_->GetString("tests", ""), "testvalue"); } |