Chromium Code Reviews| 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/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.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 "chrome/browser/component_updater/default_component_installer.h" | 16 #include "base/platform_file.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
| 19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "net/ssl/ssl_config_service.h" | 21 #include "net/ssl/ssl_config_service.h" |
| 22 | 22 |
| 23 using component_updater::ComponentUpdateService; | 23 using component_updater::ComponentUpdateService; |
| 24 using content::BrowserThread; | 24 using content::BrowserThread; |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 40 // The extension id is: dpedmmgabcgnikllifiidmijgoiihfgf | 40 // The extension id is: dpedmmgabcgnikllifiidmijgoiihfgf |
| 41 const uint8 kPublicKeySHA256[32] = { | 41 const uint8 kPublicKeySHA256[32] = { |
| 42 0x3f, 0x43, 0xcc, 0x60, 0x12, 0x6d, 0x8a, 0xbb, | 42 0x3f, 0x43, 0xcc, 0x60, 0x12, 0x6d, 0x8a, 0xbb, |
| 43 0x85, 0x88, 0x3c, 0x89, 0x6e, 0x88, 0x75, 0x65, | 43 0x85, 0x88, 0x3c, 0x89, 0x6e, 0x88, 0x75, 0x65, |
| 44 0xb9, 0x46, 0x09, 0xe8, 0xca, 0x92, 0xdd, 0x82, | 44 0xb9, 0x46, 0x09, 0xe8, 0xca, 0x92, 0xdd, 0x82, |
| 45 0x4e, 0x6d, 0x0e, 0xe6, 0x79, 0x8a, 0x87, 0xf5 | 45 0x4e, 0x6d, 0x0e, 0xe6, 0x79, 0x8a, 0x87, 0xf5 |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 const char kCldManifestName[] = "CLD2 Data"; | 48 const char kCldManifestName[] = "CLD2 Data"; |
| 49 | 49 |
| 50 class CldComponentInstallerTraits : public ComponentInstallerTraits { | |
| 51 public: | |
| 52 CldComponentInstallerTraits(); | |
| 53 virtual ~CldComponentInstallerTraits() {} | |
| 54 | |
| 55 private: | |
| 56 // The following methods override ComponentInstallerTraits. | |
| 57 virtual bool CanAutoUpdate() const OVERRIDE; | |
| 58 virtual bool OnCustomInstall(const base::DictionaryValue& manifest, | |
| 59 const base::FilePath& install_dir) OVERRIDE; | |
| 60 virtual bool VerifyInstallation( | |
| 61 const base::FilePath& install_dir) const OVERRIDE; | |
| 62 virtual void ComponentReady( | |
| 63 const base::Version& version, | |
| 64 const base::FilePath& path, | |
| 65 scoped_ptr<base::DictionaryValue> manifest) OVERRIDE; | |
| 66 virtual base::FilePath GetBaseDirectory() const OVERRIDE; | |
| 67 virtual void GetHash(std::vector<uint8>* hash) const OVERRIDE; | |
| 68 virtual std::string GetName() const OVERRIDE; | |
| 69 | |
| 70 base::FilePath GetInstalledPath(const base::FilePath& base) const; | |
| 71 void SetLatestCldDataFile(const base::FilePath& path); | |
| 72 DISALLOW_COPY_AND_ASSIGN(CldComponentInstallerTraits); | |
| 73 }; | |
| 74 | |
| 75 CldComponentInstallerTraits::CldComponentInstallerTraits() { | 50 CldComponentInstallerTraits::CldComponentInstallerTraits() { |
| 76 } | 51 } |
| 77 | 52 |
| 78 bool CldComponentInstallerTraits::CanAutoUpdate() const { | 53 bool CldComponentInstallerTraits::CanAutoUpdate() const { |
| 79 return true; | 54 return true; |
| 80 } | 55 } |
| 81 | 56 |
| 82 bool CldComponentInstallerTraits::OnCustomInstall( | 57 bool CldComponentInstallerTraits::OnCustomInstall( |
| 83 const base::DictionaryValue& manifest, | 58 const base::DictionaryValue& manifest, |
| 84 const base::FilePath& install_dir) { | 59 const base::FilePath& install_dir) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 | 108 |
| 134 void RegisterCldComponent(ComponentUpdateService* cus) { | 109 void RegisterCldComponent(ComponentUpdateService* cus) { |
| 135 scoped_ptr<ComponentInstallerTraits> traits( | 110 scoped_ptr<ComponentInstallerTraits> traits( |
| 136 new CldComponentInstallerTraits()); | 111 new CldComponentInstallerTraits()); |
| 137 // |cus| will take ownership of |installer| during installer->Register(cus). | 112 // |cus| will take ownership of |installer| during installer->Register(cus). |
| 138 DefaultComponentInstaller* installer = | 113 DefaultComponentInstaller* installer = |
| 139 new DefaultComponentInstaller(traits.Pass()); | 114 new DefaultComponentInstaller(traits.Pass()); |
| 140 installer->Register(cus); | 115 installer->Register(cus); |
| 141 } | 116 } |
| 142 | 117 |
| 143 // This method is completely threadsafe. | |
| 144 void CldComponentInstallerTraits::SetLatestCldDataFile( | 118 void CldComponentInstallerTraits::SetLatestCldDataFile( |
| 145 const base::FilePath& path) { | 119 const base::FilePath& path) { |
| 146 VLOG(1) << "Setting CLD data file location: " << path.value(); | 120 VLOG(1) << "Setting CLD data file location: " << path.value(); |
| 147 base::AutoLock lock(cld_file_lock.Get()); | 121 base::AutoLock lock(cld_file_lock.Get()); |
| 148 cld_file.Get() = path; | 122 cld_file.Get() = path; |
| 149 } | 123 } |
| 150 | 124 |
| 151 bool GetLatestCldDataFile(base::FilePath* path) { | 125 base::FilePath GetLatestCldDataFile() { |
| 152 base::AutoLock lock(cld_file_lock.Get()); | 126 base::AutoLock lock(cld_file_lock.Get()); |
| 153 const base::FilePath cached = cld_file.Get(); | 127 // cld_file is an empty path by default, meaning "file not available yet", |
|
Sorin Jianu
2014/05/15 16:03:58
Excellent!
| |
| 154 if (cached.empty()) | 128 // so we can simply return by value (making a copy). |
|
Sorin Jianu
2014/05/15 16:03:58
@128 Comment not needed as it is both obvious and
Andrew Hayden (chromium.org)
2014/05/16 12:03:25
Done.
| |
| 155 return false; | 129 return cld_file.Get(); |
| 156 *path = cached; | |
| 157 return true; | |
| 158 } | 130 } |
| 159 | 131 |
| 160 } // namespace component_updater | 132 } // namespace component_updater |
| OLD | NEW |