| 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/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 14 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
| 15 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
| 16 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
| 17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
| 19 #include "extensions/browser/extension_function_dispatcher.h" | 20 #include "extensions/browser/extension_function_dispatcher.h" |
| 20 #include "extensions/browser/extension_message_filter.h" | 21 #include "extensions/browser/extension_message_filter.h" |
| 21 #include "extensions/common/error_utils.h" | 22 #include "extensions/common/error_utils.h" |
| 22 #include "extensions/common/extension_api.h" | 23 #include "extensions/common/extension_api.h" |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 if (bad_message_) { | 400 if (bad_message_) { |
| 400 type = BAD_MESSAGE; | 401 type = BAD_MESSAGE; |
| 401 LOG(ERROR) << "Bad extension message " << name_; | 402 LOG(ERROR) << "Bad extension message " << name_; |
| 402 } | 403 } |
| 403 | 404 |
| 404 // If results were never set, we send an empty argument list. | 405 // If results were never set, we send an empty argument list. |
| 405 if (!results_) | 406 if (!results_) |
| 406 results_.reset(new base::ListValue()); | 407 results_.reset(new base::ListValue()); |
| 407 | 408 |
| 408 response_callback_.Run(type, *results_, GetError(), histogram_value()); | 409 response_callback_.Run(type, *results_, GetError(), histogram_value()); |
| 410 |
| 411 // TODO(devlin): Once we have a baseline metric for how long functions take, |
| 412 // we can create a handful of buckets and record the function name so that we |
| 413 // can find what the fastest/slowest are. See crbug.com/608561. |
| 414 // Note: Certain functions perform actions that are inherently slow - such as |
| 415 // anything waiting on user action. As such, we can't always assume that a |
| 416 // long execution time equates to a poorly-performing function. |
| 417 if (success) { |
| 418 UMA_HISTOGRAM_TIMES("Extensions.Functions.SucceededTotalExecutionTime", |
| 419 timer_.Elapsed()); |
| 420 } else { |
| 421 UMA_HISTOGRAM_TIMES("Extensions.Functions.FailedTotalExecutionTime", |
| 422 timer_.Elapsed()); |
| 423 } |
| 409 } | 424 } |
| 410 | 425 |
| 411 void ExtensionFunction::OnRespondingLater(ResponseValue value) { | 426 void ExtensionFunction::OnRespondingLater(ResponseValue value) { |
| 412 SendResponse(value->Apply()); | 427 SendResponse(value->Apply()); |
| 413 } | 428 } |
| 414 | 429 |
| 415 UIThreadExtensionFunction::UIThreadExtensionFunction() | 430 UIThreadExtensionFunction::UIThreadExtensionFunction() |
| 416 : context_(nullptr), | 431 : context_(nullptr), |
| 417 render_frame_host_(nullptr), | 432 render_frame_host_(nullptr), |
| 418 delegate_(nullptr) { | 433 delegate_(nullptr) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { | 574 ExtensionFunction::ResponseAction SyncIOThreadExtensionFunction::Run() { |
| 560 return RespondNow(RunSync() ? ArgumentList(std::move(results_)) | 575 return RespondNow(RunSync() ? ArgumentList(std::move(results_)) |
| 561 : Error(error_)); | 576 : Error(error_)); |
| 562 } | 577 } |
| 563 | 578 |
| 564 // static | 579 // static |
| 565 bool SyncIOThreadExtensionFunction::ValidationFailure( | 580 bool SyncIOThreadExtensionFunction::ValidationFailure( |
| 566 SyncIOThreadExtensionFunction* function) { | 581 SyncIOThreadExtensionFunction* function) { |
| 567 return false; | 582 return false; |
| 568 } | 583 } |
| OLD | NEW |