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

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: Switch to default component installer and traits 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..ee88781f5f27c47a3702cab39ca49e00498b52ff
--- /dev/null
+++ b/chrome/browser/component_updater/cld_component_installer.cc
@@ -0,0 +1,131 @@
+// 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/numerics/safe_conversions.h"
+#include "base/path_service.h"
+#include "base/rand_util.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/time/time.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 component_updater {
+
+// CRX hash. The extension id is: FIXME(andrewhayden)
+const uint8 kSha2Hash[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+// File name of the CLD component manifest on different platforms.
+const char kCldManifestName[] = "Cld";
+
+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;
+
+ 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) {
+ // Copy the file from the install directory to the user data directory.
+ // We can't copy straight to the destination path, though, because the file
+ // might start being read before it is done being written. So copy it to a
+ // temporary location first, then rename it.
+ // We can'd delete the installed copy, because Component Updater needs it
+ // to stay where it is.
+ // TODO(andrewhayden): Change the logic to allow the component updater to
+ // set the location of the input file for readers.
+ base::FilePath source_path = install_dir.Append(chrome::kCLDDataFilename);
+ base::FilePath temp_path = install_dir.Append(chrome::kCLDDataFilename)
+ .Append(".tmp");
+ if (!base::CopyFile(source_path, temp_path)) {
+ LOG(WARNING) << "failed to copy cld data file";
+ return false;
+ }
+ base::FilePath final_path = install_dir.Append(chrome::kCLDDataFilename);;
+ if (!base::Move(temp_path, final_path)) {
+ LOG(WARNING) << "failed to rename cld data file";
+ return false;
+ }
+ return true;
+}
+
+void CldComponentInstallerTraits::ComponentReady(
+ const base::Version& version,
+ const base::FilePath& path,
+ scoped_ptr<base::DictionaryValue> manifest) {
+ // TODO(andrewhayden): set the location of the input file for all readers
+}
+
+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;
+ // TODO(andrewhayden): introduce a new subdir?
+ PathService::Get(chrome::DIR_USER_DATA, &result);
+ return result;
+}
+
+void CldComponentInstallerTraits::GetHash(
+ std::vector<uint8>* hash) const {
+ hash->assign(kSha2Hash, kSha2Hash + arraysize(kSha2Hash));
+}
+
+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);
+}
+
+} // namespace component_updater

Powered by Google App Engine
This is Rietveld 408576698