Chromium Code Reviews| 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 "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "chrome/browser/extensions/extension_creator.h" | 10 #include "chrome/browser/extensions/extension_creator.h" |
| 11 #include "chrome/common/chrome_constants.h" | |
| 11 | 12 |
| 12 PackExtensionJob::PackExtensionJob(Client* client, | 13 PackExtensionJob::PackExtensionJob(Client* client, |
| 13 const FilePath& root_directory, | 14 const FilePath& root_directory, |
| 14 const FilePath& key_file) | 15 const FilePath& key_file) |
| 15 : client_(client), root_directory_(root_directory), key_file_(key_file) { | 16 : client_(client), key_file_(key_file) { |
| 17 root_directory_ = root_directory.StripTrailingSeparators(); | |
| 16 CHECK(ChromeThread::GetCurrentThreadIdentifier(&client_thread_id_)); | 18 CHECK(ChromeThread::GetCurrentThreadIdentifier(&client_thread_id_)); |
| 17 } | 19 } |
| 18 | 20 |
| 19 void PackExtensionJob::Start() { | 21 void PackExtensionJob::Start() { |
| 20 ChromeThread::PostTask( | 22 ChromeThread::PostTask( |
| 21 ChromeThread::FILE, FROM_HERE, | 23 ChromeThread::FILE, FROM_HERE, |
| 22 NewRunnableMethod(this, &PackExtensionJob::RunOnFileThread)); | 24 NewRunnableMethod(this, &PackExtensionJob::RunOnFileThread)); |
| 23 } | 25 } |
| 24 | 26 |
| 25 void PackExtensionJob::ClearClient() { | 27 void PackExtensionJob::ClearClient() { |
| 26 client_ = NULL; | 28 client_ = NULL; |
| 27 } | 29 } |
| 28 | 30 |
| 29 void PackExtensionJob::RunOnFileThread() { | 31 void PackExtensionJob::RunOnFileThread() { |
| 30 crx_file_out_ = root_directory_.ReplaceExtension(FILE_PATH_LITERAL("crx")); | 32 crx_file_out_ = FilePath(root_directory_.value() + |
| 33 chrome::kExtensionFileExtension); | |
| 31 | 34 |
| 32 if (key_file_.empty()) | 35 if (key_file_.empty()) |
| 33 key_file_out_ = root_directory_.ReplaceExtension(FILE_PATH_LITERAL("pem")); | 36 key_file_out_ = FilePath(root_directory_.value() + |
| 37 chrome::kExtensionKeyFileExtension); | |
| 34 | 38 |
| 35 // TODO(aa): Need to internationalize the errors that ExtensionCreator | 39 // TODO(aa): Need to internationalize the errors that ExtensionCreator |
| 36 // returns. See bug 20734. | 40 // returns. See bug 20734. |
| 37 ExtensionCreator creator; | 41 ExtensionCreator creator; |
| 38 if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_)) { | 42 if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_)) { |
| 39 ChromeThread::PostTask( | 43 ChromeThread::PostTask( |
| 40 client_thread_id_, FROM_HERE, | 44 client_thread_id_, FROM_HERE, |
| 41 NewRunnableMethod(this, &PackExtensionJob::ReportSuccessOnUIThread)); | 45 NewRunnableMethod(this, &PackExtensionJob::ReportSuccessOnClientThread)) ; |
|
Matt Perry
2010/08/06 00:03:55
80 cols
| |
| 42 } else { | 46 } else { |
| 43 ChromeThread::PostTask( | 47 ChromeThread::PostTask( |
| 44 client_thread_id_, FROM_HERE, | 48 client_thread_id_, FROM_HERE, |
| 45 NewRunnableMethod( | 49 NewRunnableMethod( |
| 46 this, &PackExtensionJob::ReportFailureOnUIThread, | 50 this, &PackExtensionJob::ReportFailureOnClientThread, |
| 47 creator.error_message())); | 51 creator.error_message())); |
| 48 } | 52 } |
| 49 } | 53 } |
| 50 | 54 |
| 51 void PackExtensionJob::ReportSuccessOnUIThread() { | 55 void PackExtensionJob::ReportSuccessOnClientThread() { |
| 52 if (client_) | 56 if (client_) |
| 53 client_->OnPackSuccess(crx_file_out_, key_file_out_); | 57 client_->OnPackSuccess(crx_file_out_, key_file_out_); |
| 54 } | 58 } |
| 55 | 59 |
| 56 void PackExtensionJob::ReportFailureOnUIThread(const std::string& error) { | 60 void PackExtensionJob::ReportFailureOnClientThread(const std::string& error) { |
| 57 if (client_) | 61 if (client_) |
| 58 client_->OnPackFailure(UTF8ToWide(error)); | 62 client_->OnPackFailure(error); |
| 59 } | 63 } |
| OLD | NEW |