Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(630)

Side by Side Diff: chrome/browser/extensions/extensions_startup.cc

Issue 5703004: Fix extension packer command-line code for Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix some lint errors. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/extensions_service.h" 10 #include "chrome/browser/extensions/extensions_service.h"
11 #include "chrome/browser/extensions/pack_extension_job.h"
12 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
14 13
15 #if defined(OS_WIN) 14 #if defined(OS_WIN)
16 #include "app/win_util.h" 15 #include "app/win_util.h"
17 #endif 16 #endif
18 17
19 namespace extensions_startup { 18 void ExtensionsStartupUtil::OnPackSuccess(
20
21 class PackExtensionLogger : public PackExtensionJob::Client {
22 public:
23 PackExtensionLogger() : process_startup_(false) {}
24 virtual void OnPackSuccess(const FilePath& crx_path,
25 const FilePath& output_private_key_path);
26 virtual void OnPackFailure(const std::string& error_message);
27
28 private:
29 // We need to track if this extension packing job was created on process
30 // startup or not so we know if we should Quit() the message loop after
31 // packaging the extension.
32 bool process_startup_;
33 void ShowPackExtensionMessage(const std::wstring& caption,
34 const std::wstring& message);
35
36 DISALLOW_COPY_AND_ASSIGN(PackExtensionLogger);
37 };
38
39 void PackExtensionLogger::OnPackSuccess(
40 const FilePath& crx_path, 19 const FilePath& crx_path,
41 const FilePath& output_private_key_path) { 20 const FilePath& output_private_key_path) {
42 ShowPackExtensionMessage(L"Extension Packaging Success", 21 ShowPackExtensionMessage(L"Extension Packaging Success",
43 PackExtensionJob::StandardSuccessMessage( 22 PackExtensionJob::StandardSuccessMessage(
44 crx_path, output_private_key_path)); 23 crx_path, output_private_key_path));
45 } 24 }
46 25
47 void PackExtensionLogger::OnPackFailure(const std::string& error_message) { 26 void ExtensionsStartupUtil::OnPackFailure(const std::string& error_message) {
48 ShowPackExtensionMessage(L"Extension Packaging Error", 27 ShowPackExtensionMessage(L"Extension Packaging Error",
49 UTF8ToWide(error_message)); 28 UTF8ToWide(error_message));
50 } 29 }
51 30
52 void PackExtensionLogger::ShowPackExtensionMessage( 31 void ExtensionsStartupUtil::ShowPackExtensionMessage(
53 const std::wstring& caption, 32 const std::wstring& caption,
54 const std::wstring& message) { 33 const std::wstring& message) {
55 #if defined(OS_WIN) 34 #if defined(OS_WIN)
56 win_util::MessageBox(NULL, message, caption, MB_OK | MB_SETFOREGROUND); 35 win_util::MessageBox(NULL, message, caption, MB_OK | MB_SETFOREGROUND);
57 #else 36 #else
58 // Just send caption & text to stdout on mac & linux. 37 // Just send caption & text to stdout on mac & linux.
59 std::string out_text = WideToASCII(caption); 38 std::string out_text = WideToASCII(caption);
60 out_text.append("\n\n"); 39 out_text.append("\n\n");
61 out_text.append(WideToASCII(message)); 40 out_text.append(WideToASCII(message));
62 out_text.append("\n"); 41 out_text.append("\n");
63 base::StringPrintf("%s", out_text.c_str()); 42 base::StringPrintf("%s", out_text.c_str());
64 #endif 43 #endif
65
66 // We got the notification and processed it; we don't expect any further tasks
67 // to be posted to the current thread, so we should stop blocking and exit.
68 // This call to |Quit()| matches the call to |Run()| in
69 // |ProcessCmdLineImpl()|.
70 MessageLoop::current()->Quit();
71 } 44 }
72 45
73 bool HandlePackExtension(const CommandLine& cmd_line) { 46 bool ExtensionsStartupUtil::PackExtension(const CommandLine& cmd_line) {
74 if (cmd_line.HasSwitch(switches::kPackExtension)) { 47 if (!cmd_line.HasSwitch(switches::kPackExtension))
75 // Input Paths. 48 return false;
76 FilePath src_dir = cmd_line.GetSwitchValuePath(
77 switches::kPackExtension);
78 FilePath private_key_path;
79 if (cmd_line.HasSwitch(switches::kPackExtensionKey)) {
80 private_key_path = cmd_line.GetSwitchValuePath(
81 switches::kPackExtensionKey);
82 }
83 49
84 // Launch a job to perform the packing on the file thread. 50 // Input Paths.
85 PackExtensionLogger pack_client; 51 FilePath src_dir = cmd_line.GetSwitchValuePath(switches::kPackExtension);
86 scoped_refptr<PackExtensionJob> pack_job( 52 FilePath private_key_path;
87 new PackExtensionJob(&pack_client, src_dir, private_key_path)); 53 if (cmd_line.HasSwitch(switches::kPackExtensionKey)) {
88 pack_job->Start(); 54 private_key_path = cmd_line.GetSwitchValuePath(switches::kPackExtensionKey);
55 }
89 56
90 // The job will post a notification task to the current thread's message 57 // Launch a job to perform the packing on the file thread.
91 // loop when it is finished. We manually run the loop here so that we 58 pack_job_ = new PackExtensionJob(this, src_dir, private_key_path);
92 // block and catch the notification. Otherwise, the process would exit; 59 pack_job_->set_asynchronous(false);
93 // in particular, this would mean that |pack_client| would be destroyed 60 pack_job_->Start();
94 // and we wouldn't be able to report success or failure back to the user.
95 // This call to |Run()| is matched by a call to |Quit()| in the
96 // |PackExtensionLogger|'s notification handling code.
97 MessageLoop::current()->Run();
98 61
62 return true;
Mark Mentovai 2010/12/13 20:44:46 Allays true? How ’bout false if someone called th
63 }
64
65 bool ExtensionsStartupUtil::UninstallExtension(const CommandLine& cmd_line,
66 Profile* profile) {
67 DCHECK(profile);
68
69 if (!cmd_line.HasSwitch(switches::kUninstallExtension))
70 return false;
71
72 ExtensionsService* extensions_service = profile->GetExtensionsService();
73 if (!extensions_service)
74 return false;
75
76 std::string extension_id = cmd_line.GetSwitchValueASCII(
77 switches::kUninstallExtension);
78 if (ExtensionsService::UninstallExtensionHelper(extensions_service,
79 extension_id)) {
99 return true; 80 return true;
100 } 81 }
101 82
102 return false; 83 return false;
103 } 84 }
104 85
105 bool HandleUninstallExtension(const CommandLine& cmd_line, Profile* profile) { 86 ExtensionsStartupUtil::~ExtensionsStartupUtil() {
106 DCHECK(profile); 87 if (pack_job_.get())
107 88 pack_job_->ClearClient();
108 if (cmd_line.HasSwitch(switches::kUninstallExtension)) {
109 ExtensionsService* extensions_service = profile->GetExtensionsService();
110 if (extensions_service) {
111 std::string extension_id = cmd_line.GetSwitchValueASCII(
112 switches::kUninstallExtension);
113 if (ExtensionsService::UninstallExtensionHelper(extensions_service,
114 extension_id)) {
115 return true;
116 }
117 }
118 }
119
120 return false;
121 } 89 }
122
123 } // namespace extensions_startup
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698