| Index: chrome/browser/dom_ui/options/core_options_handler.cc
|
| ===================================================================
|
| --- chrome/browser/dom_ui/options/core_options_handler.cc (revision 62351)
|
| +++ chrome/browser/dom_ui/options/core_options_handler.cc (working copy)
|
| @@ -117,6 +117,8 @@
|
| NewCallback(this, &CoreOptionsHandler::HandleSetStringPref));
|
| dom_ui_->RegisterMessageCallback("setObjectPref",
|
| NewCallback(this, &CoreOptionsHandler::HandleSetObjectPref));
|
| + dom_ui_->RegisterMessageCallback("clearPref",
|
| + NewCallback(this, &CoreOptionsHandler::HandleClearPref));
|
| dom_ui_->RegisterMessageCallback("coreOptionsUserMetricsAction",
|
| NewCallback(this, &CoreOptionsHandler::HandleUserMetricsAction));
|
| }
|
| @@ -126,7 +128,6 @@
|
| }
|
|
|
| Value* CoreOptionsHandler::FetchPref(const std::string& pref_name) {
|
| - DCHECK(dom_ui_);
|
| PrefService* pref_service = dom_ui_->GetProfile()->GetPrefs();
|
|
|
| const PrefService::Preference* pref =
|
| @@ -152,7 +153,6 @@
|
| Value::ValueType pref_type,
|
| const std::string& value_string,
|
| const std::string& metric) {
|
| - DCHECK(dom_ui_);
|
| PrefService* pref_service = dom_ui_->GetProfile()->GetPrefs();
|
|
|
| switch (pref_type) {
|
| @@ -176,6 +176,16 @@
|
| ProcessUserMetric(pref_type, value_string, metric);
|
| }
|
|
|
| +void CoreOptionsHandler::ClearPref(const std::string& pref_name,
|
| + const std::string& metric) {
|
| + PrefService* pref_service = dom_ui_->GetProfile()->GetPrefs();
|
| + pref_service->ClearPref(pref_name.c_str());
|
| + pref_service->ScheduleSavePersistentPrefs();
|
| +
|
| + if (!metric.empty())
|
| + UserMetricsRecordAction(UserMetricsAction(metric.c_str()));
|
| +}
|
| +
|
| void CoreOptionsHandler::ProcessUserMetric(Value::ValueType pref_type,
|
| const std::string& value_string,
|
| const std::string& metric) {
|
| @@ -196,9 +206,7 @@
|
| void CoreOptionsHandler::HandleFetchPrefs(const ListValue* args) {
|
| // First param is name of callback function, so, there needs to be at least
|
| // one more element for the actual preference identifier.
|
| - const size_t kMinFetchPrefsParamCount = 2;
|
| - if (args->GetSize() < kMinFetchPrefsParamCount)
|
| - return;
|
| + DCHECK_GE(static_cast<int>(args->GetSize()), 2);
|
|
|
| // Get callback JS function name.
|
| Value* callback;
|
| @@ -233,9 +241,7 @@
|
| void CoreOptionsHandler::HandleObservePrefs(const ListValue* args) {
|
| // First param is name is JS callback function name, the rest are pref
|
| // identifiers that we are observing.
|
| - const size_t kMinObservePrefsParamCount = 2;
|
| - if (args->GetSize() < kMinObservePrefsParamCount)
|
| - return;
|
| + DCHECK_GE(static_cast<int>(args->GetSize()), 2);
|
|
|
| // Get preference change callback function name.
|
| string16 callback_func_name;
|
| @@ -281,8 +287,7 @@
|
|
|
| void CoreOptionsHandler::HandleSetPref(const ListValue* args,
|
| Value::ValueType type) {
|
| - if (args->GetSize() < 2)
|
| - return;
|
| + DCHECK_GT(static_cast<int>(args->GetSize()), 1);
|
|
|
| std::string pref_name;
|
| if (!args->GetString(0, &pref_name))
|
| @@ -299,6 +304,20 @@
|
| SetPref(pref_name, type, value_string, metric);
|
| }
|
|
|
| +void CoreOptionsHandler::HandleClearPref(const ListValue* args) {
|
| + DCHECK_GT(static_cast<int>(args->GetSize()), 0);
|
| +
|
| + std::string pref_name;
|
| + if (!args->GetString(0, &pref_name))
|
| + return;
|
| +
|
| + std::string metric;
|
| + if (args->GetSize() > 1)
|
| + args->GetString(1, &metric);
|
| +
|
| + ClearPref(pref_name, metric);
|
| +}
|
| +
|
| void CoreOptionsHandler::HandleUserMetricsAction(const ListValue* args) {
|
| std::string metric = WideToUTF8(ExtractStringValue(args));
|
| if (!metric.empty())
|
| @@ -306,8 +325,6 @@
|
| }
|
|
|
| void CoreOptionsHandler::NotifyPrefChanged(const std::string* pref_name) {
|
| - DCHECK(pref_name);
|
| - DCHECK(dom_ui_);
|
| PrefService* pref_service = dom_ui_->GetProfile()->GetPrefs();
|
| const PrefService::Preference* pref =
|
| pref_service->FindPreference(pref_name->c_str());
|
|
|