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