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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/component_updater/cld_component_installer.h"
6
7 #include "base/bind.h"
8 #include "base/file_util.h"
9 #include "base/numerics/safe_conversions.h"
10 #include "base/path_service.h"
11 #include "base/rand_util.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/time/time.h"
14 #include "chrome/browser/component_updater/default_component_installer.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/chrome_paths.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "net/ssl/ssl_config_service.h"
20
21 using component_updater::ComponentUpdateService;
22 using content::BrowserThread;
23
24 namespace component_updater {
25
26 // CRX hash. The extension id is: FIXME(andrewhayden)
27 const uint8 kSha2Hash[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
28 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
29 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
31
32 // File name of the CLD component manifest on different platforms.
33 const char kCldManifestName[] = "Cld";
34
35 class CldComponentInstallerTraits : public ComponentInstallerTraits {
36 public:
37 CldComponentInstallerTraits();
38 virtual ~CldComponentInstallerTraits() {}
39
40 private:
41 // The following methods override ComponentInstallerTraits.
42 virtual bool CanAutoUpdate() const OVERRIDE;
43 virtual bool OnCustomInstall(const base::DictionaryValue& manifest,
44 const base::FilePath& install_dir) OVERRIDE;
45 virtual bool VerifyInstallation(
46 const base::FilePath& install_dir) const OVERRIDE;
47 virtual void ComponentReady(
48 const base::Version& version,
49 const base::FilePath& path,
50 scoped_ptr<base::DictionaryValue> manifest) OVERRIDE;
51 virtual base::FilePath GetBaseDirectory() const OVERRIDE;
52 virtual void GetHash(std::vector<uint8>* hash) const OVERRIDE;
53 virtual std::string GetName() const OVERRIDE;
54
55 DISALLOW_COPY_AND_ASSIGN(CldComponentInstallerTraits);
56 };
57
58 CldComponentInstallerTraits::CldComponentInstallerTraits() {
59 }
60
61 bool CldComponentInstallerTraits::CanAutoUpdate() const {
62 return true;
63 }
64
65 bool CldComponentInstallerTraits::OnCustomInstall(
66 const base::DictionaryValue& manifest,
67 const base::FilePath& install_dir) {
68 // Copy the file from the install directory to the user data directory.
69 // We can't copy straight to the destination path, though, because the file
70 // might start being read before it is done being written. So copy it to a
71 // temporary location first, then rename it.
72 // We can'd delete the installed copy, because Component Updater needs it
73 // to stay where it is.
74 // TODO(andrewhayden): Change the logic to allow the component updater to
75 // set the location of the input file for readers.
76 base::FilePath source_path = install_dir.Append(chrome::kCLDDataFilename);
77 base::FilePath temp_path = install_dir.Append(chrome::kCLDDataFilename)
78 .Append(".tmp");
79 if (!base::CopyFile(source_path, temp_path)) {
80 LOG(WARNING) << "failed to copy cld data file";
81 return false;
82 }
83 base::FilePath final_path = install_dir.Append(chrome::kCLDDataFilename);;
84 if (!base::Move(temp_path, final_path)) {
85 LOG(WARNING) << "failed to rename cld data file";
86 return false;
87 }
88 return true;
89 }
90
91 void CldComponentInstallerTraits::ComponentReady(
92 const base::Version& version,
93 const base::FilePath& path,
94 scoped_ptr<base::DictionaryValue> manifest) {
95 // TODO(andrewhayden): set the location of the input file for all readers
96 }
97
98 bool CldComponentInstallerTraits::VerifyInstallation(
99 const base::FilePath& install_dir) const {
100 // We can't really do much to verify the CLD2 data file. In theory we could
101 // read the headers, but that won't do much other than tell us whether or
102 // not the headers are valid. So just check if the file exists.
103 return base::PathExists(install_dir.Append(chrome::kCLDDataFilename));
104 }
105
106 base::FilePath CldComponentInstallerTraits::GetBaseDirectory() const {
107 base::FilePath result;
108 // TODO(andrewhayden): introduce a new subdir?
109 PathService::Get(chrome::DIR_USER_DATA, &result);
110 return result;
111 }
112
113 void CldComponentInstallerTraits::GetHash(
114 std::vector<uint8>* hash) const {
115 hash->assign(kSha2Hash, kSha2Hash + arraysize(kSha2Hash));
116 }
117
118 std::string CldComponentInstallerTraits::GetName() const {
119 return kCldManifestName;
120 }
121
122 void RegisterCldComponent(ComponentUpdateService* cus) {
123 scoped_ptr<ComponentInstallerTraits> traits(
124 new CldComponentInstallerTraits);
125 // |cus| will take ownership of |installer| during installer->Register(cus).
126 DefaultComponentInstaller* installer
127 = new DefaultComponentInstaller(traits.Pass());
128 installer->Register(cus);
129 }
130
131 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698