| 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/pack_extension_job.h" | 5 #include "chrome/browser/extensions/pack_extension_job.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 const base::FilePath& key_file, | 22 const base::FilePath& key_file, |
| 23 int run_flags) | 23 int run_flags) |
| 24 : client_(client), key_file_(key_file), asynchronous_(true), | 24 : client_(client), key_file_(key_file), asynchronous_(true), |
| 25 run_flags_(run_flags | ExtensionCreator::kRequireModernManifestVersion) { | 25 run_flags_(run_flags | ExtensionCreator::kRequireModernManifestVersion) { |
| 26 root_directory_ = root_directory.StripTrailingSeparators(); | 26 root_directory_ = root_directory.StripTrailingSeparators(); |
| 27 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); | 27 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void PackExtensionJob::Start() { | 30 void PackExtensionJob::Start() { |
| 31 if (asynchronous_) { | 31 if (asynchronous_) { |
| 32 BrowserThread::PostTask( | 32 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 33 BrowserThread::FILE, FROM_HERE, | 33 base::BindOnce(&PackExtensionJob::Run, this)); |
| 34 base::Bind(&PackExtensionJob::Run, this)); | |
| 35 } else { | 34 } else { |
| 36 Run(); | 35 Run(); |
| 37 } | 36 } |
| 38 } | 37 } |
| 39 | 38 |
| 40 void PackExtensionJob::ClearClient() { | 39 void PackExtensionJob::ClearClient() { |
| 41 client_ = NULL; | 40 client_ = NULL; |
| 42 } | 41 } |
| 43 | 42 |
| 44 PackExtensionJob::~PackExtensionJob() {} | 43 PackExtensionJob::~PackExtensionJob() {} |
| 45 | 44 |
| 46 void PackExtensionJob::Run() { | 45 void PackExtensionJob::Run() { |
| 47 crx_file_out_ = base::FilePath(root_directory_.value() + | 46 crx_file_out_ = base::FilePath(root_directory_.value() + |
| 48 kExtensionFileExtension); | 47 kExtensionFileExtension); |
| 49 | 48 |
| 50 if (key_file_.empty()) | 49 if (key_file_.empty()) |
| 51 key_file_out_ = base::FilePath(root_directory_.value() + | 50 key_file_out_ = base::FilePath(root_directory_.value() + |
| 52 kExtensionKeyFileExtension); | 51 kExtensionKeyFileExtension); |
| 53 | 52 |
| 54 // TODO(aa): Need to internationalize the errors that ExtensionCreator | 53 // TODO(aa): Need to internationalize the errors that ExtensionCreator |
| 55 // returns. See bug 20734. | 54 // returns. See bug 20734. |
| 56 ExtensionCreator creator; | 55 ExtensionCreator creator; |
| 57 if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_, | 56 if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_, |
| 58 run_flags_)) { | 57 run_flags_)) { |
| 59 if (asynchronous_) { | 58 if (asynchronous_) { |
| 60 BrowserThread::PostTask( | 59 BrowserThread::PostTask( |
| 61 client_thread_id_, FROM_HERE, | 60 client_thread_id_, FROM_HERE, |
| 62 base::Bind(&PackExtensionJob::ReportSuccessOnClientThread, this)); | 61 base::BindOnce(&PackExtensionJob::ReportSuccessOnClientThread, this)); |
| 63 } else { | 62 } else { |
| 64 ReportSuccessOnClientThread(); | 63 ReportSuccessOnClientThread(); |
| 65 } | 64 } |
| 66 } else { | 65 } else { |
| 67 if (asynchronous_) { | 66 if (asynchronous_) { |
| 68 BrowserThread::PostTask( | 67 BrowserThread::PostTask( |
| 69 client_thread_id_, FROM_HERE, | 68 client_thread_id_, FROM_HERE, |
| 70 base::Bind( | 69 base::BindOnce(&PackExtensionJob::ReportFailureOnClientThread, this, |
| 71 &PackExtensionJob::ReportFailureOnClientThread, this, | 70 creator.error_message(), creator.error_type())); |
| 72 creator.error_message(), creator.error_type())); | |
| 73 } else { | 71 } else { |
| 74 ReportFailureOnClientThread(creator.error_message(), | 72 ReportFailureOnClientThread(creator.error_message(), |
| 75 creator.error_type()); | 73 creator.error_type()); |
| 76 } | 74 } |
| 77 } | 75 } |
| 78 } | 76 } |
| 79 | 77 |
| 80 void PackExtensionJob::ReportSuccessOnClientThread() { | 78 void PackExtensionJob::ReportSuccessOnClientThread() { |
| 81 if (client_) | 79 if (client_) |
| 82 client_->OnPackSuccess(crx_file_out_, key_file_out_); | 80 client_->OnPackSuccess(crx_file_out_, key_file_out_); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 101 crx_file_string); | 99 crx_file_string); |
| 102 } else { | 100 } else { |
| 103 return l10n_util::GetStringFUTF16( | 101 return l10n_util::GetStringFUTF16( |
| 104 IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_NEW, | 102 IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_NEW, |
| 105 crx_file_string, | 103 crx_file_string, |
| 106 key_file_string); | 104 key_file_string); |
| 107 } | 105 } |
| 108 } | 106 } |
| 109 | 107 |
| 110 } // namespace extensions | 108 } // namespace extensions |
| OLD | NEW |