File: updater_state_mac.mm

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (126 lines) | stat: -rw-r--r-- 4,176 bytes parent folder | download | duplicates (6)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/component_updater/updater_state.h"

#import <Foundation/Foundation.h>

#include "base/apple/bridging.h"
#include "base/apple/foundation_util.h"
#include "base/enterprise_util.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/version.h"

namespace component_updater {

namespace {

const base::FilePath::CharType kKeystonePlist[] =
    FILE_PATH_LITERAL("Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/"
                      "Contents/Info.plist");

// Gets a value from the updater settings.
template <class T>
T* GetUpdaterSettingsValue(NSString* value_name) {
  id plist_type = CFBridgingRelease(
      CFPreferencesCopyAppValue(base::apple::NSToCFPtrCast(value_name),
                                CFSTR("com.google.Keystone.Agent")));

  return base::apple::ObjCCastStrict<T>(plist_type);
}

base::Time GetUpdaterSettingsTime(NSString* value_name) {
  NSDate* date = GetUpdaterSettingsValue<NSDate>(value_name);
  base::Time result =
      base::Time::FromCFAbsoluteTime([date timeIntervalSinceReferenceDate]);

  return result;
}

base::Version GetVersionFromPlist(const base::FilePath& info_plist) {
  @autoreleasepool {
    NSData* data = [NSData
        dataWithContentsOfFile:base::apple::FilePathToNSString(info_plist)];
    if ([data length] == 0) {
      return base::Version();
    }
    NSDictionary* all_keys =
        base::apple::ObjCCastStrict<NSDictionary>([NSPropertyListSerialization
            propertyListWithData:data
                         options:NSPropertyListImmutable
                          format:nil
                           error:nil]);
    if (all_keys == nil) {
      return base::Version();
    }
    CFStringRef version = base::apple::GetValueFromDictionary<CFStringRef>(
        base::apple::NSToCFPtrCast(all_keys), kCFBundleVersionKey);
    if (version == nullptr) {
      return base::Version();
    }
    return base::Version(base::SysCFStringRefToUTF8(version));
  }
}

}  // namespace

std::string UpdaterState::StateReaderKeystone::GetUpdaterName() const {
  return std::string("Keystone");
}

base::Version UpdaterState::StateReaderKeystone::GetUpdaterVersion(
    bool /*is_machine*/) const {
  // System Keystone takes precedence over user one, so check this one first.
  base::FilePath local_library;
  if (base::apple::GetLocalDirectory(NSLibraryDirectory, &local_library)) {
    base::FilePath system_bundle_plist = local_library.Append(kKeystonePlist);
    base::Version system_keystone = GetVersionFromPlist(system_bundle_plist);
    if (system_keystone.IsValid()) {
      return system_keystone;
    }
  }
  base::FilePath user_bundle_plist =
      base::apple::GetUserLibraryPath().Append(kKeystonePlist);
  return GetVersionFromPlist(user_bundle_plist);
}

base::Time UpdaterState::StateReaderKeystone::GetUpdaterLastStartedAU(
    bool /*is_machine*/) const {
  return GetUpdaterSettingsTime(@"lastCheckStartDate");
}

base::Time UpdaterState::StateReaderKeystone::GetUpdaterLastChecked(
    bool /*is_machine*/) const {
  return GetUpdaterSettingsTime(@"lastServerCheckDate");
}

bool UpdaterState::StateReaderKeystone::IsAutoupdateCheckEnabled() const {
  return UpdaterState::IsAutoupdateCheckEnabled();
}

int UpdaterState::StateReaderKeystone::GetUpdatePolicy() const {
  return UpdaterState::GetUpdatePolicy();
}

update_client::CategorizedError
UpdaterState::StateReaderKeystone::GetLastUpdateCheckError() const {
  return {};
}

bool UpdaterState::IsAutoupdateCheckEnabled() {
  // Auto-update check period override (in seconds).
  // Applies only to older versions of Keystone.
  Boolean foundValue = false;
  long value = CFPreferencesGetAppIntegerValue(
      CFSTR("checkInterval"), CFSTR("com.google.Keystone.Agent"), &foundValue);
  return !foundValue || (0 < value && value < (24 * 60 * 60));
}

int UpdaterState::GetUpdatePolicy() {
  return -1;  // Keystone does not support update policies.
}

}  // namespace component_updater