Commit 737a9f06 authored by vabr@chromium.org's avatar vabr@chromium.org

Moving metrics to api/ .


BUG=101244
TEST=N/A, only moving code, no change in functionality


Review URL: https://chromiumcodereview.appspot.com/10696145

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146092 0039d316-1c4b-4281-b951-d872f2087c98
parent bf48a1f4
...@@ -197,7 +197,7 @@ ...@@ -197,7 +197,7 @@
'|chrome/common/metrics/.*'\ '|chrome/common/metrics/.*'\
'|chrome_frame/metrics.*'\ '|chrome_frame/metrics.*'\
'|chrome/browser/chromeos/external_metrics.*'\ '|chrome/browser/chromeos/external_metrics.*'\
'|chrome/browser/extensions/extension_metrics_module.*'\ '|chrome/browser/extensions/api/metrics/metrics.*'\
'|chrome/browser/ui/webui/metrics_handler.*'\ '|chrome/browser/ui/webui/metrics_handler.*'\
'|content/browser/user_metrics.cc'\ '|content/browser/user_metrics.cc'\
'|content/public/browser/user_metrics.h'\ '|content/public/browser/user_metrics.h'\
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/extensions/extension_metrics_module.h" #include "chrome/browser/extensions/api/metrics/metrics.h"
#include <algorithm> #include <algorithm>
...@@ -10,13 +10,17 @@ ...@@ -10,13 +10,17 @@
#include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension.h"
#include "content/public/browser/user_metrics.h" #include "content/public/browser/user_metrics.h"
namespace extensions {
using base::Histogram; using base::Histogram;
using base::LinearHistogram; using base::LinearHistogram;
using content::UserMetricsAction;
namespace {
const size_t kMaxBuckets = 10000; // We don't ever want more than these many const size_t kMaxBuckets = 10000; // We don't ever want more than these many
// buckets; there is no real need for them // buckets; there is no real need for them
// and would cause crazy memory usage // and would cause crazy memory usage
} // namespace
bool MetricsRecordUserActionFunction::RunImpl() { bool MetricsRecordUserActionFunction::RunImpl() {
std::string name; std::string name;
...@@ -33,12 +37,11 @@ bool MetricsHistogramHelperFunction::GetNameAndSample(std::string* name, ...@@ -33,12 +37,11 @@ bool MetricsHistogramHelperFunction::GetNameAndSample(std::string* name,
return true; return true;
} }
bool MetricsHistogramHelperFunction::RecordValue(const std::string& name, bool MetricsHistogramHelperFunction::RecordValue(
Histogram::ClassType type, const std::string& name,
int min, Histogram::ClassType type,
int max, int min, int max, size_t buckets,
size_t buckets, int sample) {
int sample) {
// Make sure toxic values don't get to internal code. // Make sure toxic values don't get to internal code.
// Fix for maximums // Fix for maximums
min = std::min(min, INT_MAX - 3); min = std::min(min, INT_MAX - 3);
...@@ -55,15 +58,11 @@ bool MetricsHistogramHelperFunction::RecordValue(const std::string& name, ...@@ -55,15 +58,11 @@ bool MetricsHistogramHelperFunction::RecordValue(const std::string& name,
Histogram* counter; Histogram* counter;
if (type == Histogram::LINEAR_HISTOGRAM) { if (type == Histogram::LINEAR_HISTOGRAM) {
counter = LinearHistogram::FactoryGet(name, counter = LinearHistogram::FactoryGet(name,
min, min, max, buckets,
max,
buckets,
Histogram::kUmaTargetedHistogramFlag); Histogram::kUmaTargetedHistogramFlag);
} else { } else {
counter = Histogram::FactoryGet(name, counter = Histogram::FactoryGet(name,
min, min, max, buckets,
max,
buckets,
Histogram::kUmaTargetedHistogramFlag); Histogram::kUmaTargetedHistogramFlag);
} }
...@@ -99,7 +98,10 @@ bool MetricsRecordPercentageFunction::RunImpl() { ...@@ -99,7 +98,10 @@ bool MetricsRecordPercentageFunction::RunImpl() {
std::string name; std::string name;
int sample; int sample;
EXTENSION_FUNCTION_VALIDATE(GetNameAndSample(&name, &sample)); EXTENSION_FUNCTION_VALIDATE(GetNameAndSample(&name, &sample));
return RecordValue(name, Histogram::LINEAR_HISTOGRAM, 1, 101, 102, sample); return RecordValue(name,
Histogram::LINEAR_HISTOGRAM,
1, 101, 102,
sample);
} }
bool MetricsRecordCountFunction::RunImpl() { bool MetricsRecordCountFunction::RunImpl() {
...@@ -146,3 +148,5 @@ bool MetricsRecordLongTimeFunction::RunImpl() { ...@@ -146,3 +148,5 @@ bool MetricsRecordLongTimeFunction::RunImpl() {
static const int kOneHourMs = 60 * 60 * 1000; static const int kOneHourMs = 60 * 60 * 1000;
return RecordValue(name, Histogram::HISTOGRAM, 1, kOneHourMs, 50, sample); return RecordValue(name, Histogram::HISTOGRAM, 1, kOneHourMs, 50, sample);
} }
} // namespace extensions
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_METRICS_MODULE_H__ #ifndef CHROME_BROWSER_EXTENSIONS_API_METRICS_METRICS_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_METRICS_MODULE_H__ #define CHROME_BROWSER_EXTENSIONS_API_METRICS_METRICS_H_
#pragma once #pragma once
#include <string> #include <string>
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "chrome/browser/extensions/extension_function.h" #include "chrome/browser/extensions/extension_function.h"
namespace extensions {
class MetricsRecordUserActionFunction : public SyncExtensionFunction { class MetricsRecordUserActionFunction : public SyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION_NAME("metricsPrivate.recordUserAction") DECLARE_EXTENSION_FUNCTION_NAME("metricsPrivate.recordUserAction")
...@@ -28,7 +30,8 @@ class MetricsHistogramHelperFunction : public SyncExtensionFunction { ...@@ -28,7 +30,8 @@ class MetricsHistogramHelperFunction : public SyncExtensionFunction {
bool GetNameAndSample(std::string* name, int* sample); bool GetNameAndSample(std::string* name, int* sample);
virtual bool RecordValue(const std::string& name, virtual bool RecordValue(const std::string& name,
base::Histogram::ClassType type, base::Histogram::ClassType type,
int min, int max, size_t buckets, int sample); int min, int max, size_t buckets,
int sample);
}; };
class MetricsRecordValueFunction : public MetricsHistogramHelperFunction { class MetricsRecordValueFunction : public MetricsHistogramHelperFunction {
...@@ -119,4 +122,6 @@ class MetricsRecordLongTimeFunction : public MetricsHistogramHelperFunction { ...@@ -119,4 +122,6 @@ class MetricsRecordLongTimeFunction : public MetricsHistogramHelperFunction {
virtual bool RunImpl() OVERRIDE; virtual bool RunImpl() OVERRIDE;
}; };
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_METRICS_MODULE_H__ } // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_METRICS_METRICS_H_
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chrome/browser/extensions/api/extension_action/extension_script_badge_api.h" #include "chrome/browser/extensions/api/extension_action/extension_script_badge_api.h"
#include "chrome/browser/extensions/api/identity/identity_api.h" #include "chrome/browser/extensions/api/identity/identity_api.h"
#include "chrome/browser/extensions/api/media_gallery/media_gallery_api.h" #include "chrome/browser/extensions/api/media_gallery/media_gallery_api.h"
#include "chrome/browser/extensions/api/metrics/metrics.h"
#include "chrome/browser/extensions/api/offscreen_tabs/offscreen_tabs_api.h" #include "chrome/browser/extensions/api/offscreen_tabs/offscreen_tabs_api.h"
#include "chrome/browser/extensions/api/omnibox/omnibox_api.h" #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
#include "chrome/browser/extensions/api/permissions/permissions_api.h" #include "chrome/browser/extensions/api/permissions/permissions_api.h"
...@@ -39,7 +40,6 @@ ...@@ -39,7 +40,6 @@
#include "chrome/browser/extensions/extension_idle_api.h" #include "chrome/browser/extensions/extension_idle_api.h"
#include "chrome/browser/extensions/extension_managed_mode_api.h" #include "chrome/browser/extensions/extension_managed_mode_api.h"
#include "chrome/browser/extensions/extension_management_api.h" #include "chrome/browser/extensions/extension_management_api.h"
#include "chrome/browser/extensions/extension_metrics_module.h"
#include "chrome/browser/extensions/extension_module.h" #include "chrome/browser/extensions/extension_module.h"
#include "chrome/browser/extensions/extension_page_capture_api.h" #include "chrome/browser/extensions/extension_page_capture_api.h"
#include "chrome/browser/extensions/extension_preference_api.h" #include "chrome/browser/extensions/extension_preference_api.h"
...@@ -207,15 +207,15 @@ void ExtensionFunctionRegistry::ResetFunctions() { ...@@ -207,15 +207,15 @@ void ExtensionFunctionRegistry::ResetFunctions() {
RegisterFunction<GetProcessInfoFunction>(); RegisterFunction<GetProcessInfoFunction>();
// Metrics. // Metrics.
RegisterFunction<MetricsRecordUserActionFunction>(); RegisterFunction<extensions::MetricsRecordUserActionFunction>();
RegisterFunction<MetricsRecordValueFunction>(); RegisterFunction<extensions::MetricsRecordValueFunction>();
RegisterFunction<MetricsRecordPercentageFunction>(); RegisterFunction<extensions::MetricsRecordPercentageFunction>();
RegisterFunction<MetricsRecordCountFunction>(); RegisterFunction<extensions::MetricsRecordCountFunction>();
RegisterFunction<MetricsRecordSmallCountFunction>(); RegisterFunction<extensions::MetricsRecordSmallCountFunction>();
RegisterFunction<MetricsRecordMediumCountFunction>(); RegisterFunction<extensions::MetricsRecordMediumCountFunction>();
RegisterFunction<MetricsRecordTimeFunction>(); RegisterFunction<extensions::MetricsRecordTimeFunction>();
RegisterFunction<MetricsRecordMediumTimeFunction>(); RegisterFunction<extensions::MetricsRecordMediumTimeFunction>();
RegisterFunction<MetricsRecordLongTimeFunction>(); RegisterFunction<extensions::MetricsRecordLongTimeFunction>();
// RLZ. // RLZ.
#if defined(OS_WIN) || defined(OS_MACOSX) #if defined(OS_WIN) || defined(OS_MACOSX)
......
...@@ -528,6 +528,8 @@ ...@@ -528,6 +528,8 @@
}], }],
['enable_extensions==1', { ['enable_extensions==1', {
'sources': [ 'sources': [
'browser/extensions/api/metrics/metrics.cc',
'browser/extensions/api/metrics/metrics.h',
'browser/extensions/api/tabs/execute_code_in_tab_function.cc', 'browser/extensions/api/tabs/execute_code_in_tab_function.cc',
'browser/extensions/api/tabs/execute_code_in_tab_function.h', 'browser/extensions/api/tabs/execute_code_in_tab_function.h',
'browser/extensions/api/tabs/tabs.cc', 'browser/extensions/api/tabs/tabs.cc',
...@@ -556,8 +558,6 @@ ...@@ -556,8 +558,6 @@
'browser/extensions/extension_managed_mode_api.h', 'browser/extensions/extension_managed_mode_api.h',
'browser/extensions/extension_management_api.cc', 'browser/extensions/extension_management_api.cc',
'browser/extensions/extension_management_api.h', 'browser/extensions/extension_management_api.h',
'browser/extensions/extension_metrics_module.cc',
'browser/extensions/extension_metrics_module.h',
'browser/extensions/extension_page_capture_api.cc', 'browser/extensions/extension_page_capture_api.cc',
'browser/extensions/extension_page_capture_api.h', 'browser/extensions/extension_page_capture_api.h',
'browser/extensions/extension_preference_api.cc', 'browser/extensions/extension_preference_api.cc',
......
...@@ -2732,6 +2732,7 @@ ...@@ -2732,6 +2732,7 @@
'browser/extensions/api/identity/identity_apitest.cc', 'browser/extensions/api/identity/identity_apitest.cc',
'browser/extensions/api/idltest/idltest_apitest.cc', 'browser/extensions/api/idltest/idltest_apitest.cc',
'browser/extensions/api/media_gallery/media_gallery_apitest.cc', 'browser/extensions/api/media_gallery/media_gallery_apitest.cc',
'browser/extensions/api/metrics/metrics_apitest.cc',
'browser/extensions/api/offscreen_tabs/offscreen_tabs_apitest.cc', 'browser/extensions/api/offscreen_tabs/offscreen_tabs_apitest.cc',
'browser/extensions/api/omnibox/omnibox_apitest.cc', 'browser/extensions/api/omnibox/omnibox_apitest.cc',
'browser/extensions/api/permissions/permissions_apitest.cc', 'browser/extensions/api/permissions/permissions_apitest.cc',
...@@ -2798,7 +2799,6 @@ ...@@ -2798,7 +2799,6 @@
'browser/extensions/extension_management_apitest.cc', 'browser/extensions/extension_management_apitest.cc',
'browser/extensions/extension_management_browsertest.cc', 'browser/extensions/extension_management_browsertest.cc',
'browser/extensions/extension_messages_apitest.cc', 'browser/extensions/extension_messages_apitest.cc',
'browser/extensions/extension_metrics_apitest.cc',
'browser/extensions/extension_module_apitest.cc', 'browser/extensions/extension_module_apitest.cc',
'browser/extensions/extension_override_apitest.cc', 'browser/extensions/extension_override_apitest.cc',
'browser/extensions/extension_page_capture_apitest.cc', 'browser/extensions/extension_page_capture_apitest.cc',
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
// Any changes to the logging done in these functions should be matched // Any changes to the logging done in these functions should be matched
// with the checks done in IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Metrics). // with the checks done in IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Metrics).
// See extension_metrics_apitest.cc. // See metrics_apitest.cc.
chrome.test.runTests([ chrome.test.runTests([
function recordUserAction() { function recordUserAction() {
// Log a metric once. // Log a metric once.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment