OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/runtime/runtime_api.h" | 5 #include "extensions/browser/api/runtime/runtime_api.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 base::Bind(&RuntimeRequestUpdateCheckFunction::CheckComplete, | 453 base::Bind(&RuntimeRequestUpdateCheckFunction::CheckComplete, |
454 this))) { | 454 this))) { |
455 return RespondNow(Error(kUpdatesDisabledError)); | 455 return RespondNow(Error(kUpdatesDisabledError)); |
456 } | 456 } |
457 return RespondLater(); | 457 return RespondLater(); |
458 } | 458 } |
459 | 459 |
460 void RuntimeRequestUpdateCheckFunction::CheckComplete( | 460 void RuntimeRequestUpdateCheckFunction::CheckComplete( |
461 const RuntimeAPIDelegate::UpdateCheckResult& result) { | 461 const RuntimeAPIDelegate::UpdateCheckResult& result) { |
462 if (result.success) { | 462 if (result.success) { |
463 base::ListValue* results = new base::ListValue; | |
464 results->AppendString(result.response); | |
465 base::DictionaryValue* details = new base::DictionaryValue; | 463 base::DictionaryValue* details = new base::DictionaryValue; |
466 results->Append(details); | |
467 details->SetString("version", result.version); | 464 details->SetString("version", result.version); |
468 Respond(MultipleArguments(results)); | 465 Respond(TwoArguments(new base::StringValue(result.response), details)); |
469 } else { | 466 } else { |
470 Respond(SingleArgument(new base::StringValue(result.response))); | 467 // HMM(kalman): Why does !success not imply Error()? |
| 468 Respond(OneArgument(new base::StringValue(result.response))); |
471 } | 469 } |
472 } | 470 } |
473 | 471 |
474 ExtensionFunction::ResponseAction RuntimeRestartFunction::Run() { | 472 ExtensionFunction::ResponseAction RuntimeRestartFunction::Run() { |
475 std::string message; | 473 std::string message; |
476 bool result = | 474 bool result = |
477 RuntimeAPI::GetFactoryInstance()->Get(browser_context())->RestartDevice( | 475 RuntimeAPI::GetFactoryInstance()->Get(browser_context())->RestartDevice( |
478 &message); | 476 &message); |
479 if (!result) { | 477 if (!result) { |
480 return RespondNow(Error(message)); | 478 return RespondNow(Error(message)); |
481 } | 479 } |
482 return RespondNow(NoArguments()); | 480 return RespondNow(NoArguments()); |
483 } | 481 } |
484 | 482 |
485 ExtensionFunction::ResponseAction RuntimeGetPlatformInfoFunction::Run() { | 483 ExtensionFunction::ResponseAction RuntimeGetPlatformInfoFunction::Run() { |
486 runtime::PlatformInfo info; | 484 runtime::PlatformInfo info; |
487 if (!RuntimeAPI::GetFactoryInstance() | 485 if (!RuntimeAPI::GetFactoryInstance() |
488 ->Get(browser_context()) | 486 ->Get(browser_context()) |
489 ->GetPlatformInfo(&info)) { | 487 ->GetPlatformInfo(&info)) { |
490 return RespondNow(Error(kPlatformInfoUnavailable)); | 488 return RespondNow(Error(kPlatformInfoUnavailable)); |
491 } | 489 } |
492 return RespondNow(MultipleArguments( | 490 return RespondNow( |
493 runtime::GetPlatformInfo::Results::Create(info).release())); | 491 ArgumentList(runtime::GetPlatformInfo::Results::Create(info))); |
494 } | 492 } |
495 | 493 |
496 ExtensionFunction::ResponseAction | 494 ExtensionFunction::ResponseAction |
497 RuntimeGetPackageDirectoryEntryFunction::Run() { | 495 RuntimeGetPackageDirectoryEntryFunction::Run() { |
498 fileapi::IsolatedContext* isolated_context = | 496 fileapi::IsolatedContext* isolated_context = |
499 fileapi::IsolatedContext::GetInstance(); | 497 fileapi::IsolatedContext::GetInstance(); |
500 DCHECK(isolated_context); | 498 DCHECK(isolated_context); |
501 | 499 |
502 std::string relative_path = kPackageDirectoryPath; | 500 std::string relative_path = kPackageDirectoryPath; |
503 base::FilePath path = extension_->path(); | 501 base::FilePath path = extension_->path(); |
504 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( | 502 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( |
505 fileapi::kFileSystemTypeNativeLocal, path, &relative_path); | 503 fileapi::kFileSystemTypeNativeLocal, path, &relative_path); |
506 | 504 |
507 int renderer_id = render_view_host_->GetProcess()->GetID(); | 505 int renderer_id = render_view_host_->GetProcess()->GetID(); |
508 content::ChildProcessSecurityPolicy* policy = | 506 content::ChildProcessSecurityPolicy* policy = |
509 content::ChildProcessSecurityPolicy::GetInstance(); | 507 content::ChildProcessSecurityPolicy::GetInstance(); |
510 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 508 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
511 base::DictionaryValue* dict = new base::DictionaryValue(); | 509 base::DictionaryValue* dict = new base::DictionaryValue(); |
512 dict->SetString("fileSystemId", filesystem_id); | 510 dict->SetString("fileSystemId", filesystem_id); |
513 dict->SetString("baseName", relative_path); | 511 dict->SetString("baseName", relative_path); |
514 return RespondNow(SingleArgument(dict)); | 512 return RespondNow(OneArgument(dict)); |
515 } | 513 } |
516 | 514 |
517 } // namespace extensions | 515 } // namespace extensions |
OLD | NEW |