| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util.h" |
| 7 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 9 #include "base/task.h" | 10 #include "base/task.h" |
| 10 #include "chrome/browser/extensions/extension_creator.h" | 11 #include "chrome/browser/extensions/extension_creator.h" |
| 12 #include "chrome/common/chrome_constants.h" |
| 13 #include "grit/generated_resources.h" |
| 11 | 14 |
| 12 PackExtensionJob::PackExtensionJob(Client* client, | 15 PackExtensionJob::PackExtensionJob(Client* client, |
| 13 const FilePath& root_directory, | 16 const FilePath& root_directory, |
| 14 const FilePath& key_file) | 17 const FilePath& key_file) |
| 15 : client_(client), root_directory_(root_directory), key_file_(key_file) { | 18 : client_(client), key_file_(key_file) { |
| 19 root_directory_ = root_directory.StripTrailingSeparators(); |
| 16 CHECK(ChromeThread::GetCurrentThreadIdentifier(&client_thread_id_)); | 20 CHECK(ChromeThread::GetCurrentThreadIdentifier(&client_thread_id_)); |
| 17 } | 21 } |
| 18 | 22 |
| 19 void PackExtensionJob::Start() { | 23 void PackExtensionJob::Start() { |
| 20 ChromeThread::PostTask( | 24 ChromeThread::PostTask( |
| 21 ChromeThread::FILE, FROM_HERE, | 25 ChromeThread::FILE, FROM_HERE, |
| 22 NewRunnableMethod(this, &PackExtensionJob::RunOnFileThread)); | 26 NewRunnableMethod(this, &PackExtensionJob::RunOnFileThread)); |
| 23 } | 27 } |
| 24 | 28 |
| 25 void PackExtensionJob::ClearClient() { | 29 void PackExtensionJob::ClearClient() { |
| 26 client_ = NULL; | 30 client_ = NULL; |
| 27 } | 31 } |
| 28 | 32 |
| 29 void PackExtensionJob::RunOnFileThread() { | 33 void PackExtensionJob::RunOnFileThread() { |
| 30 crx_file_out_ = root_directory_.ReplaceExtension(FILE_PATH_LITERAL("crx")); | 34 crx_file_out_ = FilePath(root_directory_.value() + |
| 35 chrome::kExtensionFileExtension); |
| 31 | 36 |
| 32 if (key_file_.empty()) | 37 if (key_file_.empty()) |
| 33 key_file_out_ = root_directory_.ReplaceExtension(FILE_PATH_LITERAL("pem")); | 38 key_file_out_ = FilePath(root_directory_.value() + |
| 39 chrome::kExtensionKeyFileExtension); |
| 34 | 40 |
| 35 // TODO(aa): Need to internationalize the errors that ExtensionCreator | 41 // TODO(aa): Need to internationalize the errors that ExtensionCreator |
| 36 // returns. See bug 20734. | 42 // returns. See bug 20734. |
| 37 ExtensionCreator creator; | 43 ExtensionCreator creator; |
| 38 if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_)) { | 44 if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_)) { |
| 39 ChromeThread::PostTask( | 45 ChromeThread::PostTask( |
| 40 client_thread_id_, FROM_HERE, | 46 client_thread_id_, FROM_HERE, |
| 41 NewRunnableMethod(this, &PackExtensionJob::ReportSuccessOnUIThread)); | 47 NewRunnableMethod(this, |
| 48 &PackExtensionJob::ReportSuccessOnClientThread)); |
| 42 } else { | 49 } else { |
| 43 ChromeThread::PostTask( | 50 ChromeThread::PostTask( |
| 44 client_thread_id_, FROM_HERE, | 51 client_thread_id_, FROM_HERE, |
| 45 NewRunnableMethod( | 52 NewRunnableMethod( |
| 46 this, &PackExtensionJob::ReportFailureOnUIThread, | 53 this, &PackExtensionJob::ReportFailureOnClientThread, |
| 47 creator.error_message())); | 54 creator.error_message())); |
| 48 } | 55 } |
| 49 } | 56 } |
| 50 | 57 |
| 51 void PackExtensionJob::ReportSuccessOnUIThread() { | 58 void PackExtensionJob::ReportSuccessOnClientThread() { |
| 52 if (client_) | 59 if (client_) |
| 53 client_->OnPackSuccess(crx_file_out_, key_file_out_); | 60 client_->OnPackSuccess(crx_file_out_, key_file_out_); |
| 54 } | 61 } |
| 55 | 62 |
| 56 void PackExtensionJob::ReportFailureOnUIThread(const std::string& error) { | 63 void PackExtensionJob::ReportFailureOnClientThread(const std::string& error) { |
| 57 if (client_) | 64 if (client_) |
| 58 client_->OnPackFailure(error); | 65 client_->OnPackFailure(error); |
| 59 } | 66 } |
| 67 |
| 68 // static |
| 69 std::wstring PackExtensionJob::StandardSuccessMessage(const FilePath& crx_file, |
| 70 const FilePath& key_file) |
| 71 { |
| 72 // TODO(isherman): we should use string16 instead of wstring. |
| 73 // See crbug.com/23581 and crbug.com/24672 |
| 74 std::wstring message; |
| 75 if (key_file.empty()) { |
| 76 return l10n_util::GetStringF( |
| 77 IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_UPDATE, |
| 78 crx_file.ToWStringHack()); |
| 79 } else { |
| 80 return l10n_util::GetStringF( |
| 81 IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_NEW, |
| 82 crx_file.ToWStringHack(), |
| 83 key_file.ToWStringHack()); |
| 84 } |
| 85 } |
| OLD | NEW |