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