extensions_metrics_provider.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file.
4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#ifndef CHROME_BROWSER_METRICS_EXTENSIONS_METRICS_PROVIDER_H_
6cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#define CHROME_BROWSER_METRICS_EXTENSIONS_METRICS_PROVIDER_H_
7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include <string>
9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/basictypes.h"
11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
12cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/metrics/metrics_provider.h"
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class Profile;
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace extensions {
17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class ExtensionSet;
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace metrics {
21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class MetricsStateManager;
22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class SystemProfileProto;
23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// ExtensionsMetricsProvider groups various constants and functions used for
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// reporting extension IDs with UMA reports (after hashing the extension IDs
27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// for privacy).
28cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class ExtensionsMetricsProvider : public metrics::MetricsProvider {
29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public:
30cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Holds on to |metrics_state_manager|, which must outlive this object, as a
31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // weak pointer.
32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  explicit ExtensionsMetricsProvider(
33cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      metrics::MetricsStateManager* metrics_state_manager);
34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual ~ExtensionsMetricsProvider();
35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // metrics::MetricsProvider:
37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Writes the hashed list of installed extensions into the specified
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // SystemProfileProto object.
40cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void ProvideSystemProfileMetrics(
41cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      metrics::SystemProfileProto* system_profile) OVERRIDE;
42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) protected:
44cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Exposed for the sake of mocking in test code.
45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Retrieves the set of extensions installed in the current profile.
47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // TODO(mvrable): If metrics are ever converted to being per-profile, then
48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // this should be updated to return extensions installed in a specified
49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // profile.
50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual scoped_ptr<extensions::ExtensionSet> GetInstalledExtensions();
51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
52cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Retrieves the client ID.
53cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual uint64 GetClientID();
54cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Hashes the extension extension ID using the provided client key (which
56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // must be less than kExtensionListClientKeys) and to produce an output value
57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // between 0 and kExtensionListBuckets-1.
58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static int HashExtension(const std::string& extension_id, uint32 client_key);
59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private:
61a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Returns the profile for which extensions will be gathered.  Once a
62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // suitable profile has been found, future calls will continue to return the
63a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // same value so that reported extensions are consistent.
64a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Profile* GetMetricsProfile();
65a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
66cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // The MetricsStateManager from which the client ID is obtained.
67cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  metrics::MetricsStateManager* metrics_state_manager_;
68a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
69a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // The profile for which extensions are gathered.  Once a profile is found
70a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // its value is cached here so that GetMetricsProfile() can return a
71a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // consistent value.
72a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Profile* cached_profile_;
73a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
74cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ExtensionsMetricsProvider);
75a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
76a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
77cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#endif  // CHROME_BROWSER_METRICS_EXTENSIONS_METRICS_PROVIDER_H_
78