Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: extensions/renderer/extension_frame_helper.cc

Issue 2337063003: [Extensions] Add metrics for asynchronous port creation (Closed)
Patch Set: Rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/renderer/extension_frame_helper.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/renderer/extension_frame_helper.h" 5 #include "extensions/renderer/extension_frame_helper.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/timer/elapsed_timer.h"
9 #include "content/public/renderer/render_frame.h" 10 #include "content/public/renderer/render_frame.h"
10 #include "extensions/common/api/messaging/message.h" 11 #include "extensions/common/api/messaging/message.h"
11 #include "extensions/common/constants.h" 12 #include "extensions/common/constants.h"
12 #include "extensions/common/extension_messages.h" 13 #include "extensions/common/extension_messages.h"
13 #include "extensions/common/manifest_handlers/background_info.h" 14 #include "extensions/common/manifest_handlers/background_info.h"
14 #include "extensions/renderer/console.h" 15 #include "extensions/renderer/console.h"
15 #include "extensions/renderer/content_watcher.h" 16 #include "extensions/renderer/content_watcher.h"
16 #include "extensions/renderer/dispatcher.h" 17 #include "extensions/renderer/dispatcher.h"
17 #include "extensions/renderer/messaging_bindings.h" 18 #include "extensions/renderer/messaging_bindings.h"
18 #include "extensions/renderer/script_context.h" 19 #include "extensions/renderer/script_context.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // callbacks that are added during the iteration. 75 // callbacks that are added during the iteration.
75 std::vector<base::Closure> callbacks; 76 std::vector<base::Closure> callbacks;
76 callbacks_to_be_run_and_cleared->swap(callbacks); 77 callbacks_to_be_run_and_cleared->swap(callbacks);
77 for (auto& callback : callbacks) { 78 for (auto& callback : callbacks) {
78 callback.Run(); 79 callback.Run();
79 if (!frame_helper.get()) 80 if (!frame_helper.get())
80 return; // Frame and ExtensionFrameHelper invalidated by callback. 81 return; // Frame and ExtensionFrameHelper invalidated by callback.
81 } 82 }
82 } 83 }
83 84
85 enum class PortType {
86 EXTENSION,
87 TAB,
88 NATIVE_APP,
89 };
90
84 } // namespace 91 } // namespace
85 92
93 struct ExtensionFrameHelper::PendingPortRequest {
94 PendingPortRequest(PortType type, const base::Callback<void(int)>& callback)
95 : type(type), callback(callback) {}
96 ~PendingPortRequest() {}
97
98 base::ElapsedTimer timer;
99 PortType type;
100 base::Callback<void(int)> callback;
101
102 private:
103 DISALLOW_COPY_AND_ASSIGN(PendingPortRequest);
104 };
105
86 ExtensionFrameHelper::ExtensionFrameHelper(content::RenderFrame* render_frame, 106 ExtensionFrameHelper::ExtensionFrameHelper(content::RenderFrame* render_frame,
87 Dispatcher* extension_dispatcher) 107 Dispatcher* extension_dispatcher)
88 : content::RenderFrameObserver(render_frame), 108 : content::RenderFrameObserver(render_frame),
89 content::RenderFrameObserverTracker<ExtensionFrameHelper>(render_frame), 109 content::RenderFrameObserverTracker<ExtensionFrameHelper>(render_frame),
90 view_type_(VIEW_TYPE_INVALID), 110 view_type_(VIEW_TYPE_INVALID),
91 tab_id_(-1), 111 tab_id_(-1),
92 browser_window_id_(-1), 112 browser_window_id_(-1),
93 extension_dispatcher_(extension_dispatcher), 113 extension_dispatcher_(extension_dispatcher),
94 did_create_current_document_element_(false), 114 did_create_current_document_element_(false),
95 next_port_request_id_(0), 115 next_port_request_id_(0),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 const base::Closure& callback) { 193 const base::Closure& callback) {
174 document_load_finished_callbacks_.push_back(callback); 194 document_load_finished_callbacks_.push_back(callback);
175 } 195 }
176 196
177 void ExtensionFrameHelper::RequestPortId( 197 void ExtensionFrameHelper::RequestPortId(
178 const ExtensionMsg_ExternalConnectionInfo& info, 198 const ExtensionMsg_ExternalConnectionInfo& info,
179 const std::string& channel_name, 199 const std::string& channel_name,
180 bool include_tls_channel_id, 200 bool include_tls_channel_id,
181 const base::Callback<void(int)>& callback) { 201 const base::Callback<void(int)>& callback) {
182 int port_request_id = next_port_request_id_++; 202 int port_request_id = next_port_request_id_++;
183 pending_port_requests_[port_request_id] = callback; 203 pending_port_requests_[port_request_id] =
204 base::MakeUnique<PendingPortRequest>(PortType::EXTENSION, callback);
184 { 205 {
185 SCOPED_UMA_HISTOGRAM_TIMER( 206 SCOPED_UMA_HISTOGRAM_TIMER(
186 "Extensions.Messaging.GetPortIdSyncTime.Extension"); 207 "Extensions.Messaging.GetPortIdSyncTime.Extension");
187 render_frame()->Send(new ExtensionHostMsg_OpenChannelToExtension( 208 render_frame()->Send(new ExtensionHostMsg_OpenChannelToExtension(
188 render_frame()->GetRoutingID(), info, channel_name, 209 render_frame()->GetRoutingID(), info, channel_name,
189 include_tls_channel_id, port_request_id)); 210 include_tls_channel_id, port_request_id));
190 } 211 }
191 } 212 }
192 213
193 void ExtensionFrameHelper::RequestTabPortId( 214 void ExtensionFrameHelper::RequestTabPortId(
194 const ExtensionMsg_TabTargetConnectionInfo& info, 215 const ExtensionMsg_TabTargetConnectionInfo& info,
195 const std::string& extension_id, 216 const std::string& extension_id,
196 const std::string& channel_name, 217 const std::string& channel_name,
197 const base::Callback<void(int)>& callback) { 218 const base::Callback<void(int)>& callback) {
198 int port_request_id = next_port_request_id_++; 219 int port_request_id = next_port_request_id_++;
199 pending_port_requests_[port_request_id] = callback; 220 pending_port_requests_[port_request_id] =
221 base::MakeUnique<PendingPortRequest>(PortType::TAB, callback);
200 { 222 {
201 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.Messaging.GetPortIdSyncTime.Tab"); 223 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.Messaging.GetPortIdSyncTime.Tab");
202 render_frame()->Send(new ExtensionHostMsg_OpenChannelToTab( 224 render_frame()->Send(new ExtensionHostMsg_OpenChannelToTab(
203 render_frame()->GetRoutingID(), info, extension_id, channel_name, 225 render_frame()->GetRoutingID(), info, extension_id, channel_name,
204 port_request_id)); 226 port_request_id));
205 } 227 }
206 } 228 }
207 229
208 void ExtensionFrameHelper::RequestNativeAppPortId( 230 void ExtensionFrameHelper::RequestNativeAppPortId(
209 const std::string& native_app_name, 231 const std::string& native_app_name,
210 const base::Callback<void(int)>& callback) { 232 const base::Callback<void(int)>& callback) {
211 int port_request_id = next_port_request_id_++; 233 int port_request_id = next_port_request_id_++;
212 pending_port_requests_[port_request_id] = callback; 234 pending_port_requests_[port_request_id] =
235 base::MakeUnique<PendingPortRequest>(PortType::NATIVE_APP, callback);
213 { 236 {
214 SCOPED_UMA_HISTOGRAM_TIMER( 237 SCOPED_UMA_HISTOGRAM_TIMER(
215 "Extensions.Messaging.GetPortIdSyncTime.NativeApp"); 238 "Extensions.Messaging.GetPortIdSyncTime.NativeApp");
216 render_frame()->Send(new ExtensionHostMsg_OpenChannelToNativeApp( 239 render_frame()->Send(new ExtensionHostMsg_OpenChannelToNativeApp(
217 render_frame()->GetRoutingID(), native_app_name, port_request_id)); 240 render_frame()->GetRoutingID(), native_app_name, port_request_id));
218 } 241 }
219 } 242 }
220 243
221 void ExtensionFrameHelper::DidMatchCSS( 244 void ExtensionFrameHelper::DidMatchCSS(
222 const blink::WebVector<blink::WebString>& newly_matching_selectors, 245 const blink::WebVector<blink::WebString>& newly_matching_selectors,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 const base::ListValue& args, 357 const base::ListValue& args,
335 bool user_gesture) { 358 bool user_gesture) {
336 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id, 359 extension_dispatcher_->InvokeModuleSystemMethod(render_frame(), extension_id,
337 module_name, function_name, 360 module_name, function_name,
338 args, user_gesture); 361 args, user_gesture);
339 } 362 }
340 363
341 void ExtensionFrameHelper::OnAssignPortId(int port_id, int request_id) { 364 void ExtensionFrameHelper::OnAssignPortId(int port_id, int request_id) {
342 auto iter = pending_port_requests_.find(request_id); 365 auto iter = pending_port_requests_.find(request_id);
343 DCHECK(iter != pending_port_requests_.end()); 366 DCHECK(iter != pending_port_requests_.end());
344 iter->second.Run(port_id); 367 PendingPortRequest& request = *iter->second;
368 switch (request.type) {
369 case PortType::EXTENSION: {
370 UMA_HISTOGRAM_TIMES("Extensions.Messaging.GetPortIdAsyncTime.Extension",
371 request.timer.Elapsed());
372 break;
373 }
374 case PortType::TAB: {
375 UMA_HISTOGRAM_TIMES("Extensions.Messaging.GetPortIdAsyncTime.Tab",
376 request.timer.Elapsed());
377 break;
378 }
379 case PortType::NATIVE_APP: {
380 UMA_HISTOGRAM_TIMES("Extensions.Messaging.GetPortIdAsyncTime.NativeApp",
381 request.timer.Elapsed());
382 break;
383 }
384 }
385 request.callback.Run(port_id);
345 pending_port_requests_.erase(iter); 386 pending_port_requests_.erase(iter);
346 } 387 }
347 388
348 void ExtensionFrameHelper::OnDestruct() { 389 void ExtensionFrameHelper::OnDestruct() {
349 delete this; 390 delete this;
350 } 391 }
351 392
352 } // namespace extensions 393 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/extension_frame_helper.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698