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/startup_helper.h" | 5 #include "chrome/browser/extensions/startup_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 base::UTF16ToUTF8( | 87 base::UTF16ToUTF8( |
88 PackExtensionJob::StandardSuccessMessage(crx_path, | 88 PackExtensionJob::StandardSuccessMessage(crx_path, |
89 output_private_key_path))); | 89 output_private_key_path))); |
90 } | 90 } |
91 | 91 |
92 void StartupHelper::OnPackFailure(const std::string& error_message, | 92 void StartupHelper::OnPackFailure(const std::string& error_message, |
93 ExtensionCreator::ErrorType type) { | 93 ExtensionCreator::ErrorType type) { |
94 PrintPackExtensionMessage(error_message); | 94 PrintPackExtensionMessage(error_message); |
95 } | 95 } |
96 | 96 |
97 bool StartupHelper::PackExtension(const CommandLine& cmd_line) { | 97 bool StartupHelper::PackExtension(const base::CommandLine& cmd_line) { |
98 if (!cmd_line.HasSwitch(switches::kPackExtension)) | 98 if (!cmd_line.HasSwitch(switches::kPackExtension)) |
99 return false; | 99 return false; |
100 | 100 |
101 // Input Paths. | 101 // Input Paths. |
102 base::FilePath src_dir = | 102 base::FilePath src_dir = |
103 cmd_line.GetSwitchValuePath(switches::kPackExtension); | 103 cmd_line.GetSwitchValuePath(switches::kPackExtension); |
104 base::FilePath private_key_path; | 104 base::FilePath private_key_path; |
105 if (cmd_line.HasSwitch(switches::kPackExtensionKey)) { | 105 if (cmd_line.HasSwitch(switches::kPackExtensionKey)) { |
106 private_key_path = cmd_line.GetSwitchValuePath(switches::kPackExtensionKey); | 106 private_key_path = cmd_line.GetSwitchValuePath(switches::kPackExtensionKey); |
107 } | 107 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 198 |
199 // Whether the unpacking was successful. | 199 // Whether the unpacking was successful. |
200 bool success_; | 200 bool success_; |
201 | 201 |
202 // If the unpacking wasn't successful, this contains an error message. | 202 // If the unpacking wasn't successful, this contains an error message. |
203 base::string16 error_; | 203 base::string16 error_; |
204 }; | 204 }; |
205 | 205 |
206 } // namespace | 206 } // namespace |
207 | 207 |
208 bool StartupHelper::ValidateCrx(const CommandLine& cmd_line, | 208 bool StartupHelper::ValidateCrx(const base::CommandLine& cmd_line, |
209 std::string* error) { | 209 std::string* error) { |
210 CHECK(error); | 210 CHECK(error); |
211 base::FilePath path = cmd_line.GetSwitchValuePath(switches::kValidateCrx); | 211 base::FilePath path = cmd_line.GetSwitchValuePath(switches::kValidateCrx); |
212 if (path.empty()) { | 212 if (path.empty()) { |
213 *error = base::StringPrintf("Empty path passed for %s", | 213 *error = base::StringPrintf("Empty path passed for %s", |
214 switches::kValidateCrx); | 214 switches::kValidateCrx); |
215 return false; | 215 return false; |
216 } | 216 } |
217 base::ScopedTempDir temp_dir; | 217 base::ScopedTempDir temp_dir; |
218 | 218 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 void AppInstallHelper::OnAppInstallComplete(bool success, | 297 void AppInstallHelper::OnAppInstallComplete(bool success, |
298 const std::string& error, | 298 const std::string& error, |
299 webstore_install::Result result) { | 299 webstore_install::Result result) { |
300 success_ = success; | 300 success_ = success; |
301 error_= error; | 301 error_= error; |
302 done_callback_.Run(); | 302 done_callback_.Run(); |
303 } | 303 } |
304 | 304 |
305 } // namespace | 305 } // namespace |
306 | 306 |
307 bool StartupHelper::InstallEphemeralApp(const CommandLine& cmd_line, | 307 bool StartupHelper::InstallEphemeralApp(const base::CommandLine& cmd_line, |
308 Profile* profile) { | 308 Profile* profile) { |
309 std::string id = | 309 std::string id = |
310 cmd_line.GetSwitchValueASCII(switches::kInstallEphemeralAppFromWebstore); | 310 cmd_line.GetSwitchValueASCII(switches::kInstallEphemeralAppFromWebstore); |
311 if (!crx_file::id_util::IdIsValid(id)) { | 311 if (!crx_file::id_util::IdIsValid(id)) { |
312 LOG(ERROR) << "Invalid id for " | 312 LOG(ERROR) << "Invalid id for " |
313 << switches::kInstallEphemeralAppFromWebstore << " : '" << id << "'"; | 313 << switches::kInstallEphemeralAppFromWebstore << " : '" << id << "'"; |
314 return false; | 314 return false; |
315 } | 315 } |
316 | 316 |
317 AppInstallHelper helper; | 317 AppInstallHelper helper; |
318 base::RunLoop run_loop; | 318 base::RunLoop run_loop; |
319 helper.BeginInstall(profile, id, true, run_loop.QuitClosure()); | 319 helper.BeginInstall(profile, id, true, run_loop.QuitClosure()); |
320 run_loop.Run(); | 320 run_loop.Run(); |
321 | 321 |
322 if (!helper.success()) | 322 if (!helper.success()) |
323 LOG(ERROR) << "InstallFromWebstore failed with error: " << helper.error(); | 323 LOG(ERROR) << "InstallFromWebstore failed with error: " << helper.error(); |
324 return helper.success(); | 324 return helper.success(); |
325 } | 325 } |
326 | 326 |
327 StartupHelper::~StartupHelper() { | 327 StartupHelper::~StartupHelper() { |
328 if (pack_job_.get()) | 328 if (pack_job_.get()) |
329 pack_job_->ClearClient(); | 329 pack_job_->ClearClient(); |
330 } | 330 } |
331 | 331 |
332 } // namespace extensions | 332 } // namespace extensions |
OLD | NEW |