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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/component_updater/cld_component_installer.cc
diff --git a/chrome/browser/component_updater/cld_component_installer.cc b/chrome/browser/component_updater/cld_component_installer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f8d6bdbb208759cd122c73ccfc8bbd9d82a196ed
--- /dev/null
+++ b/chrome/browser/component_updater/cld_component_installer.cc
@@ -0,0 +1,145 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/component_updater/cld_component_installer.h"
+
+#include "base/bind.h"
+#include "base/file_util.h"
+#include "base/files/file_path.h"
+#include "base/lazy_instance.h"
+#include "base/path_service.h"
+#include "base/platform_file.h"
+#include "chrome/browser/component_updater/default_component_installer.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_paths.h"
+#include "content/public/browser/browser_thread.h"
+#include "net/ssl/ssl_config_service.h"
+
+using component_updater::ComponentUpdateService;
+using content::BrowserThread;
+
+namespace {
+
+// Once we have acquired a valid file from the component installer, we need to
+// make the path available to other parts of the system such as the
+// translation libraries. We create a global to hold onto the path, and a
+// lock to guard it.
+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
+
+struct CLDFilePathWrapper {
Sorin Jianu 2014/04/22 17:10:49 Why do we need the wrapper? Can we just say: base:
+ CLDFilePathWrapper() {
+ }
+ base::FilePath value;
+};
+base::LazyInstance<CLDFilePathWrapper>::Leaky s_file_;
+
+}
+
+namespace component_updater {
+
+// kPublicKeySHA256 is the SHA256 hash of the SubjectPublicKeyInfo of the key
+// that's used to sign generated CRL sets.
+// The extension id is: dpedmmgabcgnikllifiidmijgoiihfgf
+const uint8 kPublicKeySHA256[32] = {
Sorin Jianu 2014/04/22 17:10:49 kPublicKeySHA256 and kCldManifestName could be mem
+ 0xe8, 0xce, 0xcf, 0x42, 0x06, 0xd0, 0x93, 0x49,
+ 0x6d, 0xd9, 0x89, 0xe1, 0x41, 0x04, 0x86, 0x4a,
+ 0x8f, 0xbd, 0x86, 0x12, 0xb9, 0x58, 0x9b, 0xfb,
+ 0x4f, 0xbb, 0x1b, 0xa9, 0xd3, 0x85, 0x37, 0xef
+};
+
+const char kCldManifestName[] = "CLD2 Data";
+
+class CldComponentInstallerTraits : public ComponentInstallerTraits {
+ public:
+ CldComponentInstallerTraits();
+ virtual ~CldComponentInstallerTraits() {}
+
+ private:
+ // The following methods override ComponentInstallerTraits.
+ virtual bool CanAutoUpdate() const OVERRIDE;
+ virtual bool OnCustomInstall(const base::DictionaryValue& manifest,
+ const base::FilePath& install_dir) OVERRIDE;
+ virtual bool VerifyInstallation(
+ const base::FilePath& install_dir) const OVERRIDE;
+ virtual void ComponentReady(
+ const base::Version& version,
+ const base::FilePath& path,
+ scoped_ptr<base::DictionaryValue> manifest) OVERRIDE;
+ virtual base::FilePath GetBaseDirectory() const OVERRIDE;
+ virtual void GetHash(std::vector<uint8>* hash) const OVERRIDE;
+ virtual std::string GetName() const OVERRIDE;
+
+ void SetLatestCldDataFile(const base::FilePath& path);
+ DISALLOW_COPY_AND_ASSIGN(CldComponentInstallerTraits);
+};
+
+CldComponentInstallerTraits::CldComponentInstallerTraits() {
+}
+
+bool CldComponentInstallerTraits::CanAutoUpdate() const {
+ return true;
+}
+
+bool CldComponentInstallerTraits::OnCustomInstall(
+ const base::DictionaryValue& manifest,
+ const base::FilePath& install_dir) {
+ return true; // Nothing custom here.
+}
+
+void CldComponentInstallerTraits::ComponentReady(
+ const base::Version& version,
+ const base::FilePath& path,
+ scoped_ptr<base::DictionaryValue> manifest) {
+ base::FilePath source_path = path.Append(chrome::kCLDDataFilename);
+ SetLatestCldDataFile(source_path);
+}
+
+bool CldComponentInstallerTraits::VerifyInstallation(
+ const base::FilePath& install_dir) const {
+ // We can't really do much to verify the CLD2 data file. In theory we could
+ // read the headers, but that won't do much other than tell us whether or
+ // not the headers are valid. So just check if the file exists.
+ return base::PathExists(install_dir.Append(chrome::kCLDDataFilename));
+}
+
+base::FilePath CldComponentInstallerTraits::GetBaseDirectory() const {
+ base::FilePath result;
+ PathService::Get(chrome::DIR_COMPONENT_CLD2, &result);
+ return result;
+}
+
+void CldComponentInstallerTraits::GetHash(std::vector<uint8>* hash) const {
+ hash->assign(kPublicKeySHA256,
+ kPublicKeySHA256 + arraysize(kPublicKeySHA256));
+}
+
+std::string CldComponentInstallerTraits::GetName() const {
+ return kCldManifestName;
+}
+
+void RegisterCldComponent(ComponentUpdateService* cus) {
+ scoped_ptr<ComponentInstallerTraits> traits(
+ new CldComponentInstallerTraits());
+ // |cus| will take ownership of |installer| during installer->Register(cus).
+ DefaultComponentInstaller* installer
+ = new DefaultComponentInstaller(traits.Pass());
+ installer->Register(cus);
+}
+
+void CldComponentInstallerTraits::SetLatestCldDataFile(
+ const base::FilePath& path) {
+ base::AutoLock lock(s_file_lock_.Get());
+ s_file_.Get().value = path;
+}
+
+bool GetLatestCldDataFile(base::FilePath* path) {
+ base::AutoLock lock(s_file_lock_.Get());
+ base::FilePath cached = s_file_.Get().value;
Sorin Jianu 2014/04/22 17:10:49 const base::FilePath cached
+ if (cached.empty() || !base::PathExists(cached)) return false;
+ *path = cached;
+ return true;
+}
+
+} // namespace component_updater
« 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