File: install_prefs_helper.cc

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 (96 lines) | stat: -rw-r--r-- 3,642 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
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "extensions/browser/install_prefs_helper.h"

#include "base/time/time.h"
#include "extensions/browser/extension_pref_names.h"
#include "extensions/browser/extension_prefs.h"

namespace extensions {

namespace {

// An installation parameter bundled with an extension.
constexpr PrefMap kInstallParam = {kPrefInstallParameter, PrefType::kString,
                                   PrefScope::kExtensionSpecific};

// A preference that indicates whether the extension was installed from
// the web store.
constexpr PrefMap kFromWebStore = {kPrefFromWebStore, PrefType::kBool,
                                   PrefScope::kExtensionSpecific};

// A preference that indicates whether the extension was installed as a
// default app.
constexpr PrefMap kWasInstalledByDefault = {
    kPrefWasInstalledByDefault, PrefType::kBool, PrefScope::kExtensionSpecific};

// A preference that indicates whether the extension was installed as an
// OEM app.
constexpr PrefMap kWasInstalledByOem = {kPrefWasInstalledByOem, PrefType::kBool,
                                        PrefScope::kExtensionSpecific};

// A preference that indicates when an extension was first installed.
// This preference is created when an extension is installed and deleted when
// it is removed. It is NOT updated when the extension is updated.
constexpr PrefMap kFirstInstallTime = {kPrefFirstInstallTime, PrefType::kTime,
                                       PrefScope::kExtensionSpecific};

// A preference that indicates when an extension was last installed/updated.
constexpr PrefMap kLastUpdateTime = {kPrefLastUpdateTime, PrefType::kTime,
                                     PrefScope::kExtensionSpecific};

bool ReadPrefAsBooleanOrFalse(const ExtensionPrefs* prefs,
                              const ExtensionId& extension_id,
                              const PrefMap& key) {
  bool value = false;
  if (prefs->ReadPrefAsBoolean(extension_id, key, &value)) {
    return value;
  }

  return false;
}

}  // namespace

std::string GetInstallParam(const ExtensionPrefs* prefs,
                            const ExtensionId& extension_id) {
  std::string value;
  // If this fails because the pref isn't set, we return an empty string.
  prefs->ReadPrefAsString(extension_id, kInstallParam, &value);
  return value;
}

void SetInstallParam(ExtensionPrefs* prefs,
                     const ExtensionId& extension_id,
                     std::string value) {
  prefs->SetStringPref(extension_id, kInstallParam, std::move(value));
}

bool IsFromWebStore(const ExtensionPrefs* prefs,
                    const ExtensionId& extension_id) {
  return ReadPrefAsBooleanOrFalse(prefs, extension_id, kFromWebStore);
}

bool WasInstalledByDefault(const ExtensionPrefs* prefs,
                           const ExtensionId& extension_id) {
  return ReadPrefAsBooleanOrFalse(prefs, extension_id, kWasInstalledByDefault);
}

bool WasInstalledByOem(const ExtensionPrefs* prefs,
                       const ExtensionId& extension_id) {
  return ReadPrefAsBooleanOrFalse(prefs, extension_id, kWasInstalledByOem);
}

base::Time GetFirstInstallTime(const ExtensionPrefs* prefs,
                               const ExtensionId& extension_id) {
  return prefs->ReadPrefAsTime(extension_id, kFirstInstallTime);
}

base::Time GetLastUpdateTime(const ExtensionPrefs* prefs,
                             const ExtensionId& extension_id) {
  return prefs->ReadPrefAsTime(extension_id, kLastUpdateTime);
}

}  // namespace extensions