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

Side by Side Diff: chrome/browser/ui/views/default_search_view.cc

Issue 7558014: Add a URL param to indicate group selection in Instant field trial. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Thread safe handling of Profiles Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/views/default_search_view.h" 5 #include "chrome/browser/ui/views/default_search_view.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 12 matching lines...) Expand all
23 #include "views/controls/image_view.h" 23 #include "views/controls/image_view.h"
24 #include "views/controls/label.h" 24 #include "views/controls/label.h"
25 #include "views/layout/grid_layout.h" 25 #include "views/layout/grid_layout.h"
26 #include "views/layout/layout_constants.h" 26 #include "views/layout/layout_constants.h"
27 #include "views/window/dialog_client_view.h" 27 #include "views/window/dialog_client_view.h"
28 #include "views/widget/widget.h" 28 #include "views/widget/widget.h"
29 29
30 namespace { 30 namespace {
31 31
32 // Returns a short name and logo resource id for the given host. 32 // Returns a short name and logo resource id for the given host.
33 void GetShortNameAndLogoId(PrefService* prefs, 33 void GetShortNameAndLogoId(Profile* profile,
Peter Kasting 2011/08/10 20:54:06 All the changes in this file can end up being reve
34 const TemplateURL* turl, 34 const TemplateURL* turl,
35 std::wstring* short_name, 35 std::wstring* short_name,
36 int* logo_id) { 36 int* logo_id) {
37 DCHECK(prefs); 37 DCHECK(profile);
38 DCHECK(turl); 38 DCHECK(turl);
39 DCHECK(short_name); 39 DCHECK(short_name);
40 DCHECK(logo_id); 40 DCHECK(logo_id);
41 41
42 GURL url = TemplateURLService::GenerateSearchURL(turl); 42 GURL url = TemplateURLService::GenerateSearchURL(turl, profile);
43 scoped_ptr<TemplateURL> built_in_data( 43 scoped_ptr<TemplateURL> built_in_data(
44 TemplateURLPrepopulateData::GetEngineForOrigin(prefs, url)); 44 TemplateURLPrepopulateData::GetEngineForOrigin(profile, url));
45 45
46 // Use the built-in information to generate the short name (to ensure 46 // Use the built-in information to generate the short name (to ensure
47 // that we don't use a name given by the search engine to itself which 47 // that we don't use a name given by the search engine to itself which
48 // in the worst case could be misleading). 48 // in the worst case could be misleading).
49 if (built_in_data.get()) { 49 if (built_in_data.get()) {
50 *short_name = built_in_data->short_name(); 50 *short_name = built_in_data->short_name();
51 *logo_id = built_in_data->logo_id(); 51 *logo_id = built_in_data->logo_id();
52 } else { 52 } else {
53 *short_name = UTF8ToWide(url.host()).c_str(); 53 *short_name = UTF8ToWide(url.host()).c_str();
54 *logo_id = kNoSearchEngineLogo; 54 *logo_id = kNoSearchEngineLogo;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 DefaultSearchView::DefaultSearchView(TabContents* tab_contents, 182 DefaultSearchView::DefaultSearchView(TabContents* tab_contents,
183 TemplateURL* proposed_default_turl, 183 TemplateURL* proposed_default_turl,
184 TemplateURLService* template_url_service) 184 TemplateURLService* template_url_service)
185 : background_image_(NULL), 185 : background_image_(NULL),
186 default_provider_button_(NULL), 186 default_provider_button_(NULL),
187 proposed_provider_button_(NULL), 187 proposed_provider_button_(NULL),
188 proposed_turl_(proposed_default_turl), 188 proposed_turl_(proposed_default_turl),
189 template_url_service_(template_url_service) { 189 template_url_service_(template_url_service) {
190 Profile* profile = 190 Profile* profile =
191 Profile::FromBrowserContext(tab_contents->browser_context()); 191 Profile::FromBrowserContext(tab_contents->browser_context());
192 PrefService* prefs = profile->GetPrefs(); 192 SetupControls(profile);
193 SetupControls(prefs);
194 193
195 // Show the dialog. 194 // Show the dialog.
196 tab_contents->CreateConstrainedDialog(this); 195 tab_contents->CreateConstrainedDialog(this);
197 } 196 }
198 197
199 void DefaultSearchView::SetupControls(PrefService* prefs) { 198 void DefaultSearchView::SetupControls(Profile* profile) {
200 using views::ColumnSet; 199 using views::ColumnSet;
201 using views::GridLayout; 200 using views::GridLayout;
202 using views::ImageView; 201 using views::ImageView;
203 using views::Label; 202 using views::Label;
204 203
205 // Column set id's. 204 // Column set id's.
206 const int kWholeDialogViewSetId = 0; 205 const int kWholeDialogViewSetId = 0;
207 const int kPaddedWholeDialogViewSetId = 1; 206 const int kPaddedWholeDialogViewSetId = 1;
208 const int kChoicesViewSetId = 2; 207 const int kChoicesViewSetId = 2;
209 208
210 // Set up the information for the proposed default. 209 // Set up the information for the proposed default.
211 std::wstring proposed_short_name; 210 std::wstring proposed_short_name;
212 int proposed_logo_id = kNoSearchEngineLogo; 211 int proposed_logo_id = kNoSearchEngineLogo;
213 GetShortNameAndLogoId(prefs, 212 GetShortNameAndLogoId(profile,
214 proposed_turl_.get(), 213 proposed_turl_.get(),
215 &proposed_short_name, 214 &proposed_short_name,
216 &proposed_logo_id); 215 &proposed_logo_id);
217 if (proposed_logo_id != kNoSearchEngineLogo) 216 if (proposed_logo_id != kNoSearchEngineLogo)
218 proposed_turl_->set_logo_id(proposed_logo_id); 217 proposed_turl_->set_logo_id(proposed_logo_id);
219 218
220 219
221 // Set up the information for the current default. 220 // Set up the information for the current default.
222 std::wstring default_short_name; 221 std::wstring default_short_name;
223 int default_logo_id = kNoSearchEngineLogo; 222 int default_logo_id = kNoSearchEngineLogo;
224 GetShortNameAndLogoId(prefs, 223 GetShortNameAndLogoId(profile,
225 template_url_service_->GetDefaultSearchProvider(), 224 template_url_service_->GetDefaultSearchProvider(),
226 &default_short_name, 225 &default_short_name,
227 &default_logo_id); 226 &default_logo_id);
228 227
229 // Now set-up the dialog contents. 228 // Now set-up the dialog contents.
230 GridLayout* layout = new views::GridLayout(this); 229 GridLayout* layout = new views::GridLayout(this);
231 layout->SetInsets(0, 0, views::kPanelVertMargin, 0); 230 layout->SetInsets(0, 0, views::kPanelVertMargin, 0);
232 SetLayoutManager(layout); 231 SetLayoutManager(layout);
233 232
234 // Add a column set that spans the whole dialog. 233 // Add a column set that spans the whole dialog.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 this, 302 this,
304 IDS_DEFAULT_SEARCH_PROMPT_CURRENT, 303 IDS_DEFAULT_SEARCH_PROMPT_CURRENT,
305 default_short_name); 304 default_short_name);
306 layout->AddView(default_provider_button_); 305 layout->AddView(default_provider_button_);
307 proposed_provider_button_ = CreateProviderChoiceButton( 306 proposed_provider_button_ = CreateProviderChoiceButton(
308 this, 307 this,
309 IDS_DEFAULT_SEARCH_PROMPT_PROPOSED, 308 IDS_DEFAULT_SEARCH_PROMPT_PROPOSED,
310 proposed_short_name); 309 proposed_short_name);
311 layout->AddView(proposed_provider_button_); 310 layout->AddView(proposed_provider_button_);
312 } 311 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698