Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: chrome/browser/extensions/api/settings_overrides/settings_overrides_api.cc

Issue 2307663002: Remove ScopedVector from search_engines. (Closed)
Patch Set: devlin Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/extensions/api/settings_overrides/settings_overrides_ap i.h" 5 #include "chrome/browser/extensions/api/settings_overrides/settings_overrides_ap i.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 26 matching lines...) Expand all
37 37
38 using api::manifest_types::ChromeSettingsOverrides; 38 using api::manifest_types::ChromeSettingsOverrides;
39 39
40 std::string SubstituteInstallParam(std::string str, 40 std::string SubstituteInstallParam(std::string str,
41 const std::string& install_parameter) { 41 const std::string& install_parameter) {
42 base::ReplaceSubstringsAfterOffset(&str, 0, "__PARAM__", install_parameter); 42 base::ReplaceSubstringsAfterOffset(&str, 0, "__PARAM__", install_parameter);
43 return str; 43 return str;
44 } 44 }
45 45
46 // Find the prepopulated search engine with the given id. 46 // Find the prepopulated search engine with the given id.
47 bool GetPrepopulatedSearchProvider(PrefService* prefs, 47 std::unique_ptr<TemplateURLData> GetPrepopulatedSearchProvider(
48 int prepopulated_id, 48 PrefService* prefs,
49 TemplateURLData* data) { 49 int prepopulated_id) {
50 DCHECK(data);
51 size_t default_index; 50 size_t default_index;
52 ScopedVector<TemplateURLData> engines = 51 std::vector<std::unique_ptr<TemplateURLData>> engines =
53 TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, &default_index); 52 TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, &default_index);
54 for (ScopedVector<TemplateURLData>::iterator i = engines.begin(); 53 for (auto& engine : engines) {
55 i != engines.end(); 54 if (engine->prepopulate_id == prepopulated_id)
56 ++i) { 55 return std::move(engine);
57 if ((*i)->prepopulate_id == prepopulated_id) {
58 *data = **i;
59 return true;
60 }
61 } 56 }
62 return false; 57 return nullptr;
63 } 58 }
64 59
65 TemplateURLData ConvertSearchProvider( 60 std::unique_ptr<TemplateURLData> ConvertSearchProvider(
66 PrefService* prefs, 61 PrefService* prefs,
67 const ChromeSettingsOverrides::Search_provider& search_provider, 62 const ChromeSettingsOverrides::Search_provider& search_provider,
68 const std::string& install_parameter) { 63 const std::string& install_parameter) {
69 TemplateURLData data; 64 std::unique_ptr<TemplateURLData> data;
70 if (search_provider.prepopulated_id) { 65 if (search_provider.prepopulated_id) {
71 if (!GetPrepopulatedSearchProvider(prefs, *search_provider.prepopulated_id, 66 data =
72 &data)) { 67 GetPrepopulatedSearchProvider(prefs, *search_provider.prepopulated_id);
68 if (!data) {
73 VLOG(1) << "Settings Overrides API can't recognize prepopulated_id=" 69 VLOG(1) << "Settings Overrides API can't recognize prepopulated_id="
74 << *search_provider.prepopulated_id; 70 << *search_provider.prepopulated_id;
75 } 71 }
76 } 72 }
77 73
74 if (!data)
75 data = base::MakeUnique<TemplateURLData>();
76
78 if (search_provider.name) 77 if (search_provider.name)
79 data.SetShortName(base::UTF8ToUTF16(*search_provider.name)); 78 data->SetShortName(base::UTF8ToUTF16(*search_provider.name));
80 if (search_provider.keyword) 79 if (search_provider.keyword)
81 data.SetKeyword(base::UTF8ToUTF16(*search_provider.keyword)); 80 data->SetKeyword(base::UTF8ToUTF16(*search_provider.keyword));
82 data.SetURL(SubstituteInstallParam(search_provider.search_url, 81 data->SetURL(
83 install_parameter)); 82 SubstituteInstallParam(search_provider.search_url, install_parameter));
84 if (search_provider.suggest_url) { 83 if (search_provider.suggest_url) {
85 data.suggestions_url = 84 data->suggestions_url =
86 SubstituteInstallParam(*search_provider.suggest_url, install_parameter); 85 SubstituteInstallParam(*search_provider.suggest_url, install_parameter);
87 } 86 }
88 if (search_provider.instant_url) { 87 if (search_provider.instant_url) {
89 data.instant_url = 88 data->instant_url =
90 SubstituteInstallParam(*search_provider.instant_url, install_parameter); 89 SubstituteInstallParam(*search_provider.instant_url, install_parameter);
91 } 90 }
92 if (search_provider.image_url) { 91 if (search_provider.image_url) {
93 data.image_url = 92 data->image_url =
94 SubstituteInstallParam(*search_provider.image_url, install_parameter); 93 SubstituteInstallParam(*search_provider.image_url, install_parameter);
95 } 94 }
96 if (search_provider.search_url_post_params) 95 if (search_provider.search_url_post_params)
97 data.search_url_post_params = *search_provider.search_url_post_params; 96 data->search_url_post_params = *search_provider.search_url_post_params;
98 if (search_provider.suggest_url_post_params) 97 if (search_provider.suggest_url_post_params)
99 data.suggestions_url_post_params = *search_provider.suggest_url_post_params; 98 data->suggestions_url_post_params =
99 *search_provider.suggest_url_post_params;
100 if (search_provider.instant_url_post_params) 100 if (search_provider.instant_url_post_params)
101 data.instant_url_post_params = *search_provider.instant_url_post_params; 101 data->instant_url_post_params = *search_provider.instant_url_post_params;
102 if (search_provider.image_url_post_params) 102 if (search_provider.image_url_post_params)
103 data.image_url_post_params = *search_provider.image_url_post_params; 103 data->image_url_post_params = *search_provider.image_url_post_params;
104 if (search_provider.favicon_url) { 104 if (search_provider.favicon_url) {
105 data.favicon_url = GURL(SubstituteInstallParam(*search_provider.favicon_url, 105 data->favicon_url = GURL(SubstituteInstallParam(
106 install_parameter)); 106 *search_provider.favicon_url, install_parameter));
107 } 107 }
108 data.safe_for_autoreplace = false; 108 data->safe_for_autoreplace = false;
109 if (search_provider.encoding) { 109 if (search_provider.encoding) {
110 data.input_encodings.clear(); 110 data->input_encodings.clear();
111 data.input_encodings.push_back(*search_provider.encoding); 111 data->input_encodings.push_back(*search_provider.encoding);
112 } 112 }
113 data.date_created = base::Time(); 113 data->date_created = base::Time();
114 data.last_modified = base::Time(); 114 data->last_modified = base::Time();
115 data.prepopulate_id = 0; 115 data->prepopulate_id = 0;
116 if (search_provider.alternate_urls) { 116 if (search_provider.alternate_urls) {
117 data.alternate_urls.clear(); 117 data->alternate_urls.clear();
118 for (size_t i = 0; i < search_provider.alternate_urls->size(); ++i) { 118 for (size_t i = 0; i < search_provider.alternate_urls->size(); ++i) {
119 if (!search_provider.alternate_urls->at(i).empty()) 119 if (!search_provider.alternate_urls->at(i).empty())
120 data.alternate_urls.push_back(SubstituteInstallParam( 120 data->alternate_urls.push_back(SubstituteInstallParam(
121 search_provider.alternate_urls->at(i), install_parameter)); 121 search_provider.alternate_urls->at(i), install_parameter));
122 } 122 }
123 } 123 }
124 return data; 124 return data;
125 } 125 }
126 126
127 } // namespace 127 } // namespace
128 128
129 SettingsOverridesAPI::SettingsOverridesAPI(content::BrowserContext* context) 129 SettingsOverridesAPI::SettingsOverridesAPI(content::BrowserContext* context)
130 : profile_(Profile::FromBrowserContext(context)), 130 : profile_(Profile::FromBrowserContext(context)),
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 const SettingsOverrides* settings = SettingsOverrides::Get(extension); 268 const SettingsOverrides* settings = SettingsOverrides::Get(extension);
269 DCHECK(settings); 269 DCHECK(settings);
270 DCHECK(settings->search_engine); 270 DCHECK(settings->search_engine);
271 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> info( 271 std::unique_ptr<TemplateURL::AssociatedExtensionInfo> info(
272 new TemplateURL::AssociatedExtensionInfo( 272 new TemplateURL::AssociatedExtensionInfo(
273 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, extension->id())); 273 TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION, extension->id()));
274 info->wants_to_be_default_engine = settings->search_engine->is_default; 274 info->wants_to_be_default_engine = settings->search_engine->is_default;
275 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_); 275 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_);
276 info->install_time = prefs->GetInstallTime(extension->id()); 276 info->install_time = prefs->GetInstallTime(extension->id());
277 std::string install_parameter = prefs->GetInstallParam(extension->id()); 277 std::string install_parameter = prefs->GetInstallParam(extension->id());
278 TemplateURLData data = ConvertSearchProvider( 278 std::unique_ptr<TemplateURLData> data = ConvertSearchProvider(
279 profile_->GetPrefs(), *settings->search_engine, install_parameter); 279 profile_->GetPrefs(), *settings->search_engine, install_parameter);
280 data.show_in_default_list = info->wants_to_be_default_engine; 280 data->show_in_default_list = info->wants_to_be_default_engine;
281 url_service_->AddExtensionControlledTURL(base::MakeUnique<TemplateURL>(data), 281 url_service_->AddExtensionControlledTURL(base::MakeUnique<TemplateURL>(*data),
282 std::move(info)); 282 std::move(info));
283 } 283 }
284 284
285 template <> 285 template <>
286 void BrowserContextKeyedAPIFactory< 286 void BrowserContextKeyedAPIFactory<
287 SettingsOverridesAPI>::DeclareFactoryDependencies() { 287 SettingsOverridesAPI>::DeclareFactoryDependencies() {
288 DependsOn(ExtensionPrefsFactory::GetInstance()); 288 DependsOn(ExtensionPrefsFactory::GetInstance());
289 DependsOn(PreferenceAPI::GetFactoryInstance()); 289 DependsOn(PreferenceAPI::GetFactoryInstance());
290 DependsOn(TemplateURLServiceFactory::GetInstance()); 290 DependsOn(TemplateURLServiceFactory::GetInstance());
291 } 291 }
292 292
293 } // namespace extensions 293 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698