| 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" | 15 #include "base/path_service.h" |
| 16 #include "components/component_updater/component_updater_paths.h" | 16 #include "components/component_updater/component_updater_paths.h" |
| 17 #include "components/translate/content/browser/browser_cld_data_provider.h" | 17 #include "components/translate/content/browser/browser_cld_data_provider.h" |
| 18 #include "components/translate/content/common/cld_data_source.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "net/ssl/ssl_config_service.h" | 20 #include "net/ssl/ssl_config_service.h" |
| 20 | 21 |
| 21 using component_updater::ComponentUpdateService; | 22 using component_updater::ComponentUpdateService; |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 // TODO(andrewhayden): Make the data file path into a gyp/gn define | 25 // TODO(andrewhayden): Make the data file path into a gyp/gn define |
| 25 // If you change this, also update component_cld_data_harness.cc | 26 // If you change this, also update component_cld_data_harness.cc |
| 26 // and cld_component_installer_unittest.cc accordingly! | 27 // and cld_component_installer_unittest.cc accordingly! |
| 27 const base::FilePath::CharType kCldDataFileName[] = | 28 const base::FilePath::CharType kCldDataFileName[] = |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 void CldComponentInstallerTraits::GetHash(std::vector<uint8>* hash) const { | 99 void CldComponentInstallerTraits::GetHash(std::vector<uint8>* hash) const { |
| 99 hash->assign(kPublicKeySHA256, | 100 hash->assign(kPublicKeySHA256, |
| 100 kPublicKeySHA256 + arraysize(kPublicKeySHA256)); | 101 kPublicKeySHA256 + arraysize(kPublicKeySHA256)); |
| 101 } | 102 } |
| 102 | 103 |
| 103 std::string CldComponentInstallerTraits::GetName() const { | 104 std::string CldComponentInstallerTraits::GetName() const { |
| 104 return kCldManifestName; | 105 return kCldManifestName; |
| 105 } | 106 } |
| 106 | 107 |
| 107 void RegisterCldComponent(ComponentUpdateService* cus) { | 108 void RegisterCldComponent(ComponentUpdateService* cus) { |
| 109 // Make sure we don't start up if the CLD data source isn't compatible. |
| 110 if (!translate::CldDataSource::ShouldRegisterForComponentUpdates()) { |
| 111 // This is a serious build-time configuration error. |
| 112 LOG(ERROR) << "Wrong CLD data source: " << |
| 113 translate::CldDataSource::GetName(); |
| 114 NOTREACHED(); |
| 115 return; |
| 116 } |
| 117 |
| 108 // This log line is to help with determining which kind of provider has been | 118 // This log line is to help with determining which kind of provider has been |
| 109 // configured. See also: chrome://translate-internals | 119 // configured. See also: chrome://translate-internals |
| 110 VLOG(1) << "Registering CLD component with the component update service"; | 120 VLOG(1) << "Registering CLD component with the component update service"; |
| 111 | 121 |
| 112 scoped_ptr<ComponentInstallerTraits> traits( | 122 scoped_ptr<ComponentInstallerTraits> traits( |
| 113 new CldComponentInstallerTraits()); | 123 new CldComponentInstallerTraits()); |
| 114 // |cus| will take ownership of |installer| during installer->Register(cus). | 124 // |cus| will take ownership of |installer| during installer->Register(cus). |
| 115 DefaultComponentInstaller* installer = | 125 DefaultComponentInstaller* installer = |
| 116 new DefaultComponentInstaller(traits.Pass()); | 126 new DefaultComponentInstaller(traits.Pass()); |
| 117 installer->Register(cus); | 127 installer->Register(cus); |
| 118 } | 128 } |
| 119 | 129 |
| 120 void CldComponentInstallerTraits::SetLatestCldDataFile( | 130 void CldComponentInstallerTraits::SetLatestCldDataFile( |
| 121 const base::FilePath& path) { | 131 const base::FilePath& path) { |
| 122 VLOG(1) << "Setting CLD data file location: " << path.value(); | 132 VLOG(1) << "Setting CLD data file location: " << path.value(); |
| 123 g_latest_cld_data_file.Get() = path; | 133 g_latest_cld_data_file.Get() = path; |
| 124 translate::SetCldDataFilePath(path); | 134 translate::SetCldDataFilePath(path); |
| 125 } | 135 } |
| 126 | 136 |
| 127 base::FilePath CldComponentInstallerTraits::GetLatestCldDataFile() { | 137 base::FilePath CldComponentInstallerTraits::GetLatestCldDataFile() { |
| 128 return g_latest_cld_data_file.Get(); | 138 return g_latest_cld_data_file.Get(); |
| 129 } | 139 } |
| 130 | 140 |
| 131 } // namespace component_updater | 141 } // namespace component_updater |
| OLD | NEW |