| 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/extensions/startup_helper.h" | 5 #include "chrome/browser/extensions/startup_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 pack_job_->set_asynchronous(false); | 113 pack_job_->set_asynchronous(false); |
| 114 pack_job_->Start(); | 114 pack_job_->Start(); |
| 115 | 115 |
| 116 return pack_job_succeeded_; | 116 return pack_job_succeeded_; |
| 117 } | 117 } |
| 118 | 118 |
| 119 namespace { | 119 namespace { |
| 120 | 120 |
| 121 class ValidateCrxHelper : public SandboxedUnpackerClient { | 121 class ValidateCrxHelper : public SandboxedUnpackerClient { |
| 122 public: | 122 public: |
| 123 ValidateCrxHelper(const base::FilePath& crx_file, | 123 ValidateCrxHelper(const CRXFileInfo& file, |
| 124 const base::FilePath& temp_dir, | 124 const base::FilePath& temp_dir, |
| 125 base::RunLoop* run_loop) | 125 base::RunLoop* run_loop) |
| 126 : crx_file_(crx_file), temp_dir_(temp_dir), run_loop_(run_loop), | 126 : crx_file_(file), |
| 127 finished_(false), success_(false) {} | 127 temp_dir_(temp_dir), |
| 128 run_loop_(run_loop), |
| 129 finished_(false), |
| 130 success_(false) {} |
| 128 | 131 |
| 129 bool finished() { return finished_; } | 132 bool finished() { return finished_; } |
| 130 bool success() { return success_; } | 133 bool success() { return success_; } |
| 131 const base::string16& error() { return error_; } | 134 const base::string16& error() { return error_; } |
| 132 | 135 |
| 133 void Start() { | 136 void Start() { |
| 134 BrowserThread::PostTask(BrowserThread::FILE, | 137 BrowserThread::PostTask(BrowserThread::FILE, |
| 135 FROM_HERE, | 138 FROM_HERE, |
| 136 base::Bind(&ValidateCrxHelper::StartOnFileThread, | 139 base::Bind(&ValidateCrxHelper::StartOnFileThread, |
| 137 this)); | 140 this)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 new SandboxedUnpacker(crx_file_, | 181 new SandboxedUnpacker(crx_file_, |
| 179 Manifest::INTERNAL, | 182 Manifest::INTERNAL, |
| 180 0, /* no special creation flags */ | 183 0, /* no special creation flags */ |
| 181 temp_dir_, | 184 temp_dir_, |
| 182 file_thread_proxy.get(), | 185 file_thread_proxy.get(), |
| 183 this)); | 186 this)); |
| 184 unpacker->Start(); | 187 unpacker->Start(); |
| 185 } | 188 } |
| 186 | 189 |
| 187 // The file being validated. | 190 // The file being validated. |
| 188 const base::FilePath& crx_file_; | 191 const CRXFileInfo& crx_file_; |
| 189 | 192 |
| 190 // The temporary directory where the sandboxed unpacker will do work. | 193 // The temporary directory where the sandboxed unpacker will do work. |
| 191 const base::FilePath& temp_dir_; | 194 const base::FilePath& temp_dir_; |
| 192 | 195 |
| 193 // Unowned pointer to a runloop, so our consumer can wait for us to finish. | 196 // Unowned pointer to a runloop, so our consumer can wait for us to finish. |
| 194 base::RunLoop* run_loop_; | 197 base::RunLoop* run_loop_; |
| 195 | 198 |
| 196 // Whether we're finished unpacking; | 199 // Whether we're finished unpacking; |
| 197 bool finished_; | 200 bool finished_; |
| 198 | 201 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 215 return false; | 218 return false; |
| 216 } | 219 } |
| 217 base::ScopedTempDir temp_dir; | 220 base::ScopedTempDir temp_dir; |
| 218 | 221 |
| 219 if (!temp_dir.CreateUniqueTempDir()) { | 222 if (!temp_dir.CreateUniqueTempDir()) { |
| 220 *error = std::string("Failed to create temp dir"); | 223 *error = std::string("Failed to create temp dir"); |
| 221 return false; | 224 return false; |
| 222 } | 225 } |
| 223 | 226 |
| 224 base::RunLoop run_loop; | 227 base::RunLoop run_loop; |
| 228 CRXFileInfo file(path); |
| 225 scoped_refptr<ValidateCrxHelper> helper( | 229 scoped_refptr<ValidateCrxHelper> helper( |
| 226 new ValidateCrxHelper(path, temp_dir.path(), &run_loop)); | 230 new ValidateCrxHelper(file, temp_dir.path(), &run_loop)); |
| 227 helper->Start(); | 231 helper->Start(); |
| 228 if (!helper->finished()) | 232 if (!helper->finished()) |
| 229 run_loop.Run(); | 233 run_loop.Run(); |
| 230 | 234 |
| 231 bool success = helper->success(); | 235 bool success = helper->success(); |
| 232 if (!success) | 236 if (!success) |
| 233 *error = base::UTF16ToUTF8(helper->error()); | 237 *error = base::UTF16ToUTF8(helper->error()); |
| 234 return success; | 238 return success; |
| 235 } | 239 } |
| 236 | 240 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 LOG(ERROR) << "InstallFromWebstore failed with error: " << helper.error(); | 327 LOG(ERROR) << "InstallFromWebstore failed with error: " << helper.error(); |
| 324 return helper.success(); | 328 return helper.success(); |
| 325 } | 329 } |
| 326 | 330 |
| 327 StartupHelper::~StartupHelper() { | 331 StartupHelper::~StartupHelper() { |
| 328 if (pack_job_.get()) | 332 if (pack_job_.get()) |
| 329 pack_job_->ClearClient(); | 333 pack_job_->ClearClient(); |
| 330 } | 334 } |
| 331 | 335 |
| 332 } // namespace extensions | 336 } // namespace extensions |
| OLD | NEW |