| 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/renderer/binding_generating_native_handler.h" | 5 #include "extensions/renderer/binding_generating_native_handler.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/timer/elapsed_timer.h" |
| 8 #include "extensions/renderer/script_context.h" | 10 #include "extensions/renderer/script_context.h" |
| 9 #include "extensions/renderer/v8_helpers.h" | 11 #include "extensions/renderer/v8_helpers.h" |
| 10 | 12 |
| 11 namespace extensions { | 13 namespace extensions { |
| 12 | 14 |
| 13 using namespace v8_helpers; | 15 using namespace v8_helpers; |
| 14 | 16 |
| 15 BindingGeneratingNativeHandler::BindingGeneratingNativeHandler( | 17 BindingGeneratingNativeHandler::BindingGeneratingNativeHandler( |
| 16 ScriptContext* context, | 18 ScriptContext* context, |
| 17 const std::string& api_name, | 19 const std::string& api_name, |
| 18 const std::string& bind_to) | 20 const std::string& bind_to) |
| 19 : context_(context), api_name_(api_name), bind_to_(bind_to) {} | 21 : context_(context), api_name_(api_name), bind_to_(bind_to) {} |
| 20 | 22 |
| 21 v8::Local<v8::Object> BindingGeneratingNativeHandler::NewInstance() { | 23 v8::Local<v8::Object> BindingGeneratingNativeHandler::NewInstance() { |
| 24 base::ElapsedTimer timer; |
| 22 // This long sequence of commands effectively runs the JavaScript code, | 25 // This long sequence of commands effectively runs the JavaScript code, |
| 23 // such that result[bind_to] is the compiled schema for |api_name|: | 26 // such that result[bind_to] is the compiled schema for |api_name|: |
| 24 // | 27 // |
| 25 // var result = {}; | 28 // var result = {}; |
| 26 // result[bind_to] = require('binding').Binding.create(api_name).generate(); | 29 // result[bind_to] = require('binding').Binding.create(api_name).generate(); |
| 27 // return result; | 30 // return result; |
| 28 // | 31 // |
| 29 // Unfortunately using the v8 APIs makes that quite verbose. | 32 // Unfortunately using the v8 APIs makes that quite verbose. |
| 30 // Each stage is marked with the code it executes. | 33 // Each stage is marked with the code it executes. |
| 31 v8::Isolate* isolate = context_->isolate(); | 34 v8::Isolate* isolate = context_->isolate(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 NOTREACHED(); | 101 NOTREACHED(); |
| 99 return v8::Local<v8::Object>(); | 102 return v8::Local<v8::Object>(); |
| 100 } | 103 } |
| 101 | 104 |
| 102 // var result = {}; | 105 // var result = {}; |
| 103 // result[bind_to] = ...; | 106 // result[bind_to] = ...; |
| 104 if (!SetProperty(v8_context, object, v8_bind_to, compiled_schema)) { | 107 if (!SetProperty(v8_context, object, v8_bind_to, compiled_schema)) { |
| 105 NOTREACHED(); | 108 NOTREACHED(); |
| 106 return v8::Local<v8::Object>(); | 109 return v8::Local<v8::Object>(); |
| 107 } | 110 } |
| 111 |
| 112 // Log UMA with microsecond accuracy*; maxes at 10 seconds. |
| 113 // *Obviously, limited by our TimeTicks implementation, but as close as |
| 114 // possible. |
| 115 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ApiBindingObjectGenerationTime", |
| 116 timer.Elapsed().InMicroseconds(), |
| 117 1, 10000000, 100); |
| 108 // return result; | 118 // return result; |
| 109 return scope.Escape(object); | 119 return scope.Escape(object); |
| 110 } | 120 } |
| 111 | 121 |
| 112 } // namespace extensions | 122 } // namespace extensions |
| OLD | NEW |