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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/metrics/sparse_histogram.h" |
12 #include "base/process/process.h" | 13 #include "base/process/process.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
17 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
18 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
19 #include "content/public/browser/user_metrics.h" | 20 #include "content/public/browser/user_metrics.h" |
20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
21 #include "content/public/browser/web_contents_observer.h" | 22 #include "content/public/browser/web_contents_observer.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 std::string violation_error = quota->Assess(extension->id(), | 265 std::string violation_error = quota->Assess(extension->id(), |
265 function.get(), | 266 function.get(), |
266 ¶ms.arguments, | 267 ¶ms.arguments, |
267 base::TimeTicks::Now()); | 268 base::TimeTicks::Now()); |
268 if (violation_error.empty()) { | 269 if (violation_error.empty()) { |
269 scoped_ptr<base::ListValue> args(params.arguments.DeepCopy()); | 270 scoped_ptr<base::ListValue> args(params.arguments.DeepCopy()); |
270 NotifyApiFunctionCalled(extension->id(), | 271 NotifyApiFunctionCalled(extension->id(), |
271 params.name, | 272 params.name, |
272 args.Pass(), | 273 args.Pass(), |
273 static_cast<content::BrowserContext*>(profile_id)); | 274 static_cast<content::BrowserContext*>(profile_id)); |
| 275 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.FunctionCalls", |
| 276 function->histogram_value()); |
274 function->Run(); | 277 function->Run(); |
275 } else { | 278 } else { |
276 function->OnQuotaExceeded(violation_error); | 279 function->OnQuotaExceeded(violation_error); |
277 } | 280 } |
278 } | 281 } |
279 | 282 |
280 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( | 283 ExtensionFunctionDispatcher::ExtensionFunctionDispatcher( |
281 content::BrowserContext* browser_context, | 284 content::BrowserContext* browser_context, |
282 Delegate* delegate) | 285 Delegate* delegate) |
283 : browser_context_(browser_context), | 286 : browser_context_(browser_context), |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 QuotaService* quota = extension_system->quota_service(); | 373 QuotaService* quota = extension_system->quota_service(); |
371 std::string violation_error = quota->Assess(extension->id(), | 374 std::string violation_error = quota->Assess(extension->id(), |
372 function.get(), | 375 function.get(), |
373 ¶ms.arguments, | 376 ¶ms.arguments, |
374 base::TimeTicks::Now()); | 377 base::TimeTicks::Now()); |
375 if (violation_error.empty()) { | 378 if (violation_error.empty()) { |
376 scoped_ptr<base::ListValue> args(params.arguments.DeepCopy()); | 379 scoped_ptr<base::ListValue> args(params.arguments.DeepCopy()); |
377 | 380 |
378 NotifyApiFunctionCalled( | 381 NotifyApiFunctionCalled( |
379 extension->id(), params.name, args.Pass(), browser_context_); | 382 extension->id(), params.name, args.Pass(), browser_context_); |
| 383 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.FunctionCalls", |
| 384 function->histogram_value()); |
380 function->Run(); | 385 function->Run(); |
381 } else { | 386 } else { |
382 function->OnQuotaExceeded(violation_error); | 387 function->OnQuotaExceeded(violation_error); |
383 } | 388 } |
384 | 389 |
385 // Note: do not access |this| after this point. We may have been deleted | 390 // Note: do not access |this| after this point. We may have been deleted |
386 // if function->Run() ended up closing the tab that owns us. | 391 // if function->Run() ended up closing the tab that owns us. |
387 | 392 |
388 // Check if extension was uninstalled by management.uninstall. | 393 // Check if extension was uninstalled by management.uninstall. |
389 if (!registry->enabled_extensions().GetByID(params.extension_id)) | 394 if (!registry->enabled_extensions().GetByID(params.extension_id)) |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 | 508 |
504 // static | 509 // static |
505 void ExtensionFunctionDispatcher::SendAccessDenied( | 510 void ExtensionFunctionDispatcher::SendAccessDenied( |
506 const ExtensionFunction::ResponseCallback& callback) { | 511 const ExtensionFunction::ResponseCallback& callback) { |
507 base::ListValue empty_list; | 512 base::ListValue empty_list; |
508 callback.Run(ExtensionFunction::FAILED, empty_list, | 513 callback.Run(ExtensionFunction::FAILED, empty_list, |
509 "Access to extension API denied."); | 514 "Access to extension API denied."); |
510 } | 515 } |
511 | 516 |
512 } // namespace extensions | 517 } // namespace extensions |
OLD | NEW |