| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/settings/search_engines_handler.h" | 5 #include "chrome/browser/ui/webui/settings/search_engines_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 AllowJavascript(); | 95 AllowJavascript(); |
| 96 | 96 |
| 97 // Find the default engine. | 97 // Find the default engine. |
| 98 const TemplateURL* default_engine = | 98 const TemplateURL* default_engine = |
| 99 list_controller_.GetDefaultSearchProvider(); | 99 list_controller_.GetDefaultSearchProvider(); |
| 100 int default_index = | 100 int default_index = |
| 101 list_controller_.table_model()->IndexOfTemplateURL(default_engine); | 101 list_controller_.table_model()->IndexOfTemplateURL(default_engine); |
| 102 | 102 |
| 103 // Build the first list (default search engines). | 103 // Build the first list (default search engines). |
| 104 std::unique_ptr<base::ListValue> defaults = | 104 std::unique_ptr<base::ListValue> defaults = |
| 105 base::WrapUnique(new base::ListValue()); | 105 base::MakeUnique<base::ListValue>(); |
| 106 int last_default_engine_index = | 106 int last_default_engine_index = |
| 107 list_controller_.table_model()->last_search_engine_index(); | 107 list_controller_.table_model()->last_search_engine_index(); |
| 108 for (int i = 0; i < last_default_engine_index; ++i) { | 108 for (int i = 0; i < last_default_engine_index; ++i) { |
| 109 // Third argument is false, as the engine is not from an extension. | 109 // Third argument is false, as the engine is not from an extension. |
| 110 defaults->Append(CreateDictionaryForEngine(i, i == default_index)); | 110 defaults->Append(CreateDictionaryForEngine(i, i == default_index)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Build the second list (other search engines). | 113 // Build the second list (other search engines). |
| 114 std::unique_ptr<base::ListValue> others = | 114 std::unique_ptr<base::ListValue> others = base::MakeUnique<base::ListValue>(); |
| 115 base::WrapUnique(new base::ListValue()); | |
| 116 int last_other_engine_index = | 115 int last_other_engine_index = |
| 117 list_controller_.table_model()->last_other_engine_index(); | 116 list_controller_.table_model()->last_other_engine_index(); |
| 118 for (int i = std::max(last_default_engine_index, 0); | 117 for (int i = std::max(last_default_engine_index, 0); |
| 119 i < last_other_engine_index; ++i) { | 118 i < last_other_engine_index; ++i) { |
| 120 others->Append(CreateDictionaryForEngine(i, i == default_index)); | 119 others->Append(CreateDictionaryForEngine(i, i == default_index)); |
| 121 } | 120 } |
| 122 | 121 |
| 123 // Build the third list (omnibox extensions). | 122 // Build the third list (omnibox extensions). |
| 124 std::unique_ptr<base::ListValue> extensions = | 123 std::unique_ptr<base::ListValue> extensions = |
| 125 base::WrapUnique(new base::ListValue()); | 124 base::MakeUnique<base::ListValue>(); |
| 126 int engine_count = list_controller_.table_model()->RowCount(); | 125 int engine_count = list_controller_.table_model()->RowCount(); |
| 127 for (int i = std::max(last_other_engine_index, 0); i < engine_count; ++i) { | 126 for (int i = std::max(last_other_engine_index, 0); i < engine_count; ++i) { |
| 128 extensions->Append(CreateDictionaryForEngine(i, i == default_index)); | 127 extensions->Append(CreateDictionaryForEngine(i, i == default_index)); |
| 129 } | 128 } |
| 130 | 129 |
| 131 std::unique_ptr<base::DictionaryValue> search_engines_info( | 130 std::unique_ptr<base::DictionaryValue> search_engines_info( |
| 132 new base::DictionaryValue); | 131 new base::DictionaryValue); |
| 133 search_engines_info->Set("defaults", base::WrapUnique(defaults.release())); | 132 search_engines_info->Set("defaults", base::WrapUnique(defaults.release())); |
| 134 search_engines_info->Set("others", base::WrapUnique(others.release())); | 133 search_engines_info->Set("others", base::WrapUnique(others.release())); |
| 135 search_engines_info->Set("extensions", | 134 search_engines_info->Set("extensions", |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 std::string extension_id; | 343 std::string extension_id; |
| 345 CHECK(args->GetString(0, &extension_id)); | 344 CHECK(args->GetString(0, &extension_id)); |
| 346 ExtensionService* extension_service = | 345 ExtensionService* extension_service = |
| 347 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 346 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 348 DCHECK(extension_service); | 347 DCHECK(extension_service); |
| 349 extension_service->DisableExtension( | 348 extension_service->DisableExtension( |
| 350 extension_id, extensions::Extension::DISABLE_USER_ACTION); | 349 extension_id, extensions::Extension::DISABLE_USER_ACTION); |
| 351 } | 350 } |
| 352 | 351 |
| 353 } // namespace settings | 352 } // namespace settings |
| OLD | NEW |