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 "app/l10n_util.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/task.h" | 10 #include "base/task.h" |
11 #include "chrome/browser/extensions/extension_creator.h" | 11 #include "chrome/browser/extensions/extension_creator.h" |
12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
14 | 14 |
15 PackExtensionJob::PackExtensionJob(Client* client, | 15 PackExtensionJob::PackExtensionJob(Client* client, |
16 const FilePath& root_directory, | 16 const FilePath& root_directory, |
17 const FilePath& key_file) | 17 const FilePath& key_file) |
18 : client_(client), key_file_(key_file) { | 18 : client_(client), key_file_(key_file), asynchronous_(true) { |
19 root_directory_ = root_directory.StripTrailingSeparators(); | 19 root_directory_ = root_directory.StripTrailingSeparators(); |
20 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); | 20 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); |
21 } | 21 } |
22 | 22 |
23 void PackExtensionJob::Start() { | 23 void PackExtensionJob::Start() { |
24 BrowserThread::PostTask( | 24 if (asynchronous_) { |
25 BrowserThread::FILE, FROM_HERE, | 25 BrowserThread::PostTask( |
26 NewRunnableMethod(this, &PackExtensionJob::RunOnFileThread)); | 26 BrowserThread::FILE, FROM_HERE, |
| 27 NewRunnableMethod(this, &PackExtensionJob::Run)); |
| 28 } else { |
| 29 Run(); |
| 30 } |
27 } | 31 } |
28 | 32 |
29 void PackExtensionJob::ClearClient() { | 33 void PackExtensionJob::ClearClient() { |
30 client_ = NULL; | 34 client_ = NULL; |
31 } | 35 } |
32 | 36 |
33 PackExtensionJob::~PackExtensionJob() {} | 37 PackExtensionJob::~PackExtensionJob() {} |
34 | 38 |
35 void PackExtensionJob::RunOnFileThread() { | 39 void PackExtensionJob::Run() { |
36 crx_file_out_ = FilePath(root_directory_.value() + | 40 crx_file_out_ = FilePath(root_directory_.value() + |
37 chrome::kExtensionFileExtension); | 41 chrome::kExtensionFileExtension); |
38 | 42 |
39 if (key_file_.empty()) | 43 if (key_file_.empty()) |
40 key_file_out_ = FilePath(root_directory_.value() + | 44 key_file_out_ = FilePath(root_directory_.value() + |
41 chrome::kExtensionKeyFileExtension); | 45 chrome::kExtensionKeyFileExtension); |
42 | 46 |
43 // TODO(aa): Need to internationalize the errors that ExtensionCreator | 47 // TODO(aa): Need to internationalize the errors that ExtensionCreator |
44 // returns. See bug 20734. | 48 // returns. See bug 20734. |
45 ExtensionCreator creator; | 49 ExtensionCreator creator; |
46 if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_)) { | 50 if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_)) { |
47 BrowserThread::PostTask( | 51 if (asynchronous_) { |
48 client_thread_id_, FROM_HERE, | 52 BrowserThread::PostTask( |
49 NewRunnableMethod(this, | 53 client_thread_id_, FROM_HERE, |
50 &PackExtensionJob::ReportSuccessOnClientThread)); | 54 NewRunnableMethod(this, |
| 55 &PackExtensionJob::ReportSuccessOnClientThread)); |
| 56 } else { |
| 57 ReportSuccessOnClientThread(); |
| 58 } |
51 } else { | 59 } else { |
52 BrowserThread::PostTask( | 60 if (asynchronous_) { |
53 client_thread_id_, FROM_HERE, | 61 BrowserThread::PostTask( |
54 NewRunnableMethod( | 62 client_thread_id_, FROM_HERE, |
55 this, &PackExtensionJob::ReportFailureOnClientThread, | 63 NewRunnableMethod( |
56 creator.error_message())); | 64 this, &PackExtensionJob::ReportFailureOnClientThread, |
| 65 creator.error_message())); |
| 66 } else { |
| 67 ReportFailureOnClientThread(creator.error_message()); |
| 68 } |
57 } | 69 } |
58 } | 70 } |
59 | 71 |
60 void PackExtensionJob::ReportSuccessOnClientThread() { | 72 void PackExtensionJob::ReportSuccessOnClientThread() { |
61 if (client_) | 73 if (client_) |
62 client_->OnPackSuccess(crx_file_out_, key_file_out_); | 74 client_->OnPackSuccess(crx_file_out_, key_file_out_); |
63 } | 75 } |
64 | 76 |
65 void PackExtensionJob::ReportFailureOnClientThread(const std::string& error) { | 77 void PackExtensionJob::ReportFailureOnClientThread(const std::string& error) { |
66 if (client_) | 78 if (client_) |
(...skipping 11 matching lines...) Expand all Loading... |
78 return l10n_util::GetStringF( | 90 return l10n_util::GetStringF( |
79 IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_UPDATE, | 91 IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_UPDATE, |
80 crx_file.ToWStringHack()); | 92 crx_file.ToWStringHack()); |
81 } else { | 93 } else { |
82 return l10n_util::GetStringF( | 94 return l10n_util::GetStringF( |
83 IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_NEW, | 95 IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_NEW, |
84 crx_file.ToWStringHack(), | 96 crx_file.ToWStringHack(), |
85 key_file.ToWStringHack()); | 97 key_file.ToWStringHack()); |
86 } | 98 } |
87 } | 99 } |
OLD | NEW |