| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/pnacl/pnacl_component_installer.h" | 5 #include "chrome/browser/component_updater/pnacl/pnacl_component_installer.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 bool PnaclComponentInstaller::Install(base::DictionaryValue* manifest, | 157 bool PnaclComponentInstaller::Install(base::DictionaryValue* manifest, |
| 158 const FilePath& unpack_path) { | 158 const FilePath& unpack_path) { |
| 159 Version version; | 159 Version version; |
| 160 if (!CheckPnaclComponentManifest(manifest, &version)) | 160 if (!CheckPnaclComponentManifest(manifest, &version)) |
| 161 return false; | 161 return false; |
| 162 if (current_version_.CompareTo(version) > 0) | 162 if (current_version_.CompareTo(version) > 0) |
| 163 return false; | 163 return false; |
| 164 | 164 |
| 165 // Make sure that at least one of the compiler files exists. | 165 // Make sure that at least one of the compiler files exists. |
| 166 if (!file_util::PathExists(unpack_path.Append(kPnaclCompilerFileName))) | 166 if (!file_util::PathExists( |
| 167 unpack_path.Append(kPnaclArch).Append(kPnaclCompilerFileName))) |
| 167 return false; | 168 return false; |
| 168 | 169 |
| 169 // Passed the basic tests. Time to install it. | 170 // Passed the basic tests. Time to install it. |
| 170 FilePath path = | 171 FilePath path = |
| 171 GetPnaclBaseDirectory().AppendASCII(version.GetString()); | 172 GetPnaclBaseDirectory().AppendASCII(version.GetString()); |
| 172 if (file_util::PathExists(path)) | 173 if (file_util::PathExists(path)) |
| 173 return false; | 174 return false; |
| 174 if (!file_util::Move(unpack_path, path)) | 175 if (!file_util::Move(unpack_path, path)) |
| 175 return false; | 176 return false; |
| 176 | 177 |
| 177 // Installation is done. Now tell the rest of chrome (just the path service | 178 // Installation is done. Now tell the rest of chrome (just the path service |
| 178 // for now). TODO(jvoung): we need notifications if someone surfed to a | 179 // for now). TODO(jvoung): we need notifications if someone surfed to a |
| 179 // Pnacl webpage and Pnacl was just installed at this time. They should | 180 // Pnacl webpage and Pnacl was just installed at this time. They should |
| 180 // then be able to reload the page and retry (or something). | 181 // then be able to reload the page and retry (or something). |
| 181 // See: http://code.google.com/p/chromium/issues/detail?id=107438 | 182 // See: http://code.google.com/p/chromium/issues/detail?id=107438 |
| 182 current_version_ = version; | 183 current_version_ = version; |
| 183 | 184 |
| 184 PathService::Override(chrome::FILE_PNACL_COMPONENT, path); | 185 PathService::Override(chrome::DIR_PNACL_COMPONENT, path); |
| 185 return true; | 186 return true; |
| 186 } | 187 } |
| 187 | 188 |
| 188 namespace { | 189 namespace { |
| 189 | 190 |
| 190 // Finally, do the registration with the right version number. | 191 // Finally, do the registration with the right version number. |
| 191 void FinishPnaclUpdateRegistration(ComponentUpdateService* cus, | 192 void FinishPnaclUpdateRegistration(ComponentUpdateService* cus, |
| 192 const Version& version) { | 193 const Version& version) { |
| 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 194 CrxComponent pnacl; | 195 CrxComponent pnacl; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 214 } | 215 } |
| 215 | 216 |
| 216 Version version(kNullVersion); | 217 Version version(kNullVersion); |
| 217 if (GetLatestPnaclDirectory(&path, &version)) { | 218 if (GetLatestPnaclDirectory(&path, &version)) { |
| 218 // Check if one of the Pnacl files is really there. | 219 // Check if one of the Pnacl files is really there. |
| 219 FilePath compiler_path = path.Append(kPnaclCompilerFileName); | 220 FilePath compiler_path = path.Append(kPnaclCompilerFileName); |
| 220 if (!file_util::PathExists(compiler_path)) { | 221 if (!file_util::PathExists(compiler_path)) { |
| 221 version = Version(kNullVersion); | 222 version = Version(kNullVersion); |
| 222 } else { | 223 } else { |
| 223 // Register the existing path for now, before checking for updates. | 224 // Register the existing path for now, before checking for updates. |
| 224 // TODO(jvoung): Will this always happen "early" or will it | 225 PathService::Override(chrome::DIR_PNACL_COMPONENT, path); |
| 225 // race with the NaCl plugin in browser tests? | |
| 226 PathService::Override(chrome::FILE_PNACL_COMPONENT, path); | |
| 227 } | 226 } |
| 228 } | 227 } |
| 229 | 228 |
| 230 BrowserThread::PostTask( | 229 BrowserThread::PostTask( |
| 231 BrowserThread::UI, FROM_HERE, | 230 BrowserThread::UI, FROM_HERE, |
| 232 base::Bind(&FinishPnaclUpdateRegistration, cus, version)); | 231 base::Bind(&FinishPnaclUpdateRegistration, cus, version)); |
| 233 } | 232 } |
| 234 | 233 |
| 235 } // namespace | 234 } // namespace |
| 236 | 235 |
| 237 void RegisterPnaclComponent(ComponentUpdateService* cus) { | 236 void RegisterPnaclComponent(ComponentUpdateService* cus) { |
| 238 BrowserThread::PostTask( | 237 BrowserThread::PostTask( |
| 239 BrowserThread::FILE, FROM_HERE, | 238 BrowserThread::FILE, FROM_HERE, |
| 240 base::Bind(&StartPnaclUpdateRegistration, cus)); | 239 base::Bind(&StartPnaclUpdateRegistration, cus)); |
| 241 } | 240 } |
| OLD | NEW |