| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/first_run_dialog.h" | 5 #include "chrome/browser/ui/views/first_run_dialog.h" |
| 6 | 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/bind.h" |
| 7 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 9 #include "chrome/browser/first_run/first_run.h" | 12 #include "chrome/browser/first_run/first_run.h" |
| 13 #include "chrome/browser/metrics/metrics_reporting_state.h" |
| 10 #include "chrome/browser/platform_util.h" | 14 #include "chrome/browser/platform_util.h" |
| 11 #include "chrome/browser/shell_integration.h" | 15 #include "chrome/browser/shell_integration.h" |
| 12 #include "chrome/common/pref_names.h" | |
| 13 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 14 #include "chrome/grit/chromium_strings.h" | 17 #include "chrome/grit/chromium_strings.h" |
| 15 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 16 #include "chrome/grit/locale_settings.h" | 19 #include "chrome/grit/locale_settings.h" |
| 17 #include "chrome/installer/util/google_update_settings.h" | |
| 18 #include "components/crash/content/app/breakpad_linux.h" | 20 #include "components/crash/content/app/breakpad_linux.h" |
| 19 #include "components/metrics/metrics_pref_names.h" | |
| 20 #include "grit/components_strings.h" | 21 #include "grit/components_strings.h" |
| 21 #include "ui/aura/env.h" | 22 #include "ui/aura/env.h" |
| 22 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 23 #include "ui/aura/window_event_dispatcher.h" | 24 #include "ui/aura/window_event_dispatcher.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/views/controls/button/checkbox.h" | 26 #include "ui/views/controls/button/checkbox.h" |
| 26 #include "ui/views/controls/link.h" | 27 #include "ui/views/controls/link.h" |
| 27 #include "ui/views/layout/grid_layout.h" | 28 #include "ui/views/layout/grid_layout.h" |
| 28 #include "ui/views/layout/layout_constants.h" | 29 #include "ui/views/layout/layout_constants.h" |
| 29 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 30 #include "ui/views/window/dialog_delegate.h" | 31 #include "ui/views/window/dialog_delegate.h" |
| 31 | 32 |
| 32 #if defined(GOOGLE_CHROME_BUILD) | 33 using views::GridLayout; |
| 33 #include "chrome/browser/browser_process.h" | |
| 34 #include "components/prefs/pref_service.h" | |
| 35 #endif | |
| 36 | 34 |
| 37 using views::GridLayout; | 35 namespace { |
| 36 |
| 37 void InitCrashReporterIfEnabled(bool enabled) { |
| 38 if (enabled) |
| 39 breakpad::InitCrashReporter(std::string()); |
| 40 } |
| 41 |
| 42 } // namespace |
| 38 | 43 |
| 39 namespace first_run { | 44 namespace first_run { |
| 40 | 45 |
| 41 bool ShowFirstRunDialog(Profile* profile) { | 46 bool ShowFirstRunDialog(Profile* profile) { |
| 42 return FirstRunDialog::Show(profile); | 47 return FirstRunDialog::Show(profile); |
| 43 } | 48 } |
| 44 | 49 |
| 45 } // namespace first_run | 50 } // namespace first_run |
| 46 | 51 |
| 47 // static | 52 // static |
| 48 bool FirstRunDialog::Show(Profile* profile) { | 53 bool FirstRunDialog::Show(Profile* profile) { |
| 49 bool dialog_shown = false; | 54 bool dialog_shown = false; |
| 50 | 55 |
| 51 #if defined(GOOGLE_CHROME_BUILD) | 56 #if defined(GOOGLE_CHROME_BUILD) |
| 52 // If the metrics reporting is managed, we won't ask. | 57 // If the metrics reporting is managed, we won't ask. |
| 53 const PrefService::Preference* metrics_reporting_pref = | 58 if (!IsMetricsReportingPolicyManaged()) { |
| 54 g_browser_process->local_state()->FindPreference( | |
| 55 metrics::prefs::kMetricsReportingEnabled); | |
| 56 | |
| 57 if (!metrics_reporting_pref || | |
| 58 !metrics_reporting_pref->IsManaged()) { | |
| 59 FirstRunDialog* dialog = new FirstRunDialog(profile); | 59 FirstRunDialog* dialog = new FirstRunDialog(profile); |
| 60 views::DialogDelegate::CreateDialogWidget(dialog, NULL, NULL)->Show(); | 60 views::DialogDelegate::CreateDialogWidget(dialog, NULL, NULL)->Show(); |
| 61 | 61 |
| 62 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | 62 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| 63 base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop); | 63 base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop); |
| 64 base::RunLoop run_loop; | 64 base::RunLoop run_loop; |
| 65 dialog->quit_runloop_ = run_loop.QuitClosure(); | 65 dialog->quit_runloop_ = run_loop.QuitClosure(); |
| 66 run_loop.Run(); | 66 run_loop.Run(); |
| 67 dialog_shown = true; | 67 dialog_shown = true; |
| 68 } | 68 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 views::View* FirstRunDialog::CreateExtraView() { | 109 views::View* FirstRunDialog::CreateExtraView() { |
| 110 views::Link* link = new views::Link(l10n_util::GetStringUTF16( | 110 views::Link* link = new views::Link(l10n_util::GetStringUTF16( |
| 111 IDS_LEARN_MORE)); | 111 IDS_LEARN_MORE)); |
| 112 link->set_listener(this); | 112 link->set_listener(this); |
| 113 return link; | 113 return link; |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool FirstRunDialog::Accept() { | 116 bool FirstRunDialog::Accept() { |
| 117 GetWidget()->Hide(); | 117 GetWidget()->Hide(); |
| 118 | 118 |
| 119 if (report_crashes_ && report_crashes_->checked()) { | 119 InitiateMetricsReportingChange(report_crashes_->checked(), |
| 120 if (GoogleUpdateSettings::SetCollectStatsConsent(true)) | 120 base::Bind(&InitCrashReporterIfEnabled)); |
| 121 breakpad::InitCrashReporter(std::string()); | |
| 122 } else { | |
| 123 GoogleUpdateSettings::SetCollectStatsConsent(false); | |
| 124 } | |
| 125 | 121 |
| 126 if (make_default_ && make_default_->checked()) | 122 if (make_default_->checked()) |
| 127 shell_integration::SetAsDefaultBrowser(); | 123 shell_integration::SetAsDefaultBrowser(); |
| 128 | 124 |
| 129 Done(); | 125 Done(); |
| 130 return true; | 126 return true; |
| 131 } | 127 } |
| 132 | 128 |
| 133 int FirstRunDialog::GetDialogButtons() const { | 129 int FirstRunDialog::GetDialogButtons() const { |
| 134 return ui::DIALOG_BUTTON_OK; | 130 return ui::DIALOG_BUTTON_OK; |
| 135 } | 131 } |
| 136 | 132 |
| 137 void FirstRunDialog::WindowClosing() { | 133 void FirstRunDialog::WindowClosing() { |
| 138 first_run::SetShouldShowWelcomePage(); | 134 first_run::SetShouldShowWelcomePage(); |
| 139 Done(); | 135 Done(); |
| 140 } | 136 } |
| 141 | 137 |
| 142 void FirstRunDialog::LinkClicked(views::Link* source, int event_flags) { | 138 void FirstRunDialog::LinkClicked(views::Link* source, int event_flags) { |
| 143 platform_util::OpenExternal(profile_, GURL(chrome::kLearnMoreReportingURL)); | 139 platform_util::OpenExternal(profile_, GURL(chrome::kLearnMoreReportingURL)); |
| 144 } | 140 } |
| OLD | NEW |