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

Side by Side Diff: chrome/browser/views/first_run_search_engine_view.cc

Issue 2934011: New first run sequence for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Added support for control of all import via master_preferences Created 10 years, 5 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/views/first_run_search_engine_view.h" 5 #include "chrome/browser/views/first_run_search_engine_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "app/resource_bundle.h" 11 #include "app/resource_bundle.h"
12 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "chrome/browser/options_window.h" 14 #include "chrome/browser/options_window.h"
15 #include "chrome/browser/profile.h" 15 #include "chrome/browser/profile.h"
16 #include "chrome/browser/search_engines/template_url.h" 16 #include "chrome/browser/search_engines/template_url.h"
17 #include "chrome/browser/search_engines/template_url_model.h"
18 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 17 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
19 #include "gfx/font.h" 18 #include "gfx/font.h"
20 #include "grit/browser_resources.h" 19 #include "grit/browser_resources.h"
21 #include "grit/chromium_strings.h" 20 #include "grit/chromium_strings.h"
22 #include "grit/google_chrome_strings.h" 21 #include "grit/google_chrome_strings.h"
23 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
24 #include "grit/locale_settings.h" 23 #include "grit/locale_settings.h"
25 #include "grit/theme_resources.h" 24 #include "grit/theme_resources.h"
26 #include "views/controls/button/button.h" 25 #include "views/controls/button/button.h"
27 #include "views/controls/image_view.h" 26 #include "views/controls/image_view.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 return choice_view_->GetPreferredSize().height(); 147 return choice_view_->GetPreferredSize().height();
149 } 148 }
150 } 149 }
151 150
152 void SearchEngineChoice::SetChoiceViewBounds(int x, int y, int width, 151 void SearchEngineChoice::SetChoiceViewBounds(int x, int y, int width,
153 int height) { 152 int height) {
154 choice_view_->SetBounds(x, y, width, height); 153 choice_view_->SetBounds(x, y, width, height);
155 } 154 }
156 155
157 FirstRunSearchEngineView::FirstRunSearchEngineView( 156 FirstRunSearchEngineView::FirstRunSearchEngineView(
158 SearchEngineSelectionObserver* observer, Profile* profile, bool randomize) 157 Profile* profile, bool randomize)
159 : background_image_(NULL), 158 : background_image_(NULL),
160 profile_(profile), 159 profile_(profile),
161 observer_(observer),
162 text_direction_is_rtl_(base::i18n::IsRTL()), 160 text_direction_is_rtl_(base::i18n::IsRTL()),
163 randomize_(randomize) { 161 randomize_(randomize) {
164 DCHECK(observer);
165 // Don't show ourselves until all the search engines have loaded from 162 // Don't show ourselves until all the search engines have loaded from
166 // the profile -- otherwise we have nothing to show. 163 // the profile -- otherwise we have nothing to show.
167 SetVisible(false); 164 SetVisible(false);
168 165
169 // Start loading the search engines for the given profile. 166 // Start loading the search engines for the given profile.
170 search_engines_model_ = profile_->GetTemplateURLModel(); 167 search_engines_model_ = profile_->GetTemplateURLModel();
171 if (search_engines_model_) { 168 if (search_engines_model_) {
172 DCHECK(!search_engines_model_->loaded()); 169 DCHECK(!search_engines_model_->loaded());
173 search_engines_model_->AddObserver(this); 170 search_engines_model_->AddObserver(this);
174 search_engines_model_->Load(); 171 search_engines_model_->Load();
175 } else { 172 } else {
176 NOTREACHED(); 173 NOTREACHED();
177 } 174 }
178 SetupControls(); 175 SetupControls();
179 } 176 }
180 177
181 FirstRunSearchEngineView::~FirstRunSearchEngineView() { 178 FirstRunSearchEngineView::~FirstRunSearchEngineView() {
182 search_engines_model_->RemoveObserver(this); 179 search_engines_model_->RemoveObserver(this);
183 } 180 }
184 181
185 void FirstRunSearchEngineView::ButtonPressed(views::Button* sender, 182 void FirstRunSearchEngineView::ButtonPressed(views::Button* sender,
186 const views::Event& event) { 183 const views::Event& event) {
187 SearchEngineChoice* choice = static_cast<SearchEngineChoice*>(sender); 184 SearchEngineChoice* choice = static_cast<SearchEngineChoice*>(sender);
188 profile_->GetTemplateURLModel()->SetSearchEngineDialogSlot( 185 TemplateURLModel* template_url_model = profile_->GetTemplateURLModel();
189 choice->slot()); 186 DCHECK(template_url_model);
190 observer_->SearchEngineChosen(choice->GetSearchEngine()); 187 template_url_model->SetSearchEngineDialogSlot(choice->slot());
188 const TemplateURL* default_search = choice->GetSearchEngine();
189 if (default_search)
190 template_url_model->SetDefaultSearchProvider(default_search);
191
192 MessageLoop::current()->Quit();
191 } 193 }
192 194
193 void FirstRunSearchEngineView::OnTemplateURLModelChanged() { 195 void FirstRunSearchEngineView::OnTemplateURLModelChanged() {
194 using views::ImageView; 196 using views::ImageView;
195 197
196 // We only watch the search engine model change once, on load. Remove 198 // We only watch the search engine model change once, on load. Remove
197 // observer so we don't try to redraw if engines change under us. 199 // observer so we don't try to redraw if engines change under us.
198 search_engines_model_->RemoveObserver(this); 200 search_engines_model_->RemoveObserver(this);
199 201
200 // Add search engines in search_engines_model_ to buttons list. The 202 // Add search engines in search_engines_model_ to buttons list. The
201 // first three will always be from prepopulated data. 203 // first three will always be from prepopulated data.
202 std::vector<const TemplateURL*> template_urls = 204 std::vector<const TemplateURL*> template_urls =
203 search_engines_model_->GetTemplateURLs(); 205 search_engines_model_->GetTemplateURLs();
204 206
205 // If we have fewer than three search engines, signal that the search engine 207 // If we have fewer than three search engines, signal that the search engine
206 // experiment is over, leaving imported default search engine setting intact. 208 // experiment is over, leaving imported default search engine setting intact.
207 if (template_urls.size() < 3) { 209 if (template_urls.size() < 3)
208 observer_->SearchEngineChosen(NULL);
209 return; 210 return;
210 }
211 211
212 std::vector<const TemplateURL*>::iterator search_engine_iter; 212 std::vector<const TemplateURL*>::iterator search_engine_iter;
213 213
214 // Is user's default search engine included in first three prepopulated 214 // Is user's default search engine included in first three prepopulated
215 // set? If not, we need to expand the dialog to include a fourth engine. 215 // set? If not, we need to expand the dialog to include a fourth engine.
216 const TemplateURL* default_search_engine = 216 const TemplateURL* default_search_engine =
217 search_engines_model_->GetDefaultSearchProvider(); 217 search_engines_model_->GetDefaultSearchProvider();
218 // If the user's default choice is not in the first three search engines 218 // If the user's default choice is not in the first three search engines
219 // in template_urls, store it in |default_choice| and provide it as a 219 // in template_urls, store it in |default_choice| and provide it as a
220 // fourth option. 220 // fourth option.
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 logo_padding; 418 logo_padding;
419 search_engine_choices_[3]->SetBounds(next_h_space, next_v_space, 419 search_engine_choices_[3]->SetBounds(next_h_space, next_v_space,
420 button_width, button_height); 420 button_width, button_height);
421 } 421 }
422 } // if (search_engine_choices.size() > 0) 422 } // if (search_engine_choices.size() > 0)
423 } 423 }
424 424
425 std::wstring FirstRunSearchEngineView::GetWindowTitle() const { 425 std::wstring FirstRunSearchEngineView::GetWindowTitle() const {
426 return l10n_util::GetString(IDS_FIRSTRUN_DLG_TITLE); 426 return l10n_util::GetString(IDS_FIRSTRUN_DLG_TITLE);
427 } 427 }
OLDNEW
« no previous file with comments | « chrome/browser/views/first_run_search_engine_view.h ('k') | chrome/browser/views/first_run_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698