summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/browser_main.cc12
-rw-r--r--chrome/browser/extensions/extensions_startup.cc105
-rw-r--r--chrome/browser/extensions/extensions_startup.h39
-rw-r--r--chrome/browser/extensions/pack_extension_job.cc40
-rw-r--r--chrome/browser/extensions/pack_extension_job.h9
-rw-r--r--chrome/browser/process_singleton_win.cc4
-rw-r--r--chrome/common/result_codes.h1
7 files changed, 109 insertions, 101 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 23d7ad6..103e5be 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -1277,8 +1277,12 @@ int BrowserMain(const MainFunctionParams& parameters) {
// If the command line specifies --pack-extension, attempt the pack extension
// startup action and exit.
if (parsed_command_line.HasSwitch(switches::kPackExtension)) {
- extensions_startup::HandlePackExtension(parsed_command_line);
- return ResultCodes::NORMAL_EXIT;
+ ExtensionsStartupUtil extension_startup_util;
+ if (extension_startup_util.PackExtension(parsed_command_line)) {
+ return ResultCodes::NORMAL_EXIT;
+ } else {
+ return ResultCodes::PACK_EXTENSION_ERROR;
+ }
}
#if !defined(OS_MACOSX)
@@ -1573,8 +1577,8 @@ int BrowserMain(const MainFunctionParams& parameters) {
// specifies --uninstall-extension, attempt the uninstall extension startup
// action.
if (parsed_command_line.HasSwitch(switches::kUninstallExtension)) {
- if (extensions_startup::HandleUninstallExtension(parsed_command_line,
- profile)) {
+ ExtensionsStartupUtil ext_startup_util;
+ if (ext_startup_util.UninstallExtension(parsed_command_line, profile)) {
return ResultCodes::NORMAL_EXIT;
} else {
return ResultCodes::UNINSTALL_EXTENSION_ERROR;
diff --git a/chrome/browser/extensions/extensions_startup.cc b/chrome/browser/extensions/extensions_startup.cc
index 1f6ce6d..37a3464 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();
+}
diff --git a/chrome/browser/extensions/extensions_startup.h b/chrome/browser/extensions/extensions_startup.h
index 85622de..2dee7d3 100644
--- a/chrome/browser/extensions/extensions_startup.h
+++ b/chrome/browser/extensions/extensions_startup.h
@@ -6,19 +6,38 @@
#define CHROME_BROWSER_EXTENSIONS_EXTENSIONS_STARTUP_H_
#pragma once
+#include "base/scoped_ptr.h"
+#include "chrome/browser/extensions/pack_extension_job.h"
+
class CommandLine;
class Profile;
// Initialization helpers for various Extension startup actions.
-namespace extensions_startup {
-// Handle --pack-extension flag from the |cmd_line| by packing the specified
-// extension. Returns false if the pack job could not be started.
-bool HandlePackExtension(const CommandLine& cmd_line);
-
-// Handle --uninstall-extension flag from the |cmd_line| by uninstalling the
-// specified extension from |profile|. Returns false if the uninstall job
-// could not be started.
-bool HandleUninstallExtension(const CommandLine& cmd_line, Profile* profile);
-} // namespace extensions_startup
+class ExtensionsStartupUtil : public PackExtensionJob::Client {
+ public:
+ ExtensionsStartupUtil();
+ virtual ~ExtensionsStartupUtil();
+
+ virtual void OnPackSuccess(const FilePath& crx_path,
+ const FilePath& output_private_key_path);
+ virtual void OnPackFailure(const std::string& error_message);
+
+ // Handle --pack-extension flag from the |cmd_line| by packing the specified
+ // extension. Returns false if the pack job failed.
+ bool PackExtension(const CommandLine& cmd_line);
+
+ // Handle --uninstall-extension flag from the |cmd_line| by uninstalling the
+ // specified extension from |profile|. Returns false if the uninstall job
+ // could not be started.
+ bool UninstallExtension(const CommandLine& cmd_line, Profile* profile);
+
+ private:
+ void ShowPackExtensionMessage(const std::wstring& caption,
+ const std::wstring& message);
+ scoped_refptr<PackExtensionJob> pack_job_;
+ bool pack_job_succeeded_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtensionsStartupUtil);
+};
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSIONS_STARTUP_H_
diff --git a/chrome/browser/extensions/pack_extension_job.cc b/chrome/browser/extensions/pack_extension_job.cc
index 5f64025..327d7c4 100644
--- a/chrome/browser/extensions/pack_extension_job.cc
+++ b/chrome/browser/extensions/pack_extension_job.cc
@@ -15,15 +15,19 @@
PackExtensionJob::PackExtensionJob(Client* client,
const FilePath& root_directory,
const FilePath& key_file)
- : client_(client), key_file_(key_file) {
+ : client_(client), key_file_(key_file), asynchronous_(true) {
root_directory_ = root_directory.StripTrailingSeparators();
CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_));
}
void PackExtensionJob::Start() {
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(this, &PackExtensionJob::RunOnFileThread));
+ if (asynchronous_) {
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ NewRunnableMethod(this, &PackExtensionJob::Run));
+ } else {
+ Run();
+ }
}
void PackExtensionJob::ClearClient() {
@@ -32,7 +36,7 @@ void PackExtensionJob::ClearClient() {
PackExtensionJob::~PackExtensionJob() {}
-void PackExtensionJob::RunOnFileThread() {
+void PackExtensionJob::Run() {
crx_file_out_ = FilePath(root_directory_.value() +
chrome::kExtensionFileExtension);
@@ -44,16 +48,24 @@ void PackExtensionJob::RunOnFileThread() {
// returns. See bug 20734.
ExtensionCreator creator;
if (creator.Run(root_directory_, crx_file_out_, key_file_, key_file_out_)) {
- BrowserThread::PostTask(
- client_thread_id_, FROM_HERE,
- NewRunnableMethod(this,
- &PackExtensionJob::ReportSuccessOnClientThread));
+ if (asynchronous_) {
+ BrowserThread::PostTask(
+ client_thread_id_, FROM_HERE,
+ NewRunnableMethod(this,
+ &PackExtensionJob::ReportSuccessOnClientThread));
+ } else {
+ ReportSuccessOnClientThread();
+ }
} else {
- BrowserThread::PostTask(
- client_thread_id_, FROM_HERE,
- NewRunnableMethod(
- this, &PackExtensionJob::ReportFailureOnClientThread,
- creator.error_message()));
+ if (asynchronous_) {
+ BrowserThread::PostTask(
+ client_thread_id_, FROM_HERE,
+ NewRunnableMethod(
+ this, &PackExtensionJob::ReportFailureOnClientThread,
+ creator.error_message()));
+ } else {
+ ReportFailureOnClientThread(creator.error_message());
+ }
}
}
diff --git a/chrome/browser/extensions/pack_extension_job.h b/chrome/browser/extensions/pack_extension_job.h
index ecd3d68..e26687a 100644
--- a/chrome/browser/extensions/pack_extension_job.h
+++ b/chrome/browser/extensions/pack_extension_job.h
@@ -33,8 +33,7 @@ class PackExtensionJob : public base::RefCountedThreadSafe<PackExtensionJob> {
const FilePath& root_directory,
const FilePath& key_file);
- // Starts the packing thread job. See http://crbug.com/27944 for more details
- // on why this function is needed.
+ // Starts the packing job.
void Start();
// The client should call this when it is destroyed to prevent
@@ -45,12 +44,15 @@ class PackExtensionJob : public base::RefCountedThreadSafe<PackExtensionJob> {
static std::wstring StandardSuccessMessage(const FilePath& crx_file,
const FilePath& key_file);
+ void set_asynchronous(bool async) { asynchronous_ = async; }
+
private:
friend class base::RefCountedThreadSafe<PackExtensionJob>;
virtual ~PackExtensionJob();
- void RunOnFileThread();
+ // If |asynchronous_| is false, this is run on whichever thread calls it.
+ void Run();
void ReportSuccessOnClientThread();
void ReportFailureOnClientThread(const std::string& error);
@@ -60,6 +62,7 @@ class PackExtensionJob : public base::RefCountedThreadSafe<PackExtensionJob> {
FilePath key_file_;
FilePath crx_file_out_;
FilePath key_file_out_;
+ bool asynchronous_;
DISALLOW_COPY_AND_ASSIGN(PackExtensionJob);
};
diff --git a/chrome/browser/process_singleton_win.cc b/chrome/browser/process_singleton_win.cc
index 6ace2f5..4925d24 100644
--- a/chrome/browser/process_singleton_win.cc
+++ b/chrome/browser/process_singleton_win.cc
@@ -285,8 +285,8 @@ LRESULT ProcessSingleton::OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds) {
// in the process that is running with the target profile, otherwise the
// uninstall will fail to unload and remove all components.
if (parsed_command_line.HasSwitch(switches::kUninstallExtension)) {
- extensions_startup::HandleUninstallExtension(parsed_command_line,
- profile);
+ ExtensionsStartupUtil ext_startup_util;
+ ext_startup_util.UninstallExtension(parsed_command_line, profile);
return TRUE;
}
diff --git a/chrome/common/result_codes.h b/chrome/common/result_codes.h
index 6625cb0..38fe54d 100644
--- a/chrome/common/result_codes.h
+++ b/chrome/common/result_codes.h
@@ -58,6 +58,7 @@ class ResultCodes {
PROFILE_IN_USE, // The profile was in use on another host.
UNINSTALL_EXTENSION_ERROR, // Failed to silently uninstall an extension.
+ PACK_EXTENSION_ERROR, // Failed to pack an extension via the cmd line.
EXIT_LAST_CODE // Last return code (keep it last).
};