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

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: Rebase onto latest master 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..ad82110266d130328e7a4475f52158ec3e812558
--- /dev/null
+++ b/chrome/browser/component_updater/cld_component_installer.cc
@@ -0,0 +1,157 @@
+// 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/logging.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. See GetLatestCldDataFile(...) for more info.
+base::LazyInstance<base::Lock> g_cld_file_lock_ = LAZY_INSTANCE_INITIALIZER;
+base::LazyInstance<base::FilePath> g_cld_file_ = LAZY_INSTANCE_INITIALIZER;
+
+}
+
+namespace component_updater {
+
+// The SHA256 of the SubjectPublicKeyInfo used to sign the extension.
+// The extension id is: dpedmmgabcgnikllifiidmijgoiihfgf
+const uint8 kPublicKeySHA256[32] = {
+ 0x3f, 0x43, 0xcc, 0x60, 0x12, 0x6d, 0x8a, 0xbb,
+ 0x85, 0x88, 0x3c, 0x89, 0x6e, 0x88, 0x75, 0x65,
+ 0xb9, 0x46, 0x09, 0xe8, 0xca, 0x92, 0xdd, 0x82,
+ 0x4e, 0x6d, 0x0e, 0xe6, 0x79, 0x8a, 0x87, 0xf5
+};
+
+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;
+
+ base::FilePath GetInstalledPath(const base::FilePath& base) const;
+ 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.
+}
+
+base::FilePath CldComponentInstallerTraits::GetInstalledPath(
+ const base::FilePath& base) const {
+ // Currently, all platforms have the file at the same location because there
+ // is no binary difference in the generated file on any supported platform.
+ // NB: This may change when 64-bit is officially supported.
+ return base.Append("_platform_specific")
+ .Append("all")
+ .Append(chrome::kCLDDataFilename);
+}
+
+void CldComponentInstallerTraits::ComponentReady(
+ const base::Version& version,
+ const base::FilePath& path,
+ scoped_ptr<base::DictionaryValue> manifest) {
+ VLOG(1) << "Component ready, version " << version.GetString()
+ << " in " << path.value();
+ SetLatestCldDataFile(GetInstalledPath(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.
+ base::FilePath expected_file = GetInstalledPath(install_dir);
Sorin Jianu 2014/04/25 16:39:41 could be const, sorry I did not see it before.
Andrew Hayden (chromium.org) 2014/04/25 17:07:21 Done.
+ VLOG(1) << "Verifying install: " << expected_file.value();
+ bool result = base::PathExists(expected_file);
Sorin Jianu 2014/04/25 16:39:41 const bool
Andrew Hayden (chromium.org) 2014/04/25 17:07:21 Done.
+ VLOG(1) << "Verification result: " << result;
+ return result;
+}
+
+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);
+}
+
+// This method is completely threadsafe.
+void CldComponentInstallerTraits::SetLatestCldDataFile(
+ const base::FilePath& path) {
+ VLOG(1) << "Setting CLD data file location: " << path.value();
+ base::AutoLock lock(g_cld_file_lock_.Get());
+ g_cld_file_.Get() = path;
+}
+
+bool GetLatestCldDataFile(base::FilePath* path) {
+ base::AutoLock lock(g_cld_file_lock_.Get());
+ base::FilePath cached = g_cld_file_.Get();
Sorin Jianu 2014/04/25 16:39:41 const base::FilePath
Andrew Hayden (chromium.org) 2014/04/25 17:07:21 Done.
+ if (cached.empty()) return false;
+ *path = cached;
+ return true;
+}
+
+} // namespace component_updater

Powered by Google App Engine
This is Rietveld 408576698