Skip to content
Snippets Groups Projects
Commit 3090eeb5 authored by jeremy@chromium.org's avatar jeremy@chromium.org
Browse files

Hook up stats reporting via default system on OS X.

Allow enabling/disabling stats via user defaults.
Fix breakpad to read from global stats setting.

To disable stats, type the following in the terminal:
defaults write com.google.Chrome usagestats -bool NO

BUG=12046

Review URL: http://codereview.chromium.org/113549

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16333 0039d316-1c4b-4281-b951-d872f2087c98
parent 1b4d44eb
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@
#import "base/scoped_nsautorelease_pool.h"
#include "base/sys_string_conversions.h"
#import "breakpad/src/client/mac/Framework/Breakpad.h"
#include "chrome/installer/util/google_update_settings.h"
#if !defined(GOOGLE_CHROME_BUILD)
// If we aren't compiling as a branded build, then add dummy versions of the
......@@ -41,12 +42,6 @@ namespace {
BreakpadRef gBreakpadRef = NULL;
// Did the user optin for reporting stats.
bool IsStatsReportingAllowed() {
NOTIMPLEMENTED();
return true;
}
} // namespace
bool IsCrashReporterEnabled() {
......@@ -67,7 +62,7 @@ void InitCrashReporter() {
// Check for Send stats preference. If preference is not specifically turned
// on then disable crash reporting.
if (!IsStatsReportingAllowed()) {
if (!GoogleUpdateSettings::GetCollectStatsConsent()) {
LOG(WARNING) << "Breakpad disabled";
return;
}
......
......@@ -90,7 +90,6 @@
#include "chrome/browser/rlz/rlz.h"
#include "chrome/browser/views/user_data_dir_dialog.h"
#include "chrome/common/env_vars.h"
#include "chrome/installer/util/google_update_settings.h"
#include "chrome/installer/util/helper.h"
#include "chrome/installer/util/install_util.h"
#include "chrome/installer/util/shell_util.h"
......@@ -108,6 +107,10 @@
#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);
......
// 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 <Foundation/Foundation.h>
#include "chrome/installer/util/google_update_settings.h"
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/sys_string_conversions.h"
#include "chrome/installer/util/google_update_constants.h"
namespace google_update {
// This is copied from chrome/installer/util/google_update_constants.cc
// Reasons duplication acceptable:
// 1. At the time of this writing, this code is a one-off for the dev release.
// 2. The value of this constant is unlikely to change and even if it does
// that negates the point of reusing it in the Mac version.
// 3. To make x-platform usage fo the constants in google_update_constants.cc
// we probably want to split them up into windows-only and x-platform strings.
const wchar_t kRegUsageStatsField[] = L"usagestats";
// Declared in a public namespace for testing purposes.
// If pref not set, assume true.
bool GetCollectStatsConsentFromDictionary(NSDictionary* dict) {
NSString* collect_stats_key = base::SysWideToNSString(
google_update::kRegUsageStatsField);
NSNumber* val = [dict objectForKey:collect_stats_key];
if (![val respondsToSelector:@selector(boolValue)]) {
return true;
}
return ([val boolValue] == YES);
}
} // namespace google_update
// static
bool GoogleUpdateSettings::GetCollectStatsConsent() {
// TODO(mac): This value should be read from the Chrome prefs setting.
// For Dev-relesae purposes, we read this value from the user's
// defaults. This allows easy control of the setting from the terminal.
// To turn stat reporting off, run the following command from the terminal:
// $ defaults write com.google.Chrome usagestats -bool 'NO'
NSUserDefaults* std_defaults = [NSUserDefaults standardUserDefaults];
return google_update::GetCollectStatsConsentFromDictionary(
[std_defaults dictionaryRepresentation]);
}
// static
bool GoogleUpdateSettings::SetCollectStatsConsent(bool consented) {
NOTIMPLEMENTED();
return false;
}
// static
bool GoogleUpdateSettings::GetBrowser(std::wstring* browser) {
NOTIMPLEMENTED();
return false;
}
// static
bool GoogleUpdateSettings::GetLanguage(std::wstring* language) {
NOTIMPLEMENTED();
return false;
}
// static
bool GoogleUpdateSettings::GetBrand(std::wstring* brand) {
NOTIMPLEMENTED();
return false;
}
// static
bool GoogleUpdateSettings::GetReferral(std::wstring* referral) {
NOTIMPLEMENTED();
return false;
}
// static
bool GoogleUpdateSettings::ClearReferral() {
NOTIMPLEMENTED();
return false;
}
// 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 <Foundation/Foundation.h>
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/sys_string_conversions.h"
#include "chrome/installer/util/google_update_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
namespace google_update {
bool GetCollectStatsConsentFromDictionary(NSDictionary* dict);
} // namespace google_update
class GoogleUpdateTest : public PlatformTest {
};
TEST_F(GoogleUpdateTest, StatsConstent) {
using google_update::GetCollectStatsConsentFromDictionary;
// Stats are on by default.
NSDictionary* empty_dict = [NSDictionary dictionary];
ASSERT_TRUE(GetCollectStatsConsentFromDictionary(empty_dict));
NSString* collect_stats_key = base::SysWideToNSString(
google_update::kRegUsageStatsField);
// Stats reporting is ON.
NSNumber* stats_enabled = [NSNumber numberWithBool:YES];
NSDictionary* enabled_dict = [NSDictionary
dictionaryWithObject:stats_enabled
forKey:collect_stats_key];
ASSERT_TRUE(GetCollectStatsConsentFromDictionary(enabled_dict));
// Stats reporting is OFF.
NSNumber* stats_disabled = [NSNumber numberWithBool:NO];
NSDictionary* disabled_dict = [NSDictionary
dictionaryWithObject:stats_disabled
forKey:collect_stats_key];
ASSERT_FALSE(GetCollectStatsConsentFromDictionary(disabled_dict));
// Check that we fail gracefully if an object of the wrong type is present.
NSDictionary* wrong_type_dict = [NSDictionary
dictionaryWithObject:empty_dict
forKey:collect_stats_key];
ASSERT_TRUE(GetCollectStatsConsentFromDictionary(wrong_type_dict));
}
......@@ -903,6 +903,7 @@
'browser/gtk/tabs/tab_strip_gtk.h',
'browser/gtk/toolbar_star_toggle_gtk.cc',
'browser/gtk/toolbar_star_toggle_gtk.h',
'browser/google_update_settings_mac.mm',
'browser/hang_monitor/hung_plugin_action.cc',
'browser/hang_monitor/hung_plugin_action.h',
'browser/hang_monitor/hung_window_detector.cc',
......@@ -2700,6 +2701,7 @@
'browser/extensions/test_extension_loader.cc',
'browser/extensions/user_script_master_unittest.cc',
'browser/google_url_tracker_unittest.cc',
'browser/google_update_settings_mac_unittest.mm',
'browser/gtk/bookmark_editor_gtk_unittest.cc',
'browser/gtk/go_button_gtk_unittest.cc',
'browser/gtk/tabs/tab_renderer_gtk_unittest.cc',
......
......@@ -50,6 +50,7 @@ class Message;
//---------------------------------------------------------------------------
// These stubs are for Browser_main()
#if defined(OS_LINUX)
class GoogleUpdateSettings {
public:
static bool GetCollectStatsConsent() {
......@@ -83,6 +84,7 @@ class GoogleUpdateSettings {
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(GoogleUpdateSettings);
};
#endif // OS_LINUX
void OpenFirstRunDialog(Profile* profile, ProcessSingleton* process_singleton);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment