| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.h" | 5 #include "extensions/browser/extension_function.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 14 #include "base/metrics/sparse_histogram.h" |
| 14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 15 #include "content/public/browser/notification_source.h" | 16 #include "content/public/browser/notification_source.h" |
| 16 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
| 17 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
| 18 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
| 20 #include "extensions/browser/extension_function_dispatcher.h" | 21 #include "extensions/browser/extension_function_dispatcher.h" |
| 21 #include "extensions/browser/extension_message_filter.h" | 22 #include "extensions/browser/extension_message_filter.h" |
| 22 #include "extensions/browser/extensions_browser_client.h" | 23 #include "extensions/browser/extensions_browser_client.h" |
| 23 #include "extensions/common/error_utils.h" | 24 #include "extensions/common/error_utils.h" |
| 24 #include "extensions/common/extension_api.h" | 25 #include "extensions/common/extension_api.h" |
| 25 #include "extensions/common/extension_messages.h" | 26 #include "extensions/common/extension_messages.h" |
| 26 | 27 |
| 27 using content::BrowserThread; | 28 using content::BrowserThread; |
| 28 using content::RenderViewHost; | 29 using content::RenderViewHost; |
| 29 using content::WebContents; | 30 using content::WebContents; |
| 30 using extensions::ErrorUtils; | 31 using extensions::ErrorUtils; |
| 31 using extensions::ExtensionAPI; | 32 using extensions::ExtensionAPI; |
| 32 using extensions::Feature; | 33 using extensions::Feature; |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 37 // Logs UMA about the performance for a given extension function run. |
| 38 void LogUma(bool success, |
| 39 base::TimeDelta elapsed_time, |
| 40 extensions::functions::HistogramValue histogram_value) { |
| 41 // Note: Certain functions perform actions that are inherently slow - such as |
| 42 // anything waiting on user action. As such, we can't always assume that a |
| 43 // long execution time equates to a poorly-performing function. |
| 44 if (success) { |
| 45 if (elapsed_time < base::TimeDelta::FromMilliseconds(1)) { |
| 46 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 47 "Extensions.Functions.SucceededTime.LessThan1ms", histogram_value); |
| 48 } else if (elapsed_time < base::TimeDelta::FromMilliseconds(5)) { |
| 49 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.Functions.SucceededTime.1msTo5ms", |
| 50 histogram_value); |
| 51 } else if (elapsed_time < base::TimeDelta::FromMilliseconds(10)) { |
| 52 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 53 "Extensions.Functions.SucceededTime.5msTo10ms", histogram_value); |
| 54 } else { |
| 55 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.Functions.SucceededTime.Over10ms", |
| 56 histogram_value); |
| 57 } |
| 58 UMA_HISTOGRAM_TIMES("Extensions.Functions.SucceededTotalExecutionTime", |
| 59 elapsed_time); |
| 60 } else { |
| 61 if (elapsed_time < base::TimeDelta::FromMilliseconds(1)) { |
| 62 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.Functions.FailedTime.LessThan1ms", |
| 63 histogram_value); |
| 64 } else if (elapsed_time < base::TimeDelta::FromMilliseconds(5)) { |
| 65 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.Functions.FailedTime.1msTo5ms", |
| 66 histogram_value); |
| 67 } else if (elapsed_time < base::TimeDelta::FromMilliseconds(10)) { |
| 68 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.Functions.FailedTime.5msTo10ms", |
| 69 histogram_value); |
| 70 } else { |
| 71 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.Functions.FailedTime.Over10ms", |
| 72 histogram_value); |
| 73 } |
| 74 UMA_HISTOGRAM_TIMES("Extensions.Functions.FailedTotalExecutionTime", |
| 75 elapsed_time); |
| 76 } |
| 77 } |
| 78 |
| 36 class ArgumentListResponseValue | 79 class ArgumentListResponseValue |
| 37 : public ExtensionFunction::ResponseValueObject { | 80 : public ExtensionFunction::ResponseValueObject { |
| 38 public: | 81 public: |
| 39 ArgumentListResponseValue(const std::string& function_name, | 82 ArgumentListResponseValue(const std::string& function_name, |
| 40 const char* title, | 83 const char* title, |
| 41 ExtensionFunction* function, | 84 ExtensionFunction* function, |
| 42 std::unique_ptr<base::ListValue> result) | 85 std::unique_ptr<base::ListValue> result) |
| 43 : function_name_(function_name), title_(title) { | 86 : function_name_(function_name), title_(title) { |
| 44 if (function->GetResultList()) { | 87 if (function->GetResultList()) { |
| 45 DCHECK_EQ(function->GetResultList(), result.get()) | 88 DCHECK_EQ(function->GetResultList(), result.get()) |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 if (bad_message_) { | 455 if (bad_message_) { |
| 413 type = BAD_MESSAGE; | 456 type = BAD_MESSAGE; |
| 414 LOG(ERROR) << "Bad extension message " << name_; | 457 LOG(ERROR) << "Bad extension message " << name_; |
| 415 } | 458 } |
| 416 | 459 |
| 417 // If results were never set, we send an empty argument list. | 460 // If results were never set, we send an empty argument list. |
| 418 if (!results_) | 461 if (!results_) |
| 419 results_.reset(new base::ListValue()); | 462 results_.reset(new base::ListValue()); |
| 420 | 463 |
| 421 response_callback_.Run(type, *results_, GetError(), histogram_value()); | 464 response_callback_.Run(type, *results_, GetError(), histogram_value()); |
| 422 | 465 LogUma(success, timer_.Elapsed(), histogram_value_); |
| 423 // TODO(devlin): Once we have a baseline metric for how long functions take, | |
| 424 // we can create a handful of buckets and record the function name so that we | |
| 425 // can find what the fastest/slowest are. See crbug.com/608561. | |
| 426 // Note: Certain functions perform actions that are inherently slow - such as | |
| 427 // anything waiting on user action. As such, we can't always assume that a | |
| 428 // long execution time equates to a poorly-performing function. | |
| 429 if (success) { | |
| 430 UMA_HISTOGRAM_TIMES("Extensions.Functions.SucceededTotalExecutionTime", | |
| 431 timer_.Elapsed()); | |
| 432 } else { | |
| 433 UMA_HISTOGRAM_TIMES("Extensions.Functions.FailedTotalExecutionTime", | |
| 434 timer_.Elapsed()); | |
| 435 } | |
| 436 } | 466 } |
| 437 | 467 |
| 438 void ExtensionFunction::OnRespondingLater(ResponseValue value) { | 468 void ExtensionFunction::OnRespondingLater(ResponseValue value) { |
| 439 SendResponse(value->Apply()); | 469 SendResponse(value->Apply()); |
| 440 } | 470 } |
| 441 | 471 |
| 442 UIThreadExtensionFunction::UIThreadExtensionFunction() | 472 UIThreadExtensionFunction::UIThreadExtensionFunction() |
| 443 : context_(nullptr), | 473 : context_(nullptr), |
| 444 render_frame_host_(nullptr), | 474 render_frame_host_(nullptr), |
| 445 is_from_service_worker_(false), | 475 is_from_service_worker_(false), |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { | 634 ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { |
| 605 return RespondNow(RunSync() ? ArgumentList(std::move(results_)) | 635 return RespondNow(RunSync() ? ArgumentList(std::move(results_)) |
| 606 : Error(error_)); | 636 : Error(error_)); |
| 607 } | 637 } |
| 608 | 638 |
| 609 // static | 639 // static |
| 610 bool SyncIOThreadExtensionFunction::ValidationFailure( | 640 bool SyncIOThreadExtensionFunction::ValidationFailure( |
| 611 SyncIOThreadExtensionFunction* function) { | 641 SyncIOThreadExtensionFunction* function) { |
| 612 return false; | 642 return false; |
| 613 } | 643 } |
| OLD | NEW |