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