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.h" | 8 #include "base/message_loop.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.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 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 | 15 |
16 using content::BrowserThread; | 16 using content::BrowserThread; |
17 | 17 |
| 18 namespace extensions { |
| 19 |
18 PackExtensionJob::PackExtensionJob(Client* client, | 20 PackExtensionJob::PackExtensionJob(Client* client, |
19 const FilePath& root_directory, | 21 const FilePath& root_directory, |
20 const FilePath& key_file, | 22 const FilePath& key_file, |
21 int run_flags) | 23 int run_flags) |
22 : client_(client), key_file_(key_file), asynchronous_(true), | 24 : client_(client), key_file_(key_file), asynchronous_(true), |
23 run_flags_(run_flags) { | 25 run_flags_(run_flags) { |
24 root_directory_ = root_directory.StripTrailingSeparators(); | 26 root_directory_ = root_directory.StripTrailingSeparators(); |
25 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); | 27 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); |
26 } | 28 } |
27 | 29 |
(...skipping 16 matching lines...) Expand all Loading... |
44 void PackExtensionJob::Run() { | 46 void PackExtensionJob::Run() { |
45 crx_file_out_ = FilePath(root_directory_.value() + | 47 crx_file_out_ = FilePath(root_directory_.value() + |
46 chrome::kExtensionFileExtension); | 48 chrome::kExtensionFileExtension); |
47 | 49 |
48 if (key_file_.empty()) | 50 if (key_file_.empty()) |
49 key_file_out_ = FilePath(root_directory_.value() + | 51 key_file_out_ = FilePath(root_directory_.value() + |
50 chrome::kExtensionKeyFileExtension); | 52 chrome::kExtensionKeyFileExtension); |
51 | 53 |
52 // TODO(aa): Need to internationalize the errors that ExtensionCreator | 54 // TODO(aa): Need to internationalize the errors that ExtensionCreator |
53 // returns. See bug 20734. | 55 // returns. See bug 20734. |
54 extensions::ExtensionCreator creator; | 56 ExtensionCreator creator; |
55 if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_, | 57 if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_, |
56 run_flags_)) { | 58 run_flags_)) { |
57 if (asynchronous_) { | 59 if (asynchronous_) { |
58 BrowserThread::PostTask( | 60 BrowserThread::PostTask( |
59 client_thread_id_, FROM_HERE, | 61 client_thread_id_, FROM_HERE, |
60 base::Bind(&PackExtensionJob::ReportSuccessOnClientThread, this)); | 62 base::Bind(&PackExtensionJob::ReportSuccessOnClientThread, this)); |
61 } else { | 63 } else { |
62 ReportSuccessOnClientThread(); | 64 ReportSuccessOnClientThread(); |
63 } | 65 } |
64 } else { | 66 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
75 } | 77 } |
76 } | 78 } |
77 | 79 |
78 void PackExtensionJob::ReportSuccessOnClientThread() { | 80 void PackExtensionJob::ReportSuccessOnClientThread() { |
79 if (client_) | 81 if (client_) |
80 client_->OnPackSuccess(crx_file_out_, key_file_out_); | 82 client_->OnPackSuccess(crx_file_out_, key_file_out_); |
81 } | 83 } |
82 | 84 |
83 void PackExtensionJob::ReportFailureOnClientThread( | 85 void PackExtensionJob::ReportFailureOnClientThread( |
84 const std::string& error, | 86 const std::string& error, |
85 extensions::ExtensionCreator::ErrorType error_type) { | 87 ExtensionCreator::ErrorType error_type) { |
86 if (client_) | 88 if (client_) |
87 client_->OnPackFailure(error, error_type); | 89 client_->OnPackFailure(error, error_type); |
88 } | 90 } |
89 | 91 |
90 // static | 92 // static |
91 string16 PackExtensionJob::StandardSuccessMessage(const FilePath& crx_file, | 93 string16 PackExtensionJob::StandardSuccessMessage(const FilePath& crx_file, |
92 const FilePath& key_file) { | 94 const FilePath& key_file) { |
93 string16 crx_file_string = crx_file.LossyDisplayName(); | 95 string16 crx_file_string = crx_file.LossyDisplayName(); |
94 string16 key_file_string = key_file.LossyDisplayName(); | 96 string16 key_file_string = key_file.LossyDisplayName(); |
95 if (key_file_string.empty()) { | 97 if (key_file_string.empty()) { |
96 return l10n_util::GetStringFUTF16( | 98 return l10n_util::GetStringFUTF16( |
97 IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_UPDATE, | 99 IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_UPDATE, |
98 crx_file_string); | 100 crx_file_string); |
99 } else { | 101 } else { |
100 return l10n_util::GetStringFUTF16( | 102 return l10n_util::GetStringFUTF16( |
101 IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_NEW, | 103 IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_NEW, |
102 crx_file_string, | 104 crx_file_string, |
103 key_file_string); | 105 key_file_string); |
104 } | 106 } |
105 } | 107 } |
| 108 |
| 109 } // namespace extensions |
OLD | NEW |