| 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/extension_function_dispatcher.h" | 5 #include "extensions/browser/extension_function_dispatcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 function->set_include_incognito( | 367 function->set_include_incognito( |
| 368 extension_info_map->IsIncognitoEnabled(extension->id())); | 368 extension_info_map->IsIncognitoEnabled(extension->id())); |
| 369 } | 369 } |
| 370 | 370 |
| 371 if (!CheckPermissions(function.get(), params, callback)) | 371 if (!CheckPermissions(function.get(), params, callback)) |
| 372 return; | 372 return; |
| 373 | 373 |
| 374 if (!extension) { | 374 if (!extension) { |
| 375 // Skip all of the UMA, quota, event page, activity logging stuff if there | 375 // Skip all of the UMA, quota, event page, activity logging stuff if there |
| 376 // isn't an extension, e.g. if the function call was from WebUI. | 376 // isn't an extension, e.g. if the function call was from WebUI. |
| 377 function->Run()->Execute(); | 377 function->RunWithValidation()->Execute(); |
| 378 return; | 378 return; |
| 379 } | 379 } |
| 380 | 380 |
| 381 QuotaService* quota = extension_info_map->GetQuotaService(); | 381 QuotaService* quota = extension_info_map->GetQuotaService(); |
| 382 std::string violation_error = quota->Assess(extension->id(), | 382 std::string violation_error = quota->Assess(extension->id(), |
| 383 function.get(), | 383 function.get(), |
| 384 ¶ms.arguments, | 384 ¶ms.arguments, |
| 385 base::TimeTicks::Now()); | 385 base::TimeTicks::Now()); |
| 386 if (violation_error.empty()) { | 386 if (violation_error.empty()) { |
| 387 std::unique_ptr<base::ListValue> args(params.arguments.DeepCopy()); | 387 std::unique_ptr<base::ListValue> args(params.arguments.DeepCopy()); |
| 388 NotifyApiFunctionCalled(extension->id(), params.name, std::move(args), | 388 NotifyApiFunctionCalled(extension->id(), params.name, std::move(args), |
| 389 static_cast<content::BrowserContext*>(profile_id)); | 389 static_cast<content::BrowserContext*>(profile_id)); |
| 390 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.FunctionCalls", | 390 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.FunctionCalls", |
| 391 function->histogram_value()); | 391 function->histogram_value()); |
| 392 tracked_objects::ScopedProfile scoped_profile( | 392 tracked_objects::ScopedProfile scoped_profile( |
| 393 FROM_HERE_WITH_EXPLICIT_FUNCTION(function->name()), | 393 FROM_HERE_WITH_EXPLICIT_FUNCTION(function->name()), |
| 394 tracked_objects::ScopedProfile::ENABLED); | 394 tracked_objects::ScopedProfile::ENABLED); |
| 395 base::ElapsedTimer timer; | 395 base::ElapsedTimer timer; |
| 396 function->Run()->Execute(); | 396 function->RunWithValidation()->Execute(); |
| 397 // TODO(devlin): Once we have a baseline metric for how long functions take, | 397 // TODO(devlin): Once we have a baseline metric for how long functions take, |
| 398 // we can create a handful of buckets and record the function name so that | 398 // we can create a handful of buckets and record the function name so that |
| 399 // we can find what the fastest/slowest are. | 399 // we can find what the fastest/slowest are. |
| 400 // Note: Many functions execute finish asynchronously, so this time is not | 400 // Note: Many functions execute finish asynchronously, so this time is not |
| 401 // always a representation of total time taken. See also | 401 // always a representation of total time taken. See also |
| 402 // Extensions.Functions.TotalExecutionTime. | 402 // Extensions.Functions.TotalExecutionTime. |
| 403 UMA_HISTOGRAM_TIMES("Extensions.Functions.SynchronousExecutionTime", | 403 UMA_HISTOGRAM_TIMES("Extensions.Functions.SynchronousExecutionTime", |
| 404 timer.Elapsed()); | 404 timer.Elapsed()); |
| 405 } else { | 405 } else { |
| 406 function->OnQuotaExceeded(violation_error); | 406 function->OnQuotaExceeded(violation_error); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 extension, browser_context_)) { | 499 extension, browser_context_)) { |
| 500 function->set_include_incognito(true); | 500 function->set_include_incognito(true); |
| 501 } | 501 } |
| 502 | 502 |
| 503 if (!CheckPermissions(function.get(), params, callback)) | 503 if (!CheckPermissions(function.get(), params, callback)) |
| 504 return; | 504 return; |
| 505 | 505 |
| 506 if (!extension) { | 506 if (!extension) { |
| 507 // Skip all of the UMA, quota, event page, activity logging stuff if there | 507 // Skip all of the UMA, quota, event page, activity logging stuff if there |
| 508 // isn't an extension, e.g. if the function call was from WebUI. | 508 // isn't an extension, e.g. if the function call was from WebUI. |
| 509 function->Run()->Execute(); | 509 function->RunWithValidation()->Execute(); |
| 510 return; | 510 return; |
| 511 } | 511 } |
| 512 | 512 |
| 513 // Fetch the ProcessManager before |this| is possibly invalidated. | 513 // Fetch the ProcessManager before |this| is possibly invalidated. |
| 514 ProcessManager* process_manager = ProcessManager::Get(browser_context_); | 514 ProcessManager* process_manager = ProcessManager::Get(browser_context_); |
| 515 | 515 |
| 516 ExtensionSystem* extension_system = ExtensionSystem::Get(browser_context_); | 516 ExtensionSystem* extension_system = ExtensionSystem::Get(browser_context_); |
| 517 QuotaService* quota = extension_system->quota_service(); | 517 QuotaService* quota = extension_system->quota_service(); |
| 518 std::string violation_error = quota->Assess(extension->id(), | 518 std::string violation_error = quota->Assess(extension->id(), |
| 519 function.get(), | 519 function.get(), |
| 520 ¶ms.arguments, | 520 ¶ms.arguments, |
| 521 base::TimeTicks::Now()); | 521 base::TimeTicks::Now()); |
| 522 | 522 |
| 523 if (violation_error.empty()) { | 523 if (violation_error.empty()) { |
| 524 std::unique_ptr<base::ListValue> args(params.arguments.DeepCopy()); | 524 std::unique_ptr<base::ListValue> args(params.arguments.DeepCopy()); |
| 525 | 525 |
| 526 // See crbug.com/39178. | 526 // See crbug.com/39178. |
| 527 ExtensionsBrowserClient::Get()->PermitExternalProtocolHandler(); | 527 ExtensionsBrowserClient::Get()->PermitExternalProtocolHandler(); |
| 528 NotifyApiFunctionCalled(extension->id(), params.name, std::move(args), | 528 NotifyApiFunctionCalled(extension->id(), params.name, std::move(args), |
| 529 browser_context_); | 529 browser_context_); |
| 530 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.FunctionCalls", | 530 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.FunctionCalls", |
| 531 function->histogram_value()); | 531 function->histogram_value()); |
| 532 tracked_objects::ScopedProfile scoped_profile( | 532 tracked_objects::ScopedProfile scoped_profile( |
| 533 FROM_HERE_WITH_EXPLICIT_FUNCTION(function->name()), | 533 FROM_HERE_WITH_EXPLICIT_FUNCTION(function->name()), |
| 534 tracked_objects::ScopedProfile::ENABLED); | 534 tracked_objects::ScopedProfile::ENABLED); |
| 535 base::ElapsedTimer timer; | 535 base::ElapsedTimer timer; |
| 536 function->Run()->Execute(); | 536 function->RunWithValidation()->Execute(); |
| 537 // TODO(devlin): Once we have a baseline metric for how long functions take, | 537 // TODO(devlin): Once we have a baseline metric for how long functions take, |
| 538 // we can create a handful of buckets and record the function name so that | 538 // we can create a handful of buckets and record the function name so that |
| 539 // we can find what the fastest/slowest are. | 539 // we can find what the fastest/slowest are. |
| 540 // Note: Many functions execute finish asynchronously, so this time is not | 540 // Note: Many functions execute finish asynchronously, so this time is not |
| 541 // always a representation of total time taken. See also | 541 // always a representation of total time taken. See also |
| 542 // Extensions.Functions.TotalExecutionTime. | 542 // Extensions.Functions.TotalExecutionTime. |
| 543 UMA_HISTOGRAM_TIMES("Extensions.Functions.SynchronousExecutionTime", | 543 UMA_HISTOGRAM_TIMES("Extensions.Functions.SynchronousExecutionTime", |
| 544 timer.Elapsed()); | 544 timer.Elapsed()); |
| 545 } else { | 545 } else { |
| 546 function->OnQuotaExceeded(violation_error); | 546 function->OnQuotaExceeded(violation_error); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 // static | 651 // static |
| 652 void ExtensionFunctionDispatcher::SendAccessDenied( | 652 void ExtensionFunctionDispatcher::SendAccessDenied( |
| 653 const ExtensionFunction::ResponseCallback& callback, | 653 const ExtensionFunction::ResponseCallback& callback, |
| 654 functions::HistogramValue histogram_value) { | 654 functions::HistogramValue histogram_value) { |
| 655 base::ListValue empty_list; | 655 base::ListValue empty_list; |
| 656 callback.Run(ExtensionFunction::FAILED, empty_list, | 656 callback.Run(ExtensionFunction::FAILED, empty_list, |
| 657 "Access to extension API denied.", histogram_value); | 657 "Access to extension API denied.", histogram_value); |
| 658 } | 658 } |
| 659 | 659 |
| 660 } // namespace extensions | 660 } // namespace extensions |
| OLD | NEW |