summaryrefslogtreecommitdiffstats
path: root/chrome/browser/google_update_settings_mac.mm
blob: 95ca90e2ad6c62382a8c7abcde465570f6f481fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// 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 false.
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 false;
  }

  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) {
  NSString* collect_stats_key = base::SysWideToNSString(
        google_update::kRegUsageStatsField);
  NSUserDefaults* std_defaults = [NSUserDefaults standardUserDefaults];
  BOOL val_to_store = consented ? YES : NO;
  [std_defaults setBool:val_to_store forKey:collect_stats_key];
  return [std_defaults synchronize];
}

// 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;
}