Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: chrome/browser/component_updater/cld_component_installer.cc

Issue 2034413003: Delete the non-static CLD data source logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase to latest master Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/component_updater/cld_component_installer.h"
6
7 #include <string>
8 #include <utility>
9 #include <vector>
10
11 #include "base/bind.h"
12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h"
14 #include "base/lazy_instance.h"
15 #include "base/logging.h"
16 #include "base/macros.h"
17 #include "base/path_service.h"
18 #include "components/component_updater/component_updater_paths.h"
19 #include "components/translate/content/browser/browser_cld_data_provider.h"
20 #include "components/translate/content/browser/browser_cld_data_provider_factory .h"
21 #include "components/translate/content/common/cld_data_source.h"
22 #include "content/public/browser/browser_thread.h"
23 #include "net/ssl/ssl_config_service.h"
24
25 using component_updater::ComponentUpdateService;
26
27 namespace {
28 // TODO(andrewhayden): Make the data file path into a gyp/gn define
29 // If you change this, also update component_cld_data_harness.cc
30 // and cld_component_installer_unittest.cc accordingly!
31 const base::FilePath::CharType kCldDataFileName[] =
32 FILE_PATH_LITERAL("cld2_data.bin");
33
34 // Tracks the last value seen in SetLatestCldDataFile.
35 base::LazyInstance<base::FilePath>::Leaky g_latest_cld_data_file =
36 LAZY_INSTANCE_INITIALIZER;
37 } // namespace
38
39 namespace component_updater {
40
41 // The SHA256 of the SubjectPublicKeyInfo used to sign the extension.
42 // The extension id is: dpedmmgabcgnikllifiidmijgoiihfgf
43 const uint8_t kPublicKeySHA256[32] = {
44 0x3f, 0x43, 0xcc, 0x60, 0x12, 0x6d, 0x8a, 0xbb,
45 0x85, 0x88, 0x3c, 0x89, 0x6e, 0x88, 0x75, 0x65,
46 0xb9, 0x46, 0x09, 0xe8, 0xca, 0x92, 0xdd, 0x82,
47 0x4e, 0x6d, 0x0e, 0xe6, 0x79, 0x8a, 0x87, 0xf5
48 };
49
50 const char kCldManifestName[] = "CLD2 Data";
51
52 CldComponentInstallerTraits::CldComponentInstallerTraits() {
53 }
54
55 bool CldComponentInstallerTraits::CanAutoUpdate() const {
56 return true;
57 }
58
59 bool CldComponentInstallerTraits::RequiresNetworkEncryption() const {
60 return false;
61 }
62
63 bool CldComponentInstallerTraits::OnCustomInstall(
64 const base::DictionaryValue& manifest,
65 const base::FilePath& install_dir) {
66 return true; // Nothing custom here.
67 }
68
69 base::FilePath CldComponentInstallerTraits::GetInstalledPath(
70 const base::FilePath& base) {
71 // Currently, all platforms have the file at the same location because there
72 // is no binary difference in the generated file on any supported platform.
73 // NB: This may change when 64-bit is officially supported.
74 return base.Append(FILE_PATH_LITERAL("_platform_specific"))
75 .Append(FILE_PATH_LITERAL("all"))
76 .Append(kCldDataFileName);
77 }
78
79 void CldComponentInstallerTraits::ComponentReady(
80 const base::Version& version,
81 const base::FilePath& path,
82 std::unique_ptr<base::DictionaryValue> manifest) {
83 VLOG(1) << "Component ready, version " << version.GetString() << " in "
84 << path.value();
85 SetLatestCldDataFile(GetInstalledPath(path));
86 }
87
88 bool CldComponentInstallerTraits::VerifyInstallation(
89 const base::DictionaryValue& manifest,
90 const base::FilePath& install_dir) const {
91 // We can't really do much to verify the CLD2 data file. In theory we could
92 // read the headers, but that won't do much other than tell us whether or
93 // not the headers are valid. So just check if the file exists.
94 const base::FilePath expected_file = GetInstalledPath(install_dir);
95 VLOG(1) << "Verifying install: " << expected_file.value();
96 const bool result = base::PathExists(expected_file);
97 VLOG(1) << "Verification result: " << (result ? "valid" : "invalid");
98 return result;
99 }
100
101 base::FilePath CldComponentInstallerTraits::GetRelativeInstallDir() const {
102 return base::FilePath(FILE_PATH_LITERAL("CLD"));
103 }
104
105 void CldComponentInstallerTraits::GetHash(std::vector<uint8_t>* hash) const {
106 hash->assign(kPublicKeySHA256,
107 kPublicKeySHA256 + arraysize(kPublicKeySHA256));
108 }
109
110 std::string CldComponentInstallerTraits::GetName() const {
111 return kCldManifestName;
112 }
113
114 std::string CldComponentInstallerTraits::GetAp() const {
115 return std::string();
116 }
117
118 // static
119 void RegisterCldComponent(ComponentUpdateService* cus) {
120 if (!translate::CldDataSource::IsUsingComponentDataSource()) {
121 // The configured CLD data source isn't the "Component" data source, so
122 // there is nothing to do.
123 return;
124 }
125
126 // This log line is to help with determining which kind of provider has been
127 // configured. See also: chrome://translate-internals
128 VLOG(1) << "Registering CLD component with the component update service";
129
130 std::unique_ptr<ComponentInstallerTraits> traits(
131 new CldComponentInstallerTraits());
132 // |cus| will take ownership of |installer| during installer->Register(cus).
133 DefaultComponentInstaller* installer =
134 new DefaultComponentInstaller(std::move(traits));
135 installer->Register(cus, base::Closure());
136 }
137
138 void CldComponentInstallerTraits::SetLatestCldDataFile(
139 const base::FilePath& path) {
140 VLOG(1) << "Setting CLD data file location: " << path.value();
141 g_latest_cld_data_file.Get() = path;
142 translate::CldDataSource::Get()->SetCldDataFilePath(path);
143 }
144
145 base::FilePath CldComponentInstallerTraits::GetLatestCldDataFile() {
146 return g_latest_cld_data_file.Get();
147 }
148
149 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698