| OLD | NEW |
| 1 // Copyright (c) 2012 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 "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 return NULL; | 115 return NULL; |
| 116 if (!root->IsType(base::Value::TYPE_DICTIONARY)) | 116 if (!root->IsType(base::Value::TYPE_DICTIONARY)) |
| 117 return NULL; | 117 return NULL; |
| 118 return static_cast<base::DictionaryValue*>(root.release()); | 118 return static_cast<base::DictionaryValue*>(root.release()); |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Read the PNaCl specific manifest. | 121 // Read the PNaCl specific manifest. |
| 122 base::DictionaryValue* ReadPnaclManifest(const base::FilePath& unpack_path) { | 122 base::DictionaryValue* ReadPnaclManifest(const base::FilePath& unpack_path) { |
| 123 base::FilePath manifest_path = GetPlatformDir(unpack_path).AppendASCII( | 123 base::FilePath manifest_path = GetPlatformDir(unpack_path).AppendASCII( |
| 124 "pnacl_public_pnacl_json"); | 124 "pnacl_public_pnacl_json"); |
| 125 if (!file_util::PathExists(manifest_path)) | 125 if (!base::PathExists(manifest_path)) |
| 126 return NULL; | 126 return NULL; |
| 127 return ReadJSONManifest(manifest_path); | 127 return ReadJSONManifest(manifest_path); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Read the component's manifest.json. | 130 // Read the component's manifest.json. |
| 131 base::DictionaryValue* ReadComponentManifest( | 131 base::DictionaryValue* ReadComponentManifest( |
| 132 const base::FilePath& unpack_path) { | 132 const base::FilePath& unpack_path) { |
| 133 base::FilePath manifest_path = unpack_path.Append( | 133 base::FilePath manifest_path = unpack_path.Append( |
| 134 FILE_PATH_LITERAL("manifest.json")); | 134 FILE_PATH_LITERAL("manifest.json")); |
| 135 if (!file_util::PathExists(manifest_path)) | 135 if (!base::PathExists(manifest_path)) |
| 136 return NULL; | 136 return NULL; |
| 137 return ReadJSONManifest(manifest_path); | 137 return ReadJSONManifest(manifest_path); |
| 138 } | 138 } |
| 139 | 139 |
| 140 } // namespace | 140 } // namespace |
| 141 | 141 |
| 142 // Check that the component's manifest is for PNaCl, and check the | 142 // Check that the component's manifest is for PNaCl, and check the |
| 143 // PNaCl manifest indicates this is the correct arch-specific package. | 143 // PNaCl manifest indicates this is the correct arch-specific package. |
| 144 bool CheckPnaclComponentManifest(const base::DictionaryValue& manifest, | 144 bool CheckPnaclComponentManifest(const base::DictionaryValue& manifest, |
| 145 const base::DictionaryValue& pnacl_manifest, | 145 const base::DictionaryValue& pnacl_manifest, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 258 |
| 259 // Don't install if the current version is actually newer. | 259 // Don't install if the current version is actually newer. |
| 260 if (current_version().CompareTo(version) > 0) { | 260 if (current_version().CompareTo(version) > 0) { |
| 261 NotifyInstallError(); | 261 NotifyInstallError(); |
| 262 return false; | 262 return false; |
| 263 } | 263 } |
| 264 | 264 |
| 265 // Passed the basic tests. Time to install it. | 265 // Passed the basic tests. Time to install it. |
| 266 base::FilePath path = GetPnaclBaseDirectory().AppendASCII( | 266 base::FilePath path = GetPnaclBaseDirectory().AppendASCII( |
| 267 version.GetString()); | 267 version.GetString()); |
| 268 if (file_util::PathExists(path)) { | 268 if (base::PathExists(path)) { |
| 269 LOG(WARNING) << "Target path already exists, not installing."; | 269 LOG(WARNING) << "Target path already exists, not installing."; |
| 270 NotifyInstallError(); | 270 NotifyInstallError(); |
| 271 return false; | 271 return false; |
| 272 } | 272 } |
| 273 if (!base::Move(unpack_path, path)) { | 273 if (!base::Move(unpack_path, path)) { |
| 274 LOG(WARNING) << "Move failed, not installing."; | 274 LOG(WARNING) << "Move failed, not installing."; |
| 275 NotifyInstallError(); | 275 NotifyInstallError(); |
| 276 return false; | 276 return false; |
| 277 } | 277 } |
| 278 | 278 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 && status != ComponentUpdateService::kReplaced) { | 365 && status != ComponentUpdateService::kReplaced) { |
| 366 NOTREACHED() << "Pnacl component registration failed."; | 366 NOTREACHED() << "Pnacl component registration failed."; |
| 367 } | 367 } |
| 368 } | 368 } |
| 369 | 369 |
| 370 // Check if there is an existing version on disk first to know when | 370 // Check if there is an existing version on disk first to know when |
| 371 // a hosted version is actually newer. | 371 // a hosted version is actually newer. |
| 372 void StartPnaclUpdateRegistration(PnaclComponentInstaller* pci) { | 372 void StartPnaclUpdateRegistration(PnaclComponentInstaller* pci) { |
| 373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 374 base::FilePath path = pci->GetPnaclBaseDirectory(); | 374 base::FilePath path = pci->GetPnaclBaseDirectory(); |
| 375 if (!file_util::PathExists(path)) { | 375 if (!base::PathExists(path)) { |
| 376 if (!file_util::CreateDirectory(path)) { | 376 if (!file_util::CreateDirectory(path)) { |
| 377 NOTREACHED() << "Could not create base Pnacl directory."; | 377 NOTREACHED() << "Could not create base Pnacl directory."; |
| 378 return; | 378 return; |
| 379 } | 379 } |
| 380 } | 380 } |
| 381 | 381 |
| 382 Version version(kNullVersion); | 382 Version version(kNullVersion); |
| 383 std::vector<base::FilePath> older_dirs; | 383 std::vector<base::FilePath> older_dirs; |
| 384 if (GetLatestPnaclDirectory(pci, &path, &version, &older_dirs)) { | 384 if (GetLatestPnaclDirectory(pci, &path, &version, &older_dirs)) { |
| 385 scoped_ptr<base::DictionaryValue> manifest( | 385 scoped_ptr<base::DictionaryValue> manifest( |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 pnacl_component.installer = pci; | 476 pnacl_component.installer = pci; |
| 477 SetPnaclHash(&pnacl_component); | 477 SetPnaclHash(&pnacl_component); |
| 478 ComponentUpdateService::Status status = cus->CheckForUpdateSoon( | 478 ComponentUpdateService::Status status = cus->CheckForUpdateSoon( |
| 479 pnacl_component); | 479 pnacl_component); |
| 480 if (status != ComponentUpdateService::kOk) { | 480 if (status != ComponentUpdateService::kOk) { |
| 481 installed.Run(false); | 481 installed.Run(false); |
| 482 return; | 482 return; |
| 483 } | 483 } |
| 484 pci->AddInstallCallback(installed); | 484 pci->AddInstallCallback(installed); |
| 485 } | 485 } |
| OLD | NEW |