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

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

Issue 216923006: Add a component updater for the CLD2 data file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address commenter notes Created 6 years, 8 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 "base/bind.h"
8 #include "base/file_util.h"
9 #include "base/files/file_path.h"
10 #include "base/lazy_instance.h"
11 #include "base/path_service.h"
12 #include "base/platform_file.h"
13 #include "chrome/browser/component_updater/default_component_installer.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/chrome_constants.h"
16 #include "chrome/common/chrome_paths.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "net/ssl/ssl_config_service.h"
19
20 using component_updater::ComponentUpdateService;
21 using content::BrowserThread;
22
23 namespace {
24
25 // Once we have acquired a valid file from the component installer, we need to
26 // make the path available to other parts of the system such as the
27 // translation libraries. We create a global to hold onto the path, and a
28 // lock to guard it.
29 base::LazyInstance<base::Lock> s_file_lock_ = LAZY_INSTANCE_INITIALIZER;
Sorin Jianu 2014/04/22 17:10:49 There should not be a trailing _. Naming conventio
30
31 struct CLDFilePathWrapper {
Sorin Jianu 2014/04/22 17:10:49 Why do we need the wrapper? Can we just say: base:
32 CLDFilePathWrapper() {
33 }
34 base::FilePath value;
35 };
36 base::LazyInstance<CLDFilePathWrapper>::Leaky s_file_;
37
38 }
39
40 namespace component_updater {
41
42 // kPublicKeySHA256 is the SHA256 hash of the SubjectPublicKeyInfo of the key
43 // that's used to sign generated CRL sets.
44 // The extension id is: dpedmmgabcgnikllifiidmijgoiihfgf
45 const uint8 kPublicKeySHA256[32] = {
Sorin Jianu 2014/04/22 17:10:49 kPublicKeySHA256 and kCldManifestName could be mem
46 0xe8, 0xce, 0xcf, 0x42, 0x06, 0xd0, 0x93, 0x49,
47 0x6d, 0xd9, 0x89, 0xe1, 0x41, 0x04, 0x86, 0x4a,
48 0x8f, 0xbd, 0x86, 0x12, 0xb9, 0x58, 0x9b, 0xfb,
49 0x4f, 0xbb, 0x1b, 0xa9, 0xd3, 0x85, 0x37, 0xef
50 };
51
52 const char kCldManifestName[] = "CLD2 Data";
53
54 class CldComponentInstallerTraits : public ComponentInstallerTraits {
55 public:
56 CldComponentInstallerTraits();
57 virtual ~CldComponentInstallerTraits() {}
58
59 private:
60 // The following methods override ComponentInstallerTraits.
61 virtual bool CanAutoUpdate() const OVERRIDE;
62 virtual bool OnCustomInstall(const base::DictionaryValue& manifest,
63 const base::FilePath& install_dir) OVERRIDE;
64 virtual bool VerifyInstallation(
65 const base::FilePath& install_dir) const OVERRIDE;
66 virtual void ComponentReady(
67 const base::Version& version,
68 const base::FilePath& path,
69 scoped_ptr<base::DictionaryValue> manifest) OVERRIDE;
70 virtual base::FilePath GetBaseDirectory() const OVERRIDE;
71 virtual void GetHash(std::vector<uint8>* hash) const OVERRIDE;
72 virtual std::string GetName() const OVERRIDE;
73
74 void SetLatestCldDataFile(const base::FilePath& path);
75 DISALLOW_COPY_AND_ASSIGN(CldComponentInstallerTraits);
76 };
77
78 CldComponentInstallerTraits::CldComponentInstallerTraits() {
79 }
80
81 bool CldComponentInstallerTraits::CanAutoUpdate() const {
82 return true;
83 }
84
85 bool CldComponentInstallerTraits::OnCustomInstall(
86 const base::DictionaryValue& manifest,
87 const base::FilePath& install_dir) {
88 return true; // Nothing custom here.
89 }
90
91 void CldComponentInstallerTraits::ComponentReady(
92 const base::Version& version,
93 const base::FilePath& path,
94 scoped_ptr<base::DictionaryValue> manifest) {
95 base::FilePath source_path = path.Append(chrome::kCLDDataFilename);
96 SetLatestCldDataFile(source_path);
97 }
98
99 bool CldComponentInstallerTraits::VerifyInstallation(
100 const base::FilePath& install_dir) const {
101 // We can't really do much to verify the CLD2 data file. In theory we could
102 // read the headers, but that won't do much other than tell us whether or
103 // not the headers are valid. So just check if the file exists.
104 return base::PathExists(install_dir.Append(chrome::kCLDDataFilename));
105 }
106
107 base::FilePath CldComponentInstallerTraits::GetBaseDirectory() const {
108 base::FilePath result;
109 PathService::Get(chrome::DIR_COMPONENT_CLD2, &result);
110 return result;
111 }
112
113 void CldComponentInstallerTraits::GetHash(std::vector<uint8>* hash) const {
114 hash->assign(kPublicKeySHA256,
115 kPublicKeySHA256 + arraysize(kPublicKeySHA256));
116 }
117
118 std::string CldComponentInstallerTraits::GetName() const {
119 return kCldManifestName;
120 }
121
122 void RegisterCldComponent(ComponentUpdateService* cus) {
123 scoped_ptr<ComponentInstallerTraits> traits(
124 new CldComponentInstallerTraits());
125 // |cus| will take ownership of |installer| during installer->Register(cus).
126 DefaultComponentInstaller* installer
127 = new DefaultComponentInstaller(traits.Pass());
128 installer->Register(cus);
129 }
130
131 void CldComponentInstallerTraits::SetLatestCldDataFile(
132 const base::FilePath& path) {
133 base::AutoLock lock(s_file_lock_.Get());
134 s_file_.Get().value = path;
135 }
136
137 bool GetLatestCldDataFile(base::FilePath* path) {
138 base::AutoLock lock(s_file_lock_.Get());
139 base::FilePath cached = s_file_.Get().value;
Sorin Jianu 2014/04/22 17:10:49 const base::FilePath cached
140 if (cached.empty() || !base::PathExists(cached)) return false;
141 *path = cached;
142 return true;
143 }
144
145 } // namespace component_updater
OLDNEW
« no previous file with comments | « chrome/browser/component_updater/cld_component_installer.h ('k') | chrome/browser/translate/translate_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698