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/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/task.h" | 9 #include "base/task.h" |
10 #include "chrome/browser/chrome_thread.h" | |
11 #include "chrome/browser/extensions/extension_creator.h" | 10 #include "chrome/browser/extensions/extension_creator.h" |
12 | 11 |
13 PackExtensionJob::PackExtensionJob(Client* client, | 12 PackExtensionJob::PackExtensionJob(Client* client, |
14 const FilePath& root_directory, | 13 const FilePath& root_directory, |
15 const FilePath& key_file) | 14 const FilePath& key_file) |
16 : ui_loop_(MessageLoop::current()), client_(client), | 15 : client_(client), root_directory_(root_directory), key_file_(key_file) { |
17 root_directory_(root_directory), key_file_(key_file) { | 16 CHECK(ChromeThread::GetCurrentThreadIdentifier(&client_thread_id_)); |
18 ChromeThread::PostTask( | 17 ChromeThread::PostTask( |
19 ChromeThread::FILE, FROM_HERE, | 18 ChromeThread::FILE, FROM_HERE, |
20 NewRunnableMethod(this, &PackExtensionJob::RunOnFileThread)); | 19 NewRunnableMethod(this, &PackExtensionJob::RunOnFileThread)); |
21 } | 20 } |
22 | 21 |
23 void PackExtensionJob::ClearClient() { | 22 void PackExtensionJob::ClearClient() { |
24 client_ = NULL; | 23 client_ = NULL; |
25 } | 24 } |
26 | 25 |
27 void PackExtensionJob::RunOnFileThread() { | 26 void PackExtensionJob::RunOnFileThread() { |
28 crx_file_out_ = root_directory_.ReplaceExtension(FILE_PATH_LITERAL("crx")); | 27 crx_file_out_ = root_directory_.ReplaceExtension(FILE_PATH_LITERAL("crx")); |
29 | 28 |
30 if (key_file_.empty()) | 29 if (key_file_.empty()) |
31 key_file_out_ = root_directory_.ReplaceExtension(FILE_PATH_LITERAL("pem")); | 30 key_file_out_ = root_directory_.ReplaceExtension(FILE_PATH_LITERAL("pem")); |
32 | 31 |
33 // TODO(aa): Need to internationalize the errors that ExtensionCreator | 32 // TODO(aa): Need to internationalize the errors that ExtensionCreator |
34 // returns. See bug 20734. | 33 // returns. See bug 20734. |
35 ExtensionCreator creator; | 34 ExtensionCreator creator; |
36 if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_)) { | 35 if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_)) { |
37 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 36 ChromeThread::PostTask( |
38 &PackExtensionJob::ReportSuccessOnUIThread)); | 37 client_thread_id_, FROM_HERE, |
| 38 NewRunnableMethod(this, &PackExtensionJob::ReportSuccessOnUIThread)); |
39 } else { | 39 } else { |
40 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 40 ChromeThread::PostTask( |
41 &PackExtensionJob::ReportFailureOnUIThread, creator.error_message())); | 41 client_thread_id_, FROM_HERE, |
| 42 NewRunnableMethod( |
| 43 this, &PackExtensionJob::ReportFailureOnUIThread, |
| 44 creator.error_message())); |
42 } | 45 } |
43 } | 46 } |
44 | 47 |
45 void PackExtensionJob::ReportSuccessOnUIThread() { | 48 void PackExtensionJob::ReportSuccessOnUIThread() { |
46 if (client_) | 49 if (client_) |
47 client_->OnPackSuccess(crx_file_out_, key_file_out_); | 50 client_->OnPackSuccess(crx_file_out_, key_file_out_); |
48 } | 51 } |
49 | 52 |
50 void PackExtensionJob::ReportFailureOnUIThread(const std::string& error) { | 53 void PackExtensionJob::ReportFailureOnUIThread(const std::string& error) { |
51 if (client_) | 54 if (client_) |
52 client_->OnPackFailure(UTF8ToWide(error)); | 55 client_->OnPackFailure(UTF8ToWide(error)); |
53 } | 56 } |
OLD | NEW |