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_
10 #include "base/macros.h"
11 #include "base/supports_user_data.h"
17 namespace data_use_measurement
{
19 // Used to annotate URLRequests with the service name if the URLRequest is used
21 class DataUseUserData
: public base::SupportsUserData::Data
{
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.
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
;
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_