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/extensions_startup.h" | 5 #include "chrome/browser/extensions/startup_helper.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/simple_message_box.h" | 12 #include "chrome/browser/ui/simple_message_box.h" |
13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
14 | 14 |
15 ExtensionsStartupUtil::ExtensionsStartupUtil() : pack_job_succeeded_(false) {} | 15 namespace extensions { |
16 | 16 |
17 void ExtensionsStartupUtil::OnPackSuccess( | 17 StartupHelper::StartupHelper() : pack_job_succeeded_(false) {} |
18 const FilePath& crx_path, | 18 |
19 const FilePath& output_private_key_path) { | 19 void StartupHelper::OnPackSuccess(const FilePath& crx_path, |
| 20 const FilePath& output_private_key_path) { |
20 pack_job_succeeded_ = true; | 21 pack_job_succeeded_ = true; |
21 chrome::ShowMessageBox(NULL, ASCIIToUTF16("Extension Packaging Success"), | 22 chrome::ShowMessageBox(NULL, ASCIIToUTF16("Extension Packaging Success"), |
22 PackExtensionJob::StandardSuccessMessage(crx_path, | 23 PackExtensionJob::StandardSuccessMessage(crx_path, |
23 output_private_key_path), | 24 output_private_key_path), |
24 chrome::MESSAGE_BOX_TYPE_INFORMATION); | 25 chrome::MESSAGE_BOX_TYPE_INFORMATION); |
25 } | 26 } |
26 | 27 |
27 void ExtensionsStartupUtil::OnPackFailure( | 28 void StartupHelper::OnPackFailure(const std::string& error_message, |
28 const std::string& error_message, | 29 ExtensionCreator::ErrorType type) { |
29 extensions::ExtensionCreator::ErrorType type) { | |
30 chrome::ShowMessageBox(NULL, ASCIIToUTF16("Extension Packaging Error"), | 30 chrome::ShowMessageBox(NULL, ASCIIToUTF16("Extension Packaging Error"), |
31 UTF8ToUTF16(error_message), chrome::MESSAGE_BOX_TYPE_WARNING); | 31 UTF8ToUTF16(error_message), chrome::MESSAGE_BOX_TYPE_WARNING); |
32 } | 32 } |
33 | 33 |
34 bool ExtensionsStartupUtil::PackExtension(const CommandLine& cmd_line) { | 34 bool StartupHelper::PackExtension(const CommandLine& cmd_line) { |
35 if (!cmd_line.HasSwitch(switches::kPackExtension)) | 35 if (!cmd_line.HasSwitch(switches::kPackExtension)) |
36 return false; | 36 return false; |
37 | 37 |
38 // Input Paths. | 38 // Input Paths. |
39 FilePath src_dir = cmd_line.GetSwitchValuePath(switches::kPackExtension); | 39 FilePath src_dir = cmd_line.GetSwitchValuePath(switches::kPackExtension); |
40 FilePath private_key_path; | 40 FilePath private_key_path; |
41 if (cmd_line.HasSwitch(switches::kPackExtensionKey)) { | 41 if (cmd_line.HasSwitch(switches::kPackExtensionKey)) { |
42 private_key_path = cmd_line.GetSwitchValuePath(switches::kPackExtensionKey); | 42 private_key_path = cmd_line.GetSwitchValuePath(switches::kPackExtensionKey); |
43 } | 43 } |
44 | 44 |
45 // Launch a job to perform the packing on the file thread. Ignore warnings | 45 // Launch a job to perform the packing on the file thread. Ignore warnings |
46 // from the packing process. (e.g. Overwrite any existing crx file.) | 46 // from the packing process. (e.g. Overwrite any existing crx file.) |
47 pack_job_ = new PackExtensionJob(this, src_dir, private_key_path, | 47 pack_job_ = new PackExtensionJob(this, src_dir, private_key_path, |
48 extensions::ExtensionCreator::kOverwriteCRX); | 48 ExtensionCreator::kOverwriteCRX); |
49 pack_job_->set_asynchronous(false); | 49 pack_job_->set_asynchronous(false); |
50 pack_job_->Start(); | 50 pack_job_->Start(); |
51 | 51 |
52 return pack_job_succeeded_; | 52 return pack_job_succeeded_; |
53 } | 53 } |
54 | 54 |
55 bool ExtensionsStartupUtil::UninstallExtension(const CommandLine& cmd_line, | 55 bool StartupHelper::UninstallExtension(const CommandLine& cmd_line, |
56 Profile* profile) { | 56 Profile* profile) { |
57 DCHECK(profile); | 57 DCHECK(profile); |
58 | 58 |
59 if (!cmd_line.HasSwitch(switches::kUninstallExtension)) | 59 if (!cmd_line.HasSwitch(switches::kUninstallExtension)) |
60 return false; | 60 return false; |
61 | 61 |
62 ExtensionService* extension_service = profile->GetExtensionService(); | 62 ExtensionService* extension_service = profile->GetExtensionService(); |
63 if (!extension_service) | 63 if (!extension_service) |
64 return false; | 64 return false; |
65 | 65 |
66 std::string extension_id = cmd_line.GetSwitchValueASCII( | 66 std::string extension_id = cmd_line.GetSwitchValueASCII( |
67 switches::kUninstallExtension); | 67 switches::kUninstallExtension); |
68 return ExtensionService::UninstallExtensionHelper(extension_service, | 68 return ExtensionService::UninstallExtensionHelper(extension_service, |
69 extension_id); | 69 extension_id); |
70 } | 70 } |
71 | 71 |
72 ExtensionsStartupUtil::~ExtensionsStartupUtil() { | 72 StartupHelper::~StartupHelper() { |
73 if (pack_job_.get()) | 73 if (pack_job_.get()) |
74 pack_job_->ClearClient(); | 74 pack_job_->ClearClient(); |
75 } | 75 } |
| 76 |
| 77 } // namespace extensions |
OLD | NEW |