summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-28 20:23:06 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-28 20:23:06 +0000
commit1e7377df1449c4e543a50c8a8a1425599c8425f7 (patch)
tree6e8ee3adcba66e4a043e91e91e0217467682a7fd /chrome/browser
parent34cf340da15aceffd59c3d05e0de2a3bc5174a2d (diff)
downloadchromium_src-1e7377df1449c4e543a50c8a8a1425599c8425f7.zip
chromium_src-1e7377df1449c4e543a50c8a8a1425599c8425f7.tar.gz
chromium_src-1e7377df1449c4e543a50c8a8a1425599c8425f7.tar.bz2
Respect Linux user prefs with regards to crash reporting.
This involves implementing GoogleUpdateSettings::[GS]etCollectStatsConsent, and a whole lot of refactoring. BUG=none TEST=delete config dir, run official Linux build, don't enable crash reporting, crash browser -> no crash reporting. Review URL: http://codereview.chromium.org/115808 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17104 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser_main.cc33
-rw-r--r--chrome/browser/first_run_gtk.cc16
-rw-r--r--chrome/browser/google_update_settings_linux.cc41
-rw-r--r--chrome/browser/google_update_settings_linux_unittest.cc23
4 files changed, 86 insertions, 27 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 5b955eb..dd0e825 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -4,11 +4,6 @@
#include "build/build_config.h"
-#if defined(OS_WIN)
-#include <windows.h>
-#include <commctrl.h>
-#endif
-
#include <algorithm>
#include "app/l10n_util.h"
@@ -51,6 +46,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
#include "chrome/common/result_codes.h"
+#include "chrome/installer/util/google_update_settings.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/net_resources.h"
@@ -77,6 +73,7 @@
#if defined(OS_WIN)
#include <windows.h>
+#include <commctrl.h>
#include <shellapi.h>
#include "app/win_util.h"
@@ -111,10 +108,6 @@
#include "chrome/common/gtk_util.h"
#endif
-#if defined(OS_WIN) || defined(OS_MACOSX)
-#include "chrome/installer/util/google_update_settings.h"
-#endif // OS_WIN || OS_MACOSX
-
namespace Platform {
void WillInitializeMainMessageLoop(const CommandLine & command_line);
@@ -252,10 +245,6 @@ int BrowserMain(const MainFunctionParams& parameters) {
CHECK(sigaction(SIGCHLD, &action, NULL) == 0);
#endif
-#if defined(OS_LINUX)
- EnableCrashDumping();
-#endif
-
// Do platform-specific things (such as finishing initializing Cocoa)
// prior to instantiating the message loop. This could be turned into a
// broadcast notification.
@@ -340,10 +329,10 @@ int BrowserMain(const MainFunctionParams& parameters) {
local_state->RegisterStringPref(prefs::kApplicationLocale, L"");
local_state->RegisterBooleanPref(prefs::kMetricsReportingEnabled, false);
-#if defined(OS_MACOSX)
- // On Mac OS X we display the first run dialog as early as possible, so we can
- // get the stats enabled.
- // TODO:
+#if defined(OS_POSIX)
+ // On Mac OS X / Linux we display the first run dialog as early as possible,
+ // so we can get the stats enabled.
+ // TODO(port):
// We check the kNoFirstRun command line switch explicitly here since the
// early placement of this block happens before that's factored into
// first_run_ui_bypass, we probably want to move that block up
@@ -355,7 +344,7 @@ int BrowserMain(const MainFunctionParams& parameters) {
Profile* profile = NULL;
OpenFirstRunDialog(profile, &process_singleton);
}
-#endif // OS_MACOSX
+#endif // OS_POSIX
// During first run we read the google_update registry key to find what
// language the user selected when downloading the installer. This
@@ -547,12 +536,12 @@ int BrowserMain(const MainFunctionParams& parameters) {
gtk_util::InitRCStyles();
#endif
- // TODO: This block of code should probably be used on all platforms!
- // On Mac OS X we display this dialog before setting the value of
+ // TODO(port): This block of code should probably be used on all platforms!
+ // On Mac OS X / Linux we display this dialog before setting the value of
// kMetricsReportingEnabled, so we display this dialog much earlier.
// On Windows a download is tagged with stats enabled/disabled so the UI
// can be displayed later in the startup process.
-#if !defined(OS_MACOSX)
+#if !defined(OS_POSIX)
// Show the First Run UI if this is the first time Chrome has been run on
// this computer, or we're being compelled to do so by a command line flag.
// Note that this be done _after_ the PrefService is initialized and all
@@ -561,7 +550,7 @@ int BrowserMain(const MainFunctionParams& parameters) {
if (is_first_run && !first_run_ui_bypass) {
OpenFirstRunDialog(profile, &process_singleton);
}
-#endif // OS_MACOSX
+#endif // OS_POSIX
// Sets things up so that if we crash from this point on, a dialog will
// popup asking the user to restart chrome. It is done this late to avoid
diff --git a/chrome/browser/first_run_gtk.cc b/chrome/browser/first_run_gtk.cc
index 8543780..5447a3f 100644
--- a/chrome/browser/first_run_gtk.cc
+++ b/chrome/browser/first_run_gtk.cc
@@ -4,10 +4,12 @@
#include "chrome/browser/first_run.h"
+#include "chrome/app/breakpad_linux.h"
// We need to reach through the browser process to tweak the metrics flag.
#include "chrome/browser/browser_process.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
+#include "chrome/installer/util/google_update_settings.h"
#include "base/message_loop.h"
@@ -94,11 +96,15 @@ void OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton) {
MessageLoop::current()->Run();
// End of above TODO.
- if (response == GTK_RESPONSE_ACCEPT &&
- gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check))) {
- // They opted in.
- g_browser_process->local_state()->SetBoolean(
- prefs::kMetricsReportingEnabled, true);
+ if (response == GTK_RESPONSE_ACCEPT) {
+ if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check))) {
+ // They opted in.
+ if (GoogleUpdateSettings::SetCollectStatsConsent(true)) {
+ InitCrashReporter();
+ }
+ } else {
+ GoogleUpdateSettings::SetCollectStatsConsent(false);
+ }
}
gtk_widget_destroy(dialog);
diff --git a/chrome/browser/google_update_settings_linux.cc b/chrome/browser/google_update_settings_linux.cc
new file mode 100644
index 0000000..f7ae4b5
--- /dev/null
+++ b/chrome/browser/google_update_settings_linux.cc
@@ -0,0 +1,41 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/installer/util/google_update_settings.h"
+
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "chrome/common/chrome_paths.h"
+
+// File name used in the user data dir to indicate consent.
+static const char kConsentToSendStats[] = "Consent To Send Stats";
+
+// static
+bool GoogleUpdateSettings::GetCollectStatsConsent() {
+ FilePath consent_file;
+ PathService::Get(chrome::DIR_USER_DATA, &consent_file);
+ consent_file = consent_file.Append(kConsentToSendStats);
+ return file_util::PathExists(consent_file);
+}
+
+// static
+bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) {
+ FilePath consent_dir;
+ PathService::Get(chrome::DIR_USER_DATA, &consent_dir);
+ if (!file_util::DirectoryExists(consent_dir))
+ return false;
+
+ FilePath consent_file = consent_dir.AppendASCII(kConsentToSendStats);
+ if (consented)
+ return file_util::WriteFile(consent_file, "", 0) == 0;
+ else
+ return file_util::Delete(consent_file, false);
+}
+
+// static
+bool GoogleUpdateSettings::GetLanguage(std::wstring* language) {
+ NOTIMPLEMENTED();
+ return false;
+}
diff --git a/chrome/browser/google_update_settings_linux_unittest.cc b/chrome/browser/google_update_settings_linux_unittest.cc
new file mode 100644
index 0000000..35f956a
--- /dev/null
+++ b/chrome/browser/google_update_settings_linux_unittest.cc
@@ -0,0 +1,23 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/installer/util/google_update_settings.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+class GoogleUpdateTest : public PlatformTest {
+};
+
+TEST_F(GoogleUpdateTest, StatsConstent) {
+ // Stats are off by default.
+ EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsent());
+
+ // Stats reporting is ON.
+ EXPECT_TRUE(GoogleUpdateSettings::SetCollectStatsConsent(true));
+ EXPECT_TRUE(GoogleUpdateSettings::GetCollectStatsConsent());
+
+ // Stats reporting is OFF.
+ EXPECT_TRUE(GoogleUpdateSettings::SetCollectStatsConsent(false));
+ EXPECT_FALSE(GoogleUpdateSettings::GetCollectStatsConsent());
+}