Commit e9d7b6cf authored by jcampan@chromium.org's avatar jcampan@chromium.org

Some code had been removed from FirstRun::IsChromeFirstRun() so that it may...

Some code had been removed from FirstRun::IsChromeFirstRun() so that it may return true then false when later invoked.This caused a bug where we would show the info-bar warning that Chromium is not the default browser after the first run.This patch resurrects that code and changes the first run UI, as it was relying on that behavior.BUG=http://crbug.com/15833TEST=Make IE or Firefox your default browser. Open Chromium so it shows the 1st run UI. Unselect the "make chromium my default browser" button, then press start. When Chromium shows up, there should be no info-bar warning you Chromium is not your default browser.     Also test that the first run UI still works as expected.
Review URL: http://codereview.chromium.org/155168

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20151 0039d316-1c4b-4281-b951-d872f2087c98
parent 5b2e8faf
...@@ -624,11 +624,10 @@ int BrowserMain(const MainFunctionParams& parameters) { ...@@ -624,11 +624,10 @@ int BrowserMain(const MainFunctionParams& parameters) {
// preferences are registered, since some of the code that the importer // preferences are registered, since some of the code that the importer
// touches reads preferences. // touches reads preferences.
if (is_first_run && !first_run_ui_bypass) { if (is_first_run && !first_run_ui_bypass) {
OpenFirstRunDialog(profile, &process_singleton); if (!OpenFirstRunDialog(profile, &process_singleton)) {
// If user cancelled the first run dialog box, the first run sentinel file // The user cancelled the first run dialog box, we should exit Chrome.
// didn't get created and we should exit Chrome.
if (FirstRun::IsChromeFirstRun())
return ResultCodes::NORMAL_EXIT; return ResultCodes::NORMAL_EXIT;
}
} }
#endif // OS_POSIX #endif // OS_POSIX
......
...@@ -58,9 +58,19 @@ bool GetFirstRunSentinelFilePath(FilePath* path) { ...@@ -58,9 +58,19 @@ bool GetFirstRunSentinelFilePath(FilePath* path) {
// TODO(port): Mac should share this code. // TODO(port): Mac should share this code.
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
bool FirstRun::IsChromeFirstRun() { bool FirstRun::IsChromeFirstRun() {
// A troolean, 0 means not yet set, 1 means set to true, 2 set to false.
static int first_run = 0;
if (first_run != 0)
return first_run == 1;
FilePath first_run_sentinel; FilePath first_run_sentinel;
return (GetFirstRunSentinelFilePath(&first_run_sentinel) && if (!GetFirstRunSentinelFilePath(&first_run_sentinel) ||
!file_util::PathExists(first_run_sentinel)); file_util::PathExists(first_run_sentinel)) {
first_run = 2;
return false;
}
first_run = 1;
return true;
} }
#endif #endif
......
...@@ -148,6 +148,8 @@ class FirstRunBrowserProcess : public BrowserProcessImpl { ...@@ -148,6 +148,8 @@ class FirstRunBrowserProcess : public BrowserProcessImpl {
// |profile| and perhaps some other tasks. // |profile| and perhaps some other tasks.
// |process_singleton| is used to lock the handling of CopyData messages // |process_singleton| is used to lock the handling of CopyData messages
// while the First Run UI is visible. // while the First Run UI is visible.
void OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton); // Returns true if the user clicked "Start", false if the user pressed "Cancel"
// or closed the dialog.
bool OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton);
#endif // CHROME_BROWSER_FIRST_RUN_H_ #endif // CHROME_BROWSER_FIRST_RUN_H_
...@@ -27,7 +27,7 @@ void DialogResponseCallback(GtkDialog* dialog, gint response, ...@@ -27,7 +27,7 @@ void DialogResponseCallback(GtkDialog* dialog, gint response,
} // namespace } // namespace
void OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton) { bool OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton) {
#if defined(GOOGLE_CHROME_BUILD) #if defined(GOOGLE_CHROME_BUILD)
GtkWidget* dialog = gtk_dialog_new_with_buttons( GtkWidget* dialog = gtk_dialog_new_with_buttons(
"Google Chrome Dev Build", "Google Chrome Dev Build",
...@@ -111,7 +111,8 @@ void OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton) { ...@@ -111,7 +111,8 @@ void OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton) {
MessageLoop::current()->Run(); MessageLoop::current()->Run();
// End of above TODO. // End of above TODO.
if (response == GTK_RESPONSE_ACCEPT) { bool accepted = (response == GTK_RESPONSE_ACCEPT);
if (accepted) {
// Mark that first run has ran. // Mark that first run has ran.
FirstRun::CreateSentinel(); FirstRun::CreateSentinel();
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check))) { if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check))) {
...@@ -125,7 +126,9 @@ void OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton) { ...@@ -125,7 +126,9 @@ void OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton) {
} }
gtk_widget_destroy(dialog); gtk_widget_destroy(dialog);
return accepted;
#else // defined(GOOGLE_CHROME_BUILD) #else // defined(GOOGLE_CHROME_BUILD)
FirstRun::CreateSentinel(); FirstRun::CreateSentinel();
return true;
#endif #endif
} }
...@@ -30,7 +30,7 @@ bool FirstRun::IsChromeFirstRun() { ...@@ -30,7 +30,7 @@ bool FirstRun::IsChromeFirstRun() {
#endif // defined(GOOGLE_CHROME_BUILD) #endif // defined(GOOGLE_CHROME_BUILD)
} }
void OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton) { bool OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton) {
// OpenFirstRunDialog is a no-op on non-branded builds. // OpenFirstRunDialog is a no-op on non-branded builds.
#if defined(GOOGLE_CHROME_BUILD) #if defined(GOOGLE_CHROME_BUILD)
// Breakpad should not be enabled on first run until the user has explicitly // Breakpad should not be enabled on first run until the user has explicitly
...@@ -56,4 +56,5 @@ void OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton) { ...@@ -56,4 +56,5 @@ void OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton) {
InitCrashProcessInfo(); InitCrashProcessInfo();
} }
#endif // defined(GOOGLE_CHROME_BUILD) #endif // defined(GOOGLE_CHROME_BUILD)
return true;
} }
...@@ -340,13 +340,17 @@ bool Upgrade::SwapNewChromeExeIfPresent() { ...@@ -340,13 +340,17 @@ bool Upgrade::SwapNewChromeExeIfPresent() {
return false; return false;
} }
void OpenFirstRunDialog(Profile* profile, bool OpenFirstRunDialog(Profile* profile,
ProcessSingleton* process_singleton) { ProcessSingleton* process_singleton) {
DCHECK(profile); DCHECK(profile);
DCHECK(process_singleton); DCHECK(process_singleton);
// We need the FirstRunView to outlive its parent, as we retrieve the accept
// state from it after the dialog has been closed.
scoped_ptr<FirstRunView> first_run_view(new FirstRunView(profile));
first_run_view->SetParentOwned(false);
views::Window* first_run_ui = views::Window::CreateChromeWindow( views::Window* first_run_ui = views::Window::CreateChromeWindow(
NULL, gfx::Rect(), new FirstRunView(profile)); NULL, gfx::Rect(), first_run_view.get());
DCHECK(first_run_ui); DCHECK(first_run_ui);
// We need to avoid dispatching new tabs when we are doing the import // We need to avoid dispatching new tabs when we are doing the import
...@@ -363,6 +367,8 @@ void OpenFirstRunDialog(Profile* profile, ...@@ -363,6 +367,8 @@ void OpenFirstRunDialog(Profile* profile,
// that keyboard accelerators (Enter, Esc, etc) work in the dialog box. // that keyboard accelerators (Enter, Esc, etc) work in the dialog box.
MessageLoopForUI::current()->Run(g_browser_process->accelerator_handler()); MessageLoopForUI::current()->Run(g_browser_process->accelerator_handler());
process_singleton->Unlock(); process_singleton->Unlock();
return first_run_view->accepted();
} }
namespace { namespace {
......
...@@ -39,14 +39,13 @@ FirstRunView::FirstRunView(Profile* profile) ...@@ -39,14 +39,13 @@ FirstRunView::FirstRunView(Profile* profile)
actions_import_(NULL), actions_import_(NULL),
actions_shorcuts_(NULL), actions_shorcuts_(NULL),
customize_link_(NULL), customize_link_(NULL),
customize_selected_(false) { customize_selected_(false),
accepted_(false) {
importer_host_ = new ImporterHost(); importer_host_ = new ImporterHost();
SetupControls(); SetupControls();
} }
FirstRunView::~FirstRunView() { FirstRunView::~FirstRunView() {
// Exit the message loop we were started with so that startup can continue.
MessageLoop::current()->Quit();
} }
void FirstRunView::SetupControls() { void FirstRunView::SetupControls() {
...@@ -184,12 +183,15 @@ bool FirstRunView::Accept() { ...@@ -184,12 +183,15 @@ bool FirstRunView::Accept() {
if (default_browser_->checked()) if (default_browser_->checked())
SetDefaultBrowser(); SetDefaultBrowser();
accepted_ = true;
FirstRunComplete(); FirstRunComplete();
MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
return true; return true;
} }
bool FirstRunView::Cancel() { bool FirstRunView::Cancel() {
UserMetrics::RecordAction(L"FirstRunDef_Cancel", profile_); UserMetrics::RecordAction(L"FirstRunDef_Cancel", profile_);
MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
return true; return true;
} }
......
...@@ -28,6 +28,8 @@ class FirstRunView : public FirstRunViewBase, ...@@ -28,6 +28,8 @@ class FirstRunView : public FirstRunViewBase,
explicit FirstRunView(Profile* profile); explicit FirstRunView(Profile* profile);
virtual ~FirstRunView(); virtual ~FirstRunView();
bool accepted() const { return accepted_;}
// Overridden from views::View: // Overridden from views::View:
virtual gfx::Size GetPreferredSize(); virtual gfx::Size GetPreferredSize();
virtual void Layout(); virtual void Layout();
...@@ -61,6 +63,10 @@ class FirstRunView : public FirstRunViewBase, ...@@ -61,6 +63,10 @@ class FirstRunView : public FirstRunViewBase,
views::Link* customize_link_; views::Link* customize_link_;
bool customize_selected_; bool customize_selected_;
// Whether the user accepted (pressed the "Start" button as opposed to
// "Cancel").
bool accepted_;
DISALLOW_COPY_AND_ASSIGN(FirstRunView); DISALLOW_COPY_AND_ASSIGN(FirstRunView);
}; };
......
...@@ -51,7 +51,7 @@ class Message; ...@@ -51,7 +51,7 @@ class Message;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// These stubs are for Browser_main() // These stubs are for Browser_main()
void OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton); bool OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton);
void InstallJankometer(const CommandLine&); void InstallJankometer(const CommandLine&);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment