File: hyphenation_component_installer.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 (155 lines) | stat: -rw-r--r-- 5,178 bytes parent folder | download | duplicates (3)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright 2020 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/hyphenation_component_installer.h"

#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/task/sequenced_task_runner.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"

namespace {

// The SHA256 of the SubjectPublicKeyInfo used to sign the extension.
// The extension id is: jamhcnnkihinmdlkakkaopbjbbcngflc
constexpr uint8_t kHyphenationPublicKeySHA256[32] = {
    0x90, 0xc7, 0x2d, 0xda, 0x87, 0x8d, 0xc3, 0xba, 0x0a, 0xa0, 0xef,
    0x19, 0x11, 0x2d, 0x65, 0xb2, 0x04, 0xfc, 0x2e, 0x3e, 0xbb, 0x35,
    0x85, 0xae, 0x64, 0xca, 0x07, 0x61, 0x15, 0x12, 0x9e, 0xbc};

constexpr char kHyphenationManifestName[] = "Hyphenation";

constexpr base::FilePath::CharType kHyphenationRelativeInstallDir[] =
    FILE_PATH_LITERAL("hyphen-data");

class HyphenationDirectory {
 public:
  static HyphenationDirectory* Get() {
    static base::NoDestructor<HyphenationDirectory> hyphenation_directory;
    return hyphenation_directory.get();
  }

  void Get(base::OnceCallback<void(const base::FilePath&)> callback) {
    DVLOG(1) << __func__;
    DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
    callbacks_.push_back(std::move(callback));
    if (!dir_.empty()) {
      FireCallbacks();
    }
  }

  void Set(const base::FilePath& new_dir) {
    DVLOG(1) << __func__ << "\"" << new_dir << "\"";
    DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
    CHECK(!new_dir.empty());
    if (new_dir == dir_) {
      return;
    }
    dir_ = new_dir;
    FireCallbacks();
  }

 private:
  void FireCallbacks() {
    DVLOG(1) << __func__ << " \"" << dir_
             << "\", callbacks=" << callbacks_.size();
    DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
    CHECK(!dir_.empty());
    std::vector<base::OnceCallback<void(const base::FilePath&)>> callbacks;
    std::swap(callbacks, callbacks_);
    for (base::OnceCallback<void(const base::FilePath&)>& callback :
         callbacks) {
      base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
          FROM_HERE, base::BindOnce(std::move(callback), dir_));
    }
  }

  base::FilePath dir_;
  std::vector<base::OnceCallback<void(const base::FilePath&)>> callbacks_;
};

}  // namespace

namespace component_updater {

HyphenationComponentInstallerPolicy::HyphenationComponentInstallerPolicy() =
    default;

HyphenationComponentInstallerPolicy::~HyphenationComponentInstallerPolicy() =
    default;

bool HyphenationComponentInstallerPolicy::
    SupportsGroupPolicyEnabledComponentUpdates() const {
  return true;
}

bool HyphenationComponentInstallerPolicy::RequiresNetworkEncryption() const {
  // Update checks and pings associated with this component do not require
  // confidentiality, since the component is identical for all users.
  return false;
}

update_client::CrxInstaller::Result
HyphenationComponentInstallerPolicy::OnCustomInstall(
    const base::Value::Dict& manifest,
    const base::FilePath& install_dir) {
  return update_client::CrxInstaller::Result(0);  // Nothing custom here.
}

void HyphenationComponentInstallerPolicy::OnCustomUninstall() {}

void HyphenationComponentInstallerPolicy::ComponentReady(
    const base::Version& version,
    const base::FilePath& install_dir,
    base::Value::Dict manifest) {
  VLOG(1) << "Hyphenation Component ready, version " << version.GetString()
          << " in " << install_dir.value();
  HyphenationDirectory* hyphenation_directory = HyphenationDirectory::Get();
  hyphenation_directory->Set(install_dir);
}

// Called during startup and installation before ComponentReady().
bool HyphenationComponentInstallerPolicy::VerifyInstallation(
    const base::Value::Dict& manifest,
    const base::FilePath& install_dir) const {
  return true;
}

base::FilePath HyphenationComponentInstallerPolicy::GetRelativeInstallDir()
    const {
  return base::FilePath(kHyphenationRelativeInstallDir);
}

void HyphenationComponentInstallerPolicy::GetHash(
    std::vector<uint8_t>* hash) const {
  hash->assign(std::begin(kHyphenationPublicKeySHA256),
               std::end(kHyphenationPublicKeySHA256));
}

std::string HyphenationComponentInstallerPolicy::GetName() const {
  return kHyphenationManifestName;
}

update_client::InstallerAttributes
HyphenationComponentInstallerPolicy::GetInstallerAttributes() const {
  return update_client::InstallerAttributes();
}

// static
void HyphenationComponentInstallerPolicy::GetHyphenationDictionary(
    base::OnceCallback<void(const base::FilePath&)> callback) {
  HyphenationDirectory* hyphenation_directory = HyphenationDirectory::Get();
  hyphenation_directory->Get(std::move(callback));
}

void RegisterHyphenationComponent(ComponentUpdateService* cus) {
  VLOG(1) << "Registering Hyphenation component.";
  auto installer = base::MakeRefCounted<ComponentInstaller>(
      std::make_unique<HyphenationComponentInstallerPolicy>());
  installer->Register(cus, base::OnceClosure());
}

}  // namespace component_updater