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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 error_= error; | 257 error_= error; |
258 done_callback_.Run(); | 258 done_callback_.Run(); |
259 } | 259 } |
260 | 260 |
261 void DeleteHelperAndRunCallback(AppInstallHelper* helper, | 261 void DeleteHelperAndRunCallback(AppInstallHelper* helper, |
262 base::Callback<void()> callback) { | 262 base::Callback<void()> callback) { |
263 delete helper; | 263 delete helper; |
264 callback.Run(); | 264 callback.Run(); |
265 } | 265 } |
266 | 266 |
267 void DeleteHelper(AppInstallHelper* helper) { | |
268 delete helper; | |
269 } | |
270 | |
267 } // namespace | 271 } // namespace |
268 | 272 |
269 bool StartupHelper::InstallFromWebstore(const CommandLine& cmd_line, | 273 bool StartupHelper::InstallFromWebstore(const CommandLine& cmd_line, |
270 Profile* profile) { | 274 Profile* profile) { |
271 std::string id = cmd_line.GetSwitchValueASCII(switches::kInstallFromWebstore); | 275 std::string id = cmd_line.GetSwitchValueASCII(switches::kInstallFromWebstore); |
272 if (!Extension::IdIsValid(id)) { | 276 if (!Extension::IdIsValid(id)) { |
273 LOG(ERROR) << "Invalid id for " << switches::kInstallFromWebstore | 277 LOG(ERROR) << "Invalid id for " << switches::kInstallFromWebstore |
274 << " : '" << id << "'"; | 278 << " : '" << id << "'"; |
275 return false; | 279 return false; |
276 } | 280 } |
277 | 281 |
278 AppInstallHelper helper; | 282 AppInstallHelper helper; |
279 base::RunLoop run_loop; | 283 base::RunLoop run_loop; |
tapted
2014/07/25 03:49:12
InstallFromWebstore does this, which is blocking -
tapted
2014/07/25 04:39:57
oops I didn't see the "but" in the function commen
| |
280 helper.BeginInstall(profile, id, true, run_loop.QuitClosure()); | 284 helper.BeginInstall(profile, id, true, run_loop.QuitClosure()); |
281 run_loop.Run(); | 285 run_loop.Run(); |
282 | 286 |
283 if (!helper.success()) | 287 if (!helper.success()) |
284 LOG(ERROR) << "InstallFromWebstore failed with error: " << helper.error(); | 288 LOG(ERROR) << "InstallFromWebstore failed with error: " << helper.error(); |
285 return helper.success(); | 289 return helper.success(); |
286 } | 290 } |
287 | 291 |
288 void StartupHelper::LimitedInstallFromWebstore( | 292 void StartupHelper::LimitedInstallFromWebstore( |
289 const CommandLine& cmd_line, | 293 const CommandLine& cmd_line, |
290 Profile* profile, | 294 Profile* profile, |
291 base::Callback<void()> done_callback) { | 295 base::Callback<void()> done_callback) { |
292 std::string id = WebStoreIdFromLimitedInstallCmdLine(cmd_line); | 296 std::string id = WebStoreIdFromLimitedInstallCmdLine(cmd_line); |
293 if (!Extension::IdIsValid(id)) { | 297 if (!Extension::IdIsValid(id)) { |
294 LOG(ERROR) << "Invalid index for " << switches::kLimitedInstallFromWebstore; | 298 LOG(ERROR) << "Invalid index for " << switches::kLimitedInstallFromWebstore; |
295 done_callback.Run(); | 299 done_callback.Run(); |
296 return; | 300 return; |
297 } | 301 } |
298 | 302 |
299 AppInstallHelper* helper = new AppInstallHelper(); | 303 AppInstallHelper* helper = new AppInstallHelper(); |
300 helper->BeginInstall(profile, id, false /*show_prompt*/, | 304 helper->BeginInstall(profile, id, false /*show_prompt*/, |
301 base::Bind(&DeleteHelperAndRunCallback, | 305 base::Bind(&DeleteHelperAndRunCallback, |
302 helper, done_callback)); | 306 helper, done_callback)); |
303 } | 307 } |
304 | 308 |
309 void StartupHelper::InstallChromeApp( | |
310 const CommandLine& cmd_line, | |
311 Profile* profile) { | |
312 std::string id = cmd_line.GetSwitchValueASCII(switches::kInstallChromeApp); | |
313 if (!Extension::IdIsValid(id)) { | |
tapted
2014/07/25 03:49:12
Would be nice to consolidate some of the repeated
| |
314 LOG(ERROR) << "Invalid id for " << switches::kInstallChromeApp | |
315 << " : '" << id << "'"; | |
316 return; | |
317 } | |
318 | |
319 AppInstallHelper* helper = new AppInstallHelper(); | |
320 helper->BeginInstall(profile, id, true /*show_prompt*/, | |
tapted
2014/07/25 03:49:12
Should the prompt that's shown be modal to a brows
| |
321 base::Bind(&DeleteHelper, helper)); | |
322 } | |
323 | |
305 std::string StartupHelper::WebStoreIdFromLimitedInstallCmdLine( | 324 std::string StartupHelper::WebStoreIdFromLimitedInstallCmdLine( |
306 const CommandLine& cmd_line) { | 325 const CommandLine& cmd_line) { |
307 std::string index = cmd_line.GetSwitchValueASCII( | 326 std::string index = cmd_line.GetSwitchValueASCII( |
308 switches::kLimitedInstallFromWebstore); | 327 switches::kLimitedInstallFromWebstore); |
309 std::string id; | 328 std::string id; |
310 if (index == "1") { | 329 if (index == "1") { |
311 id = "nckgahadagoaajjgafhacjanaoiihapd"; | 330 id = "nckgahadagoaajjgafhacjanaoiihapd"; |
312 } else if (index == "2") { | 331 } else if (index == "2") { |
313 id = "ecglahbcnmdpdciemllbhojghbkagdje"; | 332 id = "ecglahbcnmdpdciemllbhojghbkagdje"; |
314 } | 333 } |
315 return id; | 334 return id; |
316 } | 335 } |
317 | 336 |
318 StartupHelper::~StartupHelper() { | 337 StartupHelper::~StartupHelper() { |
319 if (pack_job_.get()) | 338 if (pack_job_.get()) |
320 pack_job_->ClearClient(); | 339 pack_job_->ClearClient(); |
321 } | 340 } |
322 | 341 |
323 } // namespace extensions | 342 } // namespace extensions |
OLD | NEW |