summaryrefslogtreecommitdiffstats
path: root/content/renderer/manifest/manifest_uma_util.cc
blob: 3eb5da7a5e2d004d464091e645dea0ed0737e849 (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
// Copyright 2014 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 "content/renderer/manifest/manifest_uma_util.h"

#include "base/metrics/histogram.h"
#include "content/public/common/manifest.h"

namespace content {

namespace {

static const char kUMANameParseSuccess[] = "Manifest.ParseSuccess";
static const char kUMANameFetchResult[] = "Manifest.FetchResult";

// Enum for UMA purposes, make sure you update histograms.xml if you add new
// result types. Never delete or reorder an entry; only add new entries
// immediately before MANIFEST_FETCH_RESULT_TYPE_COUNT.
enum ManifestFetchResultType {
  MANIFEST_FETCH_SUCCESS = 0,
  MANIFEST_FETCH_ERROR_EMPTY_URL = 1,
  MANIFEST_FETCH_ERROR_UNSPECIFIED = 2,

  // Must stay at the end.
  MANIFEST_FETCH_RESULT_TYPE_COUNT
};

} // anonymous namespace

void ManifestUmaUtil::ParseSucceeded(const Manifest& manifest) {
  UMA_HISTOGRAM_BOOLEAN(kUMANameParseSuccess, true);
  UMA_HISTOGRAM_BOOLEAN("Manifest.IsEmpty", manifest.IsEmpty());
  if (manifest.IsEmpty())
    return;

  UMA_HISTOGRAM_BOOLEAN("Manifest.HasProperty.name", !manifest.name.is_null());
  UMA_HISTOGRAM_BOOLEAN("Manifest.HasProperty.short_name",
      !manifest.short_name.is_null());
  UMA_HISTOGRAM_BOOLEAN("Manifest.HasProperty.start_url",
      !manifest.start_url.is_empty());
  UMA_HISTOGRAM_BOOLEAN("Manifest.HasProperty.display",
      manifest.display != blink::WebDisplayModeUndefined);
  UMA_HISTOGRAM_BOOLEAN("Manifest.HasProperty.orientation",
      manifest.orientation != blink::WebScreenOrientationLockDefault);
  UMA_HISTOGRAM_BOOLEAN("Manifest.HasProperty.icons", !manifest.icons.empty());
  UMA_HISTOGRAM_BOOLEAN("Manifest.HasProperty.gcm_sender_id",
      !manifest.gcm_sender_id.is_null());
}

void ManifestUmaUtil::ParseFailed() {
  UMA_HISTOGRAM_BOOLEAN(kUMANameParseSuccess, false);
}

void ManifestUmaUtil::FetchSucceeded() {
  UMA_HISTOGRAM_ENUMERATION(kUMANameFetchResult,
                            MANIFEST_FETCH_SUCCESS,
                            MANIFEST_FETCH_RESULT_TYPE_COUNT);
}

void ManifestUmaUtil::FetchFailed(FetchFailureReason reason) {
  ManifestFetchResultType fetch_result_type = MANIFEST_FETCH_RESULT_TYPE_COUNT;
  switch (reason) {
    case FETCH_EMPTY_URL:
      fetch_result_type = MANIFEST_FETCH_ERROR_EMPTY_URL;
      break;
    case FETCH_UNSPECIFIED_REASON:
      fetch_result_type = MANIFEST_FETCH_ERROR_UNSPECIFIED;
      break;
  }
  DCHECK_NE(fetch_result_type, MANIFEST_FETCH_RESULT_TYPE_COUNT);

  UMA_HISTOGRAM_ENUMERATION(kUMANameFetchResult,
                            fetch_result_type,
                            MANIFEST_FETCH_RESULT_TYPE_COUNT);
}

} // namespace content