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:
37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void ProvideSystemProfileMetrics(
38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      metrics::SystemProfileProto* system_profile) OVERRIDE;
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) protected:
41cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Exposed for the sake of mocking in test code.
42cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Retrieves the set of extensions installed in the given |profile|.
446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual scoped_ptr<extensions::ExtensionSet> GetInstalledExtensions(
456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      Profile* profile);
46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Retrieves the client ID.
48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual uint64 GetClientID();
49cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Hashes the extension extension ID using the provided client key (which
51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // must be less than kExtensionListClientKeys) and to produce an output value
52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // between 0 and kExtensionListBuckets-1.
53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static int HashExtension(const std::string& extension_id, uint32 client_key);
54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private:
56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Returns the profile for which extensions will be gathered.  Once a
57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // suitable profile has been found, future calls will continue to return the
58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // same value so that reported extensions are consistent.
59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Profile* GetMetricsProfile();
60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
616e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Writes whether any loaded profiles have extensions not from the webstore.
626e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void ProvideOffStoreMetric(metrics::SystemProfileProto* system_profile);
636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // Writes the hashed list of installed extensions into the specified
656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // SystemProfileProto object.
666e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void ProvideOccupiedBucketMetric(metrics::SystemProfileProto* system_profile);
676e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
68cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // The MetricsStateManager from which the client ID is obtained.
69cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  metrics::MetricsStateManager* metrics_state_manager_;
70a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
716e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // The profile for which extensions are gathered for the occupied bucket
726e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // metric. Once a profile is found its value is cached here so that
736e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // GetMetricsProfile() can return a consistent value.
74a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Profile* cached_profile_;
75a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
76cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ExtensionsMetricsProvider);
77a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
78a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
79cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#endif  // CHROME_BROWSER_METRICS_EXTENSIONS_METRICS_PROVIDER_H_
80