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

Unified Diff: chrome/browser/ui/views/first_run_search_engine_view.cc

Issue 8869005: Revert EnableClose() removal and related crash fixes. I don't understand the crashes here, and th... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/first_run_search_engine_view.cc
===================================================================
--- chrome/browser/ui/views/first_run_search_engine_view.cc (revision 113407)
+++ chrome/browser/ui/views/first_run_search_engine_view.cc (working copy)
@@ -64,10 +64,13 @@
views::Widget* window = views::Widget::CreateWindow(
new FirstRunSearchEngineView(
profile, randomize_search_engine_experiment));
+ DCHECK(window);
+
window->SetAlwaysOnTop(true);
window->Show();
views::AcceleratorHandler accelerator_handler;
MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler);
+ window->Close();
}
} // namespace first_run
@@ -140,26 +143,21 @@
FirstRunSearchEngineView::FirstRunSearchEngineView(Profile* profile,
bool randomize)
- : views::ClientView(NULL, NULL),
- background_image_(NULL),
+ : background_image_(NULL),
template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)),
text_direction_is_rtl_(base::i18n::IsRTL()),
+ template_url_service_loaded_(false),
added_to_view_hierarchy_(false),
- randomize_(randomize),
- user_chosen_engine_(false),
- fallback_choice_(NULL),
- quit_on_closing_(true) {
+ randomize_(randomize) {
// Don't show ourselves until all the search engines have loaded from
// the profile -- otherwise we have nothing to show.
SetVisible(false);
- // Start loading the search engines for the given profile. The service is
- // already loaded in tests.
+ // Start loading the search engines for the given profile.
DCHECK(template_url_service_);
- if (!template_url_service_->loaded()) {
- template_url_service_->AddObserver(this);
- template_url_service_->Load();
- }
+ DCHECK(!template_url_service_->loaded());
+ template_url_service_->AddObserver(this);
+ template_url_service_->Load();
}
FirstRunSearchEngineView::~FirstRunSearchEngineView() {
@@ -170,45 +168,16 @@
return l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_TITLE);
}
-views::View* FirstRunSearchEngineView::GetContentsView() {
- return this;
-}
-
-views::ClientView* FirstRunSearchEngineView::CreateClientView(
- views::Widget* widget) {
- return this;
-}
-
-void FirstRunSearchEngineView::WindowClosing() {
- // If the window is closed by clicking the close button, we default to the
- // engine in the first slot.
- if (!user_chosen_engine_)
- ChooseSearchEngine(fallback_choice_);
- if (quit_on_closing_)
- MessageLoop::current()->Quit();
-}
-
-views::Widget* FirstRunSearchEngineView::GetWidget() {
- return View::GetWidget();
-}
-
-const views::Widget* FirstRunSearchEngineView::GetWidget() const {
- return View::GetWidget();
-}
-
-bool FirstRunSearchEngineView::CanClose() {
- // We need a valid search engine to set as default, so if the user tries to
- // close the window before the template URL service is loaded, we must prevent
- // this from happening.
- return fallback_choice_ != NULL;
-}
-
void FirstRunSearchEngineView::ButtonPressed(views::Button* sender,
const views::Event& event) {
- ChooseSearchEngine(static_cast<SearchEngineChoice*>(sender));
- GetWidget()->Close();
- // This will call through to WindowClosing() above and will quit the message
- // loop.
+ SearchEngineChoice* choice = static_cast<SearchEngineChoice*>(sender);
+ DCHECK(template_url_service_);
+ template_url_service_->SetSearchEngineDialogSlot(choice->slot());
+ const TemplateURL* default_search = choice->GetSearchEngine();
+ if (default_search)
+ template_url_service_->SetDefaultSearchProvider(default_search);
+
+ MessageLoop::current()->Quit();
}
void FirstRunSearchEngineView::OnPaint(gfx::Canvas* canvas) {
@@ -226,6 +195,8 @@
// We only watch the search engine model change once, on load. Remove
// observer so we don't try to redraw if engines change under us.
template_url_service_->RemoveObserver(this);
+
+ template_url_service_loaded_ = true;
AddSearchEnginesIfPossible();
}
@@ -236,6 +207,9 @@
}
void FirstRunSearchEngineView::Layout() {
+ // Disable the close button.
+ GetWidget()->EnableClose(false);
+
gfx::Size pref_size = background_image_->GetPreferredSize();
background_image_->SetBounds(0, 0, GetPreferredSize().width(),
pref_size.height());
@@ -395,7 +369,7 @@
}
void FirstRunSearchEngineView::AddSearchEnginesIfPossible() {
- if (!template_url_service_->loaded() || !added_to_view_hierarchy_)
+ if (!template_url_service_loaded_ || !added_to_view_hierarchy_)
return;
// Add search engines in template_url_service_ to buttons list. The
@@ -457,10 +431,6 @@
AddChildView(default_choice); // The button associated with the choice.
}
- // It is critically important that this line happens before randomization is
- // done below.
- fallback_choice_ = search_engine_choices_.front();
-
// Randomize order of logos if option has been set.
if (randomize_) {
std::random_shuffle(search_engine_choices_.begin(),
@@ -499,12 +469,3 @@
GetWidget()->NotifyAccessibilityEvent(
this, ui::AccessibilityTypes::EVENT_ALERT, true);
}
-
-void FirstRunSearchEngineView::ChooseSearchEngine(SearchEngineChoice* choice) {
- user_chosen_engine_ = true;
- DCHECK(choice && template_url_service_);
- template_url_service_->SetSearchEngineDialogSlot(choice->slot());
- const TemplateURL* default_search = choice->GetSearchEngine();
- if (default_search)
- template_url_service_->SetDefaultSearchProvider(default_search);
-}

Powered by Google App Engine
This is Rietveld 408576698