OLD | NEW |
---|---|
(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 | |
Sorin Jianu
2014/04/18 17:46:14
These lines of code don't have to be indented insi
Andrew Hayden (chromium.org)
2014/04/22 16:10:14
Done.
| |
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. | |
Sorin Jianu
2014/04/18 17:46:14
Two ideas here. If the file path is guaranteed to
Andrew Hayden (chromium.org)
2014/04/22 16:10:14
Access to the path takes place in the blocking poo
| |
29 base::LazyInstance<base::Lock> s_file_lock_ = LAZY_INSTANCE_INITIALIZER; | |
30 | |
31 struct CLDFilePathWrapper { | |
32 CLDFilePathWrapper() { | |
33 value = NULL; | |
34 } | |
35 base::FilePath* value; | |
Sorin Jianu
2014/04/18 17:46:14
Can we use a value type here instead of a pointer
Andrew Hayden (chromium.org)
2014/04/22 16:10:14
I didn't realize filepath was just a stringtype. H
| |
36 }; | |
37 base::LazyInstance<CLDFilePathWrapper>::Leaky s_file_; | |
38 | |
39 } | |
40 | |
41 namespace component_updater { | |
42 | |
43 // kPublicKeySHA256 is the SHA256 hash of the SubjectPublicKeyInfo of the key | |
44 // that's used to sign generated CRL sets. | |
waffles
2014/04/18 17:48:02
Hash + comment are wrong, as discussed.
I know yo
| |
45 // The extension id is: dpedmmgabcgnikllifiidmijgoiihfgf | |
46 const uint8 kPublicKeySHA256[32] = { | |
47 0xe8, 0xce, 0xcf, 0x42, 0x06, 0xd0, 0x93, 0x49, | |
48 0x6d, 0xd9, 0x89, 0xe1, 0x41, 0x04, 0x86, 0x4a, | |
49 0x8f, 0xbd, 0x86, 0x12, 0xb9, 0x58, 0x9b, 0xfb, | |
50 0x4f, 0xbb, 0x1b, 0xa9, 0xd3, 0x85, 0x37, 0xef | |
51 }; | |
52 | |
53 const char kCldManifestName[] = "CLD2 Data"; | |
54 | |
55 class CldComponentInstallerTraits : public ComponentInstallerTraits { | |
56 public: | |
57 CldComponentInstallerTraits(); | |
58 virtual ~CldComponentInstallerTraits() {} | |
59 | |
60 private: | |
61 // The following methods override ComponentInstallerTraits. | |
62 virtual bool CanAutoUpdate() const OVERRIDE; | |
63 virtual bool OnCustomInstall(const base::DictionaryValue& manifest, | |
64 const base::FilePath& install_dir) OVERRIDE; | |
65 virtual bool VerifyInstallation( | |
66 const base::FilePath& install_dir) const OVERRIDE; | |
67 virtual void ComponentReady( | |
68 const base::Version& version, | |
69 const base::FilePath& path, | |
70 scoped_ptr<base::DictionaryValue> manifest) OVERRIDE; | |
71 virtual base::FilePath GetBaseDirectory() const OVERRIDE; | |
72 virtual void GetHash(std::vector<uint8>* hash) const OVERRIDE; | |
73 virtual std::string GetName() const OVERRIDE; | |
74 | |
75 void SetLatestCldDataFile(const base::FilePath& path); | |
76 DISALLOW_COPY_AND_ASSIGN(CldComponentInstallerTraits); | |
77 }; | |
78 | |
79 CldComponentInstallerTraits::CldComponentInstallerTraits() { | |
80 } | |
81 | |
82 bool CldComponentInstallerTraits::CanAutoUpdate() const { | |
83 return true; | |
84 } | |
85 | |
86 bool CldComponentInstallerTraits::OnCustomInstall( | |
87 const base::DictionaryValue& manifest, | |
88 const base::FilePath& install_dir) { | |
89 return true; // Nothing custom here. | |
90 } | |
91 | |
92 void CldComponentInstallerTraits::ComponentReady( | |
93 const base::Version& version, | |
94 const base::FilePath& path, | |
95 scoped_ptr<base::DictionaryValue> manifest) { | |
96 base::FilePath source_path = path.Append(chrome::kCLDDataFilename); | |
97 SetLatestCldDataFile(source_path); | |
98 } | |
99 | |
100 bool CldComponentInstallerTraits::VerifyInstallation( | |
101 const base::FilePath& install_dir) const { | |
102 // We can't really do much to verify the CLD2 data file. In theory we could | |
103 // read the headers, but that won't do much other than tell us whether or | |
104 // not the headers are valid. So just check if the file exists. | |
105 return base::PathExists(install_dir.Append(chrome::kCLDDataFilename)); | |
106 } | |
107 | |
108 base::FilePath CldComponentInstallerTraits::GetBaseDirectory() const { | |
109 base::FilePath result; | |
110 PathService::Get(chrome::DIR_COMPONENT_CLD2, &result); | |
111 return result; | |
112 } | |
113 | |
114 void CldComponentInstallerTraits::GetHash( | |
115 std::vector<uint8>* hash) const { | |
Sorin Jianu
2014/04/18 17:46:14
does this fit on one line?
Andrew Hayden (chromium.org)
2014/04/22 16:10:14
........... maybe. :)
| |
116 hash->assign(kPublicKeySHA256, | |
117 kPublicKeySHA256 + arraysize(kPublicKeySHA256)); | |
118 } | |
119 | |
120 std::string CldComponentInstallerTraits::GetName() const { | |
121 return kCldManifestName; | |
122 } | |
123 | |
124 void RegisterCldComponent(ComponentUpdateService* cus) { | |
125 scoped_ptr<ComponentInstallerTraits> traits( | |
126 new CldComponentInstallerTraits); | |
waffles
2014/04/18 17:48:02
We prefer "new CldComponentInstallerTraits())"
Andrew Hayden (chromium.org)
2014/04/22 16:10:14
Sorry, copy/paste cruft. Done.
| |
127 // |cus| will take ownership of |installer| during installer->Register(cus). | |
128 DefaultComponentInstaller* installer | |
129 = new DefaultComponentInstaller(traits.Pass()); | |
130 installer->Register(cus); | |
131 } | |
132 | |
133 void CldComponentInstallerTraits::SetLatestCldDataFile( | |
134 const base::FilePath& path) { | |
135 base::AutoLock lock(s_file_lock_.Get()); | |
136 base::FilePath* old = s_file_.Get().value; | |
Sorin Jianu
2014/04/18 17:46:14
Is there a reason why we don't just:
delete s_fil
Andrew Hayden (chromium.org)
2014/04/22 16:10:14
Sorry, this was leftover from when I was trying to
| |
137 s_file_.Get().value = new base::FilePath(path); | |
138 if (old != NULL) delete old; | |
Sorin Jianu
2014/04/18 17:46:14
We can delete a null pointer, no need for the chec
Andrew Hayden (chromium.org)
2014/04/22 16:10:14
My C++ is rusty, I thought this would be a segfaul
Andrew Hayden (chromium.org)
2014/04/22 16:10:14
Will go away when I stop using a pointer. Sorry, d
| |
139 } | |
140 | |
141 bool GetLatestCldDataFile(base::FilePath* path) { | |
142 base::AutoLock lock(s_file_lock_.Get()); | |
143 base::FilePath* cached = s_file_.Get().value; | |
144 if (cached == NULL || !base::PathExists(*cached)) return false; | |
145 *path = *cached; | |
146 return true; | |
147 } | |
148 | |
149 } // namespace component_updater | |
OLD | NEW |