Support needed to measure user and service traffic in Chrome.
[chromium-blink-merge.git] / components / data_use_measurement / core / data_use_user_data.h
blob55bdd1f351142e345c93b75e3e901d779fc1c63a
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_USER_DATA_H_
6 #define COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_USER_DATA_H_
8 #include <string>
10 #include "base/macros.h"
11 #include "base/supports_user_data.h"
13 namespace net {
14 class URLFetcher;
17 namespace data_use_measurement {
19 // Used to annotate URLRequests with the service name if the URLRequest is used
20 // by a service.
21 class DataUseUserData : public base::SupportsUserData::Data {
22 public:
23 // This enum should be synced with DataUseServices enum in histograms.xml.
24 // Please keep them synced after any updates. Also add service name to
25 // GetServiceNameAsString function.
26 enum ServiceName {
27 NOT_TAGGED,
28 SUGGESTIONS,
31 explicit DataUseUserData(ServiceName service_name);
32 ~DataUseUserData() override;
34 // Helper function to create DataUseUserData. The caller takes the ownership
35 // of the returned object.
36 static base::SupportsUserData::Data* Create(
37 DataUseUserData::ServiceName service);
39 // Return the service name of the ServiceName enum.
40 static std::string GetServiceNameAsString(ServiceName service);
42 // Services should use this function to attach their |service_name| to the
43 // URLFethcer serving them.
44 static void AttachToFetcher(net::URLFetcher* fetcher,
45 ServiceName service_name);
47 ServiceName service_name() const { return service_name_; }
49 // The key for retrieving back this type of user data.
50 static const void* kUserDataKey;
52 private:
53 const ServiceName service_name_;
55 DISALLOW_COPY_AND_ASSIGN(DataUseUserData);
58 } // data_use_measurement namespace
60 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_USER_DATA_H_