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

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

Issue 1986403002: Component updater for FileTypePolicies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@replace_download_ext
Patch Set: Fix test's enum check 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 2016 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/file_type_policies_component_installe r.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/logging.h"
15 #include "base/macros.h"
16 #include "base/path_service.h"
17 #include "base/version.h"
18 #include "chrome/common/safe_browsing/file_type_policies.h"
19 #include "components/component_updater/component_updater_paths.h"
20 #include "content/public/browser/browser_thread.h"
21
22 using component_updater::ComponentUpdateService;
23
24 namespace {
25 const base::FilePath::CharType kFileTypePoliciesBinaryPbFileName[] =
26 FILE_PATH_LITERAL("download_file_types.pb");
27
28 // The SHA256 of the SubjectPublicKeyInfo used to sign the extension.
29 // The extension id is: khaoiebndkojlmppeemjhbpbandiljpe
30 const uint8_t kPublicKeySHA256[32] = {
31 0xa7, 0x0e, 0x84, 0x1d, 0x3a, 0xe9, 0xbc, 0xff, 0x44, 0xc9, 0x71,
32 0xf1, 0x0d, 0x38, 0xb9, 0xf4, 0x65, 0x92, 0x31, 0x01, 0x47, 0x3f,
33 0x1b, 0x7c, 0x11, 0xb0, 0x85, 0x0f, 0xa3, 0xfd, 0xe1, 0xe5};
34
35 const char kFileTypePoliciesManifestName[] = "File Type Policies";
36
37 void LoadFileTypesFromDisk(const base::FilePath& pb_path) {
38 if (pb_path.empty())
39 return;
40
41 VLOG(1) << "Reading Download File Types from file: " << pb_path.value();
42 std::string binary_pb;
43 if (!base::ReadFileToString(pb_path, &binary_pb)) {
44 // The file won't exist on new installations, so this is not always an
45 // error.
46 VLOG(1) << "Failed reading from " << pb_path.value();
47 return;
48 }
49
50 safe_browsing::FileTypePolicies::GetInstance()->PopulateFromDynamicUpdate(
51 binary_pb);
52 }
53
54 } // namespace
55
56 namespace component_updater {
57
58 bool FileTypePoliciesComponentInstallerTraits::CanAutoUpdate() const {
59 return true;
60 }
61
62 bool FileTypePoliciesComponentInstallerTraits::RequiresNetworkEncryption()
63 const {
64 return false;
65 }
66
67 bool FileTypePoliciesComponentInstallerTraits::OnCustomInstall(
68 const base::DictionaryValue& manifest,
69 const base::FilePath& install_dir) {
70 return true; // Nothing custom here.
71 }
72
73 base::FilePath FileTypePoliciesComponentInstallerTraits::GetInstalledPath(
74 const base::FilePath& base) {
75 return base.Append(kFileTypePoliciesBinaryPbFileName);
76 }
77
78 void FileTypePoliciesComponentInstallerTraits::ComponentReady(
79 const base::Version& version,
80 const base::FilePath& install_dir,
81 std::unique_ptr<base::DictionaryValue> manifest) {
82 VLOG(1) << "Component ready, version " << version.GetString() << " in "
83 << install_dir.value();
84
85 if (!content::BrowserThread::PostBlockingPoolTask(
86 FROM_HERE,
87 base::Bind(&LoadFileTypesFromDisk, GetInstalledPath(install_dir)))) {
88 NOTREACHED();
89 }
90 }
91
92 // Called during startup and installation before ComponentReady().
93 bool FileTypePoliciesComponentInstallerTraits::VerifyInstallation(
94 const base::DictionaryValue& manifest,
95 const base::FilePath& install_dir) const {
96 // No need to actually validate the proto here, since we'll do the checking
97 // in PopulateFromDynamicUpdate().
98 return base::PathExists(GetInstalledPath(install_dir));
99 }
100
101 base::FilePath FileTypePoliciesComponentInstallerTraits::GetRelativeInstallDir()
102 const {
103 return base::FilePath(FILE_PATH_LITERAL("FileTypePolicies"));
104 }
105
106 void FileTypePoliciesComponentInstallerTraits::GetHash(
107 std::vector<uint8_t>* hash) const {
108 hash->assign(kPublicKeySHA256,
109 kPublicKeySHA256 + arraysize(kPublicKeySHA256));
110 }
111
112 std::string FileTypePoliciesComponentInstallerTraits::GetName() const {
113 return kFileTypePoliciesManifestName;
114 }
115
116 std::string FileTypePoliciesComponentInstallerTraits::GetAp() const {
117 return std::string();
118 }
119
120 void RegisterFileTypePoliciesComponent(ComponentUpdateService* cus,
121 const base::FilePath& user_data_dir) {
122 VLOG(1) << "Registering File Type Policies component.";
123
124 std::unique_ptr<ComponentInstallerTraits> traits(
125 new FileTypePoliciesComponentInstallerTraits());
126 // |cus| will take ownership of |installer| during installer->Register(cus).
127 DefaultComponentInstaller* installer =
128 new DefaultComponentInstaller(std::move(traits));
129 installer->Register(cus, base::Closure());
130 }
131
132 } // namespace component_updater
OLDNEW
« no previous file with comments | « chrome/browser/component_updater/file_type_policies_component_installer.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698