• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/socket/socket_tag.h"
6 
7 #include <tuple>
8 
9 #include "base/check.h"
10 #include "build/build_config.h"
11 
12 #if BUILDFLAG(IS_ANDROID)
13 #include "net/android/network_library.h"
14 #endif  // BUILDFLAG(IS_ANDROID)
15 
16 namespace net {
17 
18 #if BUILDFLAG(IS_ANDROID)
19 // Expose UNSET_UID to Java.
20 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net
21 enum TrafficStatsUid {
22   UNSET = -1,
23 };
24 // Java generator needs explicit integer, verify equality here.
25 static_assert(UNSET == SocketTag::UNSET_UID,
26               "TrafficStatsUid does not match SocketTag::UNSET_UID");
27 #endif  // BUILDFLAG(IS_ANDROID)
28 
operator <(const SocketTag & other) const29 bool SocketTag::operator<(const SocketTag& other) const {
30 #if BUILDFLAG(IS_ANDROID)
31   return std::tie(uid_, traffic_stats_tag_) <
32          std::tie(other.uid_, other.traffic_stats_tag_);
33 #else
34   return false;
35 #endif  // BUILDFLAG(IS_ANDROID)
36 }
37 
operator ==(const SocketTag & other) const38 bool SocketTag::operator==(const SocketTag& other) const {
39 #if BUILDFLAG(IS_ANDROID)
40   return std::tie(uid_, traffic_stats_tag_) ==
41          std::tie(other.uid_, other.traffic_stats_tag_);
42 #else
43   return true;
44 #endif  // BUILDFLAG(IS_ANDROID)
45 }
46 
Apply(SocketDescriptor socket) const47 void SocketTag::Apply(SocketDescriptor socket) const {
48 #if BUILDFLAG(IS_ANDROID)
49   net::android::TagSocket(socket, uid_, traffic_stats_tag_);
50 #else
51   CHECK(false);
52 #endif  // BUILDFLAG(IS_ANDROID)
53 }
54 
55 }  // namespace net
56