Index: chrome/browser/extensions/extensions_startup.cc |
diff --git a/chrome/browser/extensions/extensions_startup.cc b/chrome/browser/extensions/extensions_startup.cc |
index 1f6ce6d41ec5007657c8281fe29ea739b90779d5..37a3464bce58fd84470e9a2535fbea9f69276b62 100644 |
--- a/chrome/browser/extensions/extensions_startup.cc |
+++ b/chrome/browser/extensions/extensions_startup.cc |
@@ -8,7 +8,6 @@ |
#include "base/stringprintf.h" |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/extensions/extensions_service.h" |
-#include "chrome/browser/extensions/pack_extension_job.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/common/chrome_switches.h" |
@@ -16,40 +15,23 @@ |
#include "app/win_util.h" |
#endif |
-namespace extensions_startup { |
+ExtensionsStartupUtil::ExtensionsStartupUtil() : pack_job_succeeded_(false) {} |
-class PackExtensionLogger : public PackExtensionJob::Client { |
- public: |
- PackExtensionLogger() : process_startup_(false) {} |
- virtual void OnPackSuccess(const FilePath& crx_path, |
- const FilePath& output_private_key_path); |
- virtual void OnPackFailure(const std::string& error_message); |
- |
- private: |
- // We need to track if this extension packing job was created on process |
- // startup or not so we know if we should Quit() the message loop after |
- // packaging the extension. |
- bool process_startup_; |
- void ShowPackExtensionMessage(const std::wstring& caption, |
- const std::wstring& message); |
- |
- DISALLOW_COPY_AND_ASSIGN(PackExtensionLogger); |
-}; |
- |
-void PackExtensionLogger::OnPackSuccess( |
+void ExtensionsStartupUtil::OnPackSuccess( |
const FilePath& crx_path, |
const FilePath& output_private_key_path) { |
+ pack_job_succeeded_ = true; |
ShowPackExtensionMessage(L"Extension Packaging Success", |
PackExtensionJob::StandardSuccessMessage( |
crx_path, output_private_key_path)); |
} |
-void PackExtensionLogger::OnPackFailure(const std::string& error_message) { |
+void ExtensionsStartupUtil::OnPackFailure(const std::string& error_message) { |
ShowPackExtensionMessage(L"Extension Packaging Error", |
UTF8ToWide(error_message)); |
} |
-void PackExtensionLogger::ShowPackExtensionMessage( |
+void ExtensionsStartupUtil::ShowPackExtensionMessage( |
const std::wstring& caption, |
const std::wstring& message) { |
#if defined(OS_WIN) |
@@ -62,62 +44,49 @@ void PackExtensionLogger::ShowPackExtensionMessage( |
out_text.append("\n"); |
base::StringPrintf("%s", out_text.c_str()); |
#endif |
- |
- // We got the notification and processed it; we don't expect any further tasks |
- // to be posted to the current thread, so we should stop blocking and exit. |
- // This call to |Quit()| matches the call to |Run()| in |
- // |ProcessCmdLineImpl()|. |
- MessageLoop::current()->Quit(); |
} |
-bool HandlePackExtension(const CommandLine& cmd_line) { |
- if (cmd_line.HasSwitch(switches::kPackExtension)) { |
- // Input Paths. |
- FilePath src_dir = cmd_line.GetSwitchValuePath( |
- switches::kPackExtension); |
- FilePath private_key_path; |
- if (cmd_line.HasSwitch(switches::kPackExtensionKey)) { |
- private_key_path = cmd_line.GetSwitchValuePath( |
- switches::kPackExtensionKey); |
- } |
- |
- // Launch a job to perform the packing on the file thread. |
- PackExtensionLogger pack_client; |
- scoped_refptr<PackExtensionJob> pack_job( |
- new PackExtensionJob(&pack_client, src_dir, private_key_path)); |
- pack_job->Start(); |
- |
- // The job will post a notification task to the current thread's message |
- // loop when it is finished. We manually run the loop here so that we |
- // block and catch the notification. Otherwise, the process would exit; |
- // in particular, this would mean that |pack_client| would be destroyed |
- // and we wouldn't be able to report success or failure back to the user. |
- // This call to |Run()| is matched by a call to |Quit()| in the |
- // |PackExtensionLogger|'s notification handling code. |
- MessageLoop::current()->Run(); |
+bool ExtensionsStartupUtil::PackExtension(const CommandLine& cmd_line) { |
+ if (!cmd_line.HasSwitch(switches::kPackExtension)) |
+ return false; |
- return true; |
+ // Input Paths. |
+ FilePath src_dir = cmd_line.GetSwitchValuePath(switches::kPackExtension); |
+ FilePath private_key_path; |
+ if (cmd_line.HasSwitch(switches::kPackExtensionKey)) { |
+ private_key_path = cmd_line.GetSwitchValuePath(switches::kPackExtensionKey); |
} |
- return false; |
+ // Launch a job to perform the packing on the file thread. |
+ pack_job_ = new PackExtensionJob(this, src_dir, private_key_path); |
+ pack_job_->set_asynchronous(false); |
+ pack_job_->Start(); |
+ |
+ return pack_job_succeeded_; |
} |
-bool HandleUninstallExtension(const CommandLine& cmd_line, Profile* profile) { |
+bool ExtensionsStartupUtil::UninstallExtension(const CommandLine& cmd_line, |
+ Profile* profile) { |
DCHECK(profile); |
- if (cmd_line.HasSwitch(switches::kUninstallExtension)) { |
- ExtensionsService* extensions_service = profile->GetExtensionsService(); |
- if (extensions_service) { |
- std::string extension_id = cmd_line.GetSwitchValueASCII( |
- switches::kUninstallExtension); |
- if (ExtensionsService::UninstallExtensionHelper(extensions_service, |
- extension_id)) { |
- return true; |
- } |
- } |
+ if (!cmd_line.HasSwitch(switches::kUninstallExtension)) |
+ return false; |
+ |
+ ExtensionsService* extensions_service = profile->GetExtensionsService(); |
+ if (!extensions_service) |
+ return false; |
+ |
+ std::string extension_id = cmd_line.GetSwitchValueASCII( |
+ switches::kUninstallExtension); |
+ if (ExtensionsService::UninstallExtensionHelper(extensions_service, |
+ extension_id)) { |
+ return true; |
} |
return false; |
} |
-} // namespace extensions_startup |
+ExtensionsStartupUtil::~ExtensionsStartupUtil() { |
+ if (pack_job_.get()) |
+ pack_job_->ClearClient(); |
+} |