OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/component_updater/cld_component_installer.h" | 5 #include "chrome/browser/component_updater/cld_component_installer.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/path_service.h" | |
16 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "base/values.h" |
18 #include "chrome/common/chrome_constants.h" | |
19 #include "chrome/common/chrome_paths.h" | |
20 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
21 #include "net/ssl/ssl_config_service.h" | 18 #include "net/ssl/ssl_config_service.h" |
22 | 19 |
23 using component_updater::ComponentUpdateService; | 20 using component_updater::ComponentUpdateService; |
24 using content::BrowserThread; | 21 using content::BrowserThread; |
25 | 22 |
26 namespace { | 23 namespace { |
27 | 24 |
28 // Once we have acquired a valid file from the component installer, we need to | 25 // Once we have acquired a valid file from the component installer, we need to |
29 // make the path available to other parts of the system such as the | 26 // make the path available to other parts of the system such as the |
(...skipping 10 matching lines...) Expand all Loading... |
40 // The extension id is: dpedmmgabcgnikllifiidmijgoiihfgf | 37 // The extension id is: dpedmmgabcgnikllifiidmijgoiihfgf |
41 const uint8 kPublicKeySHA256[32] = { | 38 const uint8 kPublicKeySHA256[32] = { |
42 0x3f, 0x43, 0xcc, 0x60, 0x12, 0x6d, 0x8a, 0xbb, | 39 0x3f, 0x43, 0xcc, 0x60, 0x12, 0x6d, 0x8a, 0xbb, |
43 0x85, 0x88, 0x3c, 0x89, 0x6e, 0x88, 0x75, 0x65, | 40 0x85, 0x88, 0x3c, 0x89, 0x6e, 0x88, 0x75, 0x65, |
44 0xb9, 0x46, 0x09, 0xe8, 0xca, 0x92, 0xdd, 0x82, | 41 0xb9, 0x46, 0x09, 0xe8, 0xca, 0x92, 0xdd, 0x82, |
45 0x4e, 0x6d, 0x0e, 0xe6, 0x79, 0x8a, 0x87, 0xf5 | 42 0x4e, 0x6d, 0x0e, 0xe6, 0x79, 0x8a, 0x87, 0xf5 |
46 }; | 43 }; |
47 | 44 |
48 const char kCldManifestName[] = "CLD2 Data"; | 45 const char kCldManifestName[] = "CLD2 Data"; |
49 | 46 |
50 CldComponentInstallerTraits::CldComponentInstallerTraits() { | 47 CldComponentInstallerTraits::CldComponentInstallerTraits( |
| 48 const base::FilePath& base_dir, |
| 49 const base::FilePath& data_filename) |
| 50 : base_dir_(base_dir), data_filename_(data_filename) { |
51 } | 51 } |
52 | 52 |
53 bool CldComponentInstallerTraits::CanAutoUpdate() const { | 53 bool CldComponentInstallerTraits::CanAutoUpdate() const { |
54 return true; | 54 return true; |
55 } | 55 } |
56 | 56 |
57 bool CldComponentInstallerTraits::OnCustomInstall( | 57 bool CldComponentInstallerTraits::OnCustomInstall( |
58 const base::DictionaryValue& manifest, | 58 const base::DictionaryValue& manifest, |
59 const base::FilePath& install_dir) { | 59 const base::FilePath& install_dir) { |
60 return true; // Nothing custom here. | 60 return true; // Nothing custom here. |
61 } | 61 } |
62 | 62 |
63 base::FilePath CldComponentInstallerTraits::GetInstalledPath( | 63 base::FilePath CldComponentInstallerTraits::GetInstalledPath( |
64 const base::FilePath& base) { | 64 const base::FilePath& base) const { |
65 // Currently, all platforms have the file at the same location because there | 65 // Currently, all platforms have the file at the same location because there |
66 // is no binary difference in the generated file on any supported platform. | 66 // is no binary difference in the generated file on any supported platform. |
67 // NB: This may change when 64-bit is officially supported. | 67 // NB: This may change when 64-bit is officially supported. |
68 return base.Append(FILE_PATH_LITERAL("_platform_specific")) | 68 return base.Append(FILE_PATH_LITERAL("_platform_specific")) |
69 .Append(FILE_PATH_LITERAL("all")) | 69 .Append(FILE_PATH_LITERAL("all")) |
70 .Append(chrome::kCLDDataFilename); | 70 .Append(data_filename_); |
71 } | 71 } |
72 | 72 |
73 void CldComponentInstallerTraits::ComponentReady( | 73 void CldComponentInstallerTraits::ComponentReady( |
74 const base::Version& version, | 74 const base::Version& version, |
75 const base::FilePath& path, | 75 const base::FilePath& path, |
76 scoped_ptr<base::DictionaryValue> manifest) { | 76 scoped_ptr<base::DictionaryValue> manifest) { |
77 VLOG(1) << "Component ready, version " << version.GetString() << " in " | 77 VLOG(1) << "Component ready, version " << version.GetString() << " in " |
78 << path.value(); | 78 << path.value(); |
79 SetLatestCldDataFile(GetInstalledPath(path)); | 79 SetLatestCldDataFile(GetInstalledPath(path)); |
80 } | 80 } |
81 | 81 |
82 bool CldComponentInstallerTraits::VerifyInstallation( | 82 bool CldComponentInstallerTraits::VerifyInstallation( |
83 const base::FilePath& install_dir) const { | 83 const base::FilePath& install_dir) const { |
84 // We can't really do much to verify the CLD2 data file. In theory we could | 84 // We can't really do much to verify the CLD2 data file. In theory we could |
85 // read the headers, but that won't do much other than tell us whether or | 85 // read the headers, but that won't do much other than tell us whether or |
86 // not the headers are valid. So just check if the file exists. | 86 // not the headers are valid. So just check if the file exists. |
87 const base::FilePath expected_file = GetInstalledPath(install_dir); | 87 const base::FilePath expected_file = GetInstalledPath(install_dir); |
88 VLOG(1) << "Verifying install: " << expected_file.value(); | 88 VLOG(1) << "Verifying install: " << expected_file.value(); |
89 const bool result = base::PathExists(expected_file); | 89 const bool result = base::PathExists(expected_file); |
90 VLOG(1) << "Verification result: " << (result ? "valid" : "invalid"); | 90 VLOG(1) << "Verification result: " << (result ? "valid" : "invalid"); |
91 return result; | 91 return result; |
92 } | 92 } |
93 | 93 |
94 base::FilePath CldComponentInstallerTraits::GetBaseDirectory() const { | 94 base::FilePath CldComponentInstallerTraits::GetBaseDirectory() const { |
95 base::FilePath result; | 95 return base_dir_; |
96 PathService::Get(chrome::DIR_COMPONENT_CLD2, &result); | |
97 return result; | |
98 } | 96 } |
99 | 97 |
100 void CldComponentInstallerTraits::GetHash(std::vector<uint8>* hash) const { | 98 void CldComponentInstallerTraits::GetHash(std::vector<uint8>* hash) const { |
101 hash->assign(kPublicKeySHA256, | 99 hash->assign(kPublicKeySHA256, |
102 kPublicKeySHA256 + arraysize(kPublicKeySHA256)); | 100 kPublicKeySHA256 + arraysize(kPublicKeySHA256)); |
103 } | 101 } |
104 | 102 |
105 std::string CldComponentInstallerTraits::GetName() const { | 103 std::string CldComponentInstallerTraits::GetName() const { |
106 return kCldManifestName; | 104 return kCldManifestName; |
107 } | 105 } |
108 | 106 |
109 void RegisterCldComponent(ComponentUpdateService* cus) { | 107 void RegisterCldComponent(ComponentUpdateService* cus, |
| 108 const base::FilePath& base_dir, |
| 109 const base::FilePath& data_filename) { |
110 scoped_ptr<ComponentInstallerTraits> traits( | 110 scoped_ptr<ComponentInstallerTraits> traits( |
111 new CldComponentInstallerTraits()); | 111 new CldComponentInstallerTraits(base_dir, data_filename)); |
112 // |cus| will take ownership of |installer| during installer->Register(cus). | 112 // |cus| will take ownership of |installer| during installer->Register(cus). |
113 DefaultComponentInstaller* installer = | 113 DefaultComponentInstaller* installer = |
114 new DefaultComponentInstaller(traits.Pass()); | 114 new DefaultComponentInstaller(traits.Pass()); |
115 installer->Register(cus); | 115 installer->Register(cus); |
116 } | 116 } |
117 | 117 |
118 void CldComponentInstallerTraits::SetLatestCldDataFile( | 118 void CldComponentInstallerTraits::SetLatestCldDataFile( |
119 const base::FilePath& path) { | 119 const base::FilePath& path) { |
120 VLOG(1) << "Setting CLD data file location: " << path.value(); | 120 VLOG(1) << "Setting CLD data file location: " << path.value(); |
121 base::AutoLock lock(cld_file_lock.Get()); | 121 base::AutoLock lock(cld_file_lock.Get()); |
122 cld_file.Get() = path; | 122 cld_file.Get() = path; |
123 } | 123 } |
124 | 124 |
125 base::FilePath GetLatestCldDataFile() { | 125 base::FilePath GetLatestCldDataFile() { |
126 base::AutoLock lock(cld_file_lock.Get()); | 126 base::AutoLock lock(cld_file_lock.Get()); |
127 // cld_file is an empty path by default, meaning "file not available yet". | 127 // cld_file is an empty path by default, meaning "file not available yet". |
128 return cld_file.Get(); | 128 return cld_file.Get(); |
129 } | 129 } |
130 | 130 |
131 } // namespace component_updater | 131 } // namespace component_updater |
OLD | NEW |