summaryrefslogtreecommitdiff
path: root/chromium/extensions/renderer/extension_bindings_system.cc
blob: 8c344efcb9cf686f0ed67ae4f9ea53ee5c27fe28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "extensions/renderer/extension_bindings_system.h"

#include "base/metrics/histogram_macros.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_handlers/externally_connectable.h"
#include "extensions/renderer/renderer_extension_registry.h"
#include "extensions/renderer/script_context.h"

namespace extensions {

namespace {

const int kHistogramBucketCount = 50;

}  // namespace

// static
bool ExtensionBindingsSystem::IsRuntimeAvailableToContext(
    ScriptContext* context) {
  for (const auto& extension :
       *RendererExtensionRegistry::Get()->GetMainThreadExtensionSet()) {
    ExternallyConnectableInfo* info = static_cast<ExternallyConnectableInfo*>(
        extension->GetManifestData(manifest_keys::kExternallyConnectable));
    if (info && info->matches.MatchesURL(context->url()))
      return true;
  }
  return false;
}

// static
const char* const ExtensionBindingsSystem::kWebAvailableFeatures[] = {
    "app", "webstore", "dashboardPrivate",
};

void ExtensionBindingsSystem::LogUpdateBindingsForContextTime(
    Feature::Context context_type,
    base::TimeDelta elapsed) {
  static const int kTenSecondsInMicroseconds = 10000000;
  switch (context_type) {
    case Feature::UNSPECIFIED_CONTEXT:
      break;
    case Feature::WEB_PAGE_CONTEXT:
      UMA_HISTOGRAM_CUSTOM_COUNTS(
          "Extensions.Bindings.UpdateBindingsForContextTime.WebPageContext",
          elapsed.InMicroseconds(), 1, kTenSecondsInMicroseconds,
          kHistogramBucketCount);
      break;
    case Feature::BLESSED_WEB_PAGE_CONTEXT:
      UMA_HISTOGRAM_CUSTOM_COUNTS(
          "Extensions.Bindings.UpdateBindingsForContextTime."
          "BlessedWebPageContext",
          elapsed.InMicroseconds(), 1, kTenSecondsInMicroseconds,
          kHistogramBucketCount);
      break;
    case Feature::SERVICE_WORKER_CONTEXT:
      UMA_HISTOGRAM_CUSTOM_COUNTS(
          "Extensions.Bindings.UpdateBindingsForContextTime."
          "ServiceWorkerContext",
          elapsed.InMicroseconds(), 1, kTenSecondsInMicroseconds,
          kHistogramBucketCount);
      break;
    case Feature::BLESSED_EXTENSION_CONTEXT:
      UMA_HISTOGRAM_CUSTOM_COUNTS(
          "Extensions.Bindings.UpdateBindingsForContextTime."
          "BlessedExtensionContext",
          elapsed.InMicroseconds(), 1, kTenSecondsInMicroseconds,
          kHistogramBucketCount);
      break;
    case Feature::LOCK_SCREEN_EXTENSION_CONTEXT:
      UMA_HISTOGRAM_CUSTOM_COUNTS(
          "Extensions.Bindings.UpdateBindingsForContextTime."
          "LockScreenExtensionContext",
          elapsed.InMicroseconds(), 1, kTenSecondsInMicroseconds,
          kHistogramBucketCount);
      break;
    case Feature::UNBLESSED_EXTENSION_CONTEXT:
      UMA_HISTOGRAM_CUSTOM_COUNTS(
          "Extensions.Bindings.UpdateBindingsForContextTime."
          "UnblessedExtensionContext",
          elapsed.InMicroseconds(), 1, kTenSecondsInMicroseconds,
          kHistogramBucketCount);
      break;
    case Feature::CONTENT_SCRIPT_CONTEXT:
      UMA_HISTOGRAM_CUSTOM_COUNTS(
          "Extensions.Bindings.UpdateBindingsForContextTime."
          "ContentScriptContext",
          elapsed.InMicroseconds(), 1, kTenSecondsInMicroseconds,
          kHistogramBucketCount);
      break;
    case Feature::WEBUI_CONTEXT:
      UMA_HISTOGRAM_CUSTOM_COUNTS(
          "Extensions.Bindings.UpdateBindingsForContextTime.WebUIContext",
          elapsed.InMicroseconds(), 1, kTenSecondsInMicroseconds,
          kHistogramBucketCount);
  }
}

}  // namespace extensions