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

Side by Side Diff: chrome/browser/search_engines/template_url_service_test_util.cc

Issue 2814743006: Refactoring after comments in https://codereview.chromium.org/2639153002 (Closed)
Patch Set: Created 3 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/search_engines/template_url_service_test_util.h" 5 #include "chrome/browser/search_engines/template_url_service_test_util.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "chrome/browser/history/history_service_factory.h" 10 #include "chrome/browser/history/history_service_factory.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 return search_term; 151 return search_term;
152 } 152 }
153 153
154 void TemplateURLServiceTestUtil::SetGoogleBaseURL(const GURL& base_url) { 154 void TemplateURLServiceTestUtil::SetGoogleBaseURL(const GURL& base_url) {
155 DCHECK(base_url.is_valid()); 155 DCHECK(base_url.is_valid());
156 search_terms_data_->set_google_base_url(base_url.spec()); 156 search_terms_data_->set_google_base_url(base_url.spec());
157 model_->GoogleBaseURLChanged(); 157 model_->GoogleBaseURLChanged();
158 } 158 }
159 159
160 TemplateURL* TemplateURLServiceTestUtil::AddExtensionControlledTURL( 160 TemplateURL* TemplateURLServiceTestUtil::AddExtensionControlledTURL(
161 std::unique_ptr<TemplateURL> extension_turl, 161 std::unique_ptr<TemplateURL> extension_turl) {
162 const std::string& extension_id, 162 TemplateURL* result = model()->Add(std::move(extension_turl));
163 bool wants_to_be_default, 163 DCHECK(result->GetExtensionInfoForTesting());
Peter Kasting 2017/04/13 00:11:01 This unconditionally derefs the pointer, but then
Alexander Yashkin 2017/04/13 06:07:50 Added DCHECK(result)
164 base::Time install_time) { 164 if (result &&
165 auto extension_info = 165 result->GetExtensionInfoForTesting()->wants_to_be_default_engine) {
166 base::MakeUnique<TemplateURL::AssociatedExtensionInfo>(extension_id);
167 extension_info->wants_to_be_default_engine = wants_to_be_default;
168 extension_info->install_time = install_time;
169
170 TemplateURL* result = model()->AddExtensionControlledTURL(
171 std::move(extension_turl), std::move(extension_info));
172 if (wants_to_be_default && result) {
173 SetExtensionDefaultSearchInPrefs(profile()->GetTestingPrefService(), 166 SetExtensionDefaultSearchInPrefs(profile()->GetTestingPrefService(),
174 result->data()); 167 result->data());
175 } 168 }
176 return result; 169 return result;
177 } 170 }
178 171
179 void TemplateURLServiceTestUtil::RemoveExtensionControlledTURL( 172 void TemplateURLServiceTestUtil::RemoveExtensionControlledTURL(
180 const std::string& extension_id) { 173 const std::string& extension_id) {
181 TemplateURL* turl = model()->FindTemplateURLForExtension( 174 TemplateURL* turl = model()->FindTemplateURLForExtension(
182 extension_id, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); 175 extension_id, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
183 ASSERT_TRUE(turl); 176 ASSERT_TRUE(turl);
184 ASSERT_TRUE(turl->GetExtensionInfoForTesting()); 177 ASSERT_TRUE(turl->GetExtensionInfoForTesting());
185 if (turl->GetExtensionInfoForTesting()->wants_to_be_default_engine) 178 if (turl->GetExtensionInfoForTesting()->wants_to_be_default_engine)
186 RemoveExtensionDefaultSearchFromPrefs(profile()->GetTestingPrefService()); 179 RemoveExtensionDefaultSearchFromPrefs(profile()->GetTestingPrefService());
187 model()->RemoveExtensionControlledTURL( 180 model()->RemoveExtensionControlledTURL(
188 extension_id, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION); 181 extension_id, TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION);
189 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698