Home | History | Annotate | Download | only in network
      1 // Copyright 2014 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.
      4 
      5 #ifndef CHROMEOS_NETWORK_NETWORK_TYPE_PATTERN_H_
      6 #define CHROMEOS_NETWORK_NETWORK_TYPE_PATTERN_H_
      7 
      8 #include <string>
      9 
     10 #include "base/macros.h"
     11 #include "chromeos/chromeos_export.h"
     12 
     13 namespace chromeos {
     14 
     15 class CHROMEOS_EXPORT NetworkTypePattern {
     16  public:
     17   // Matches any network.
     18   static NetworkTypePattern Default();
     19 
     20   // Matches wireless (WiFi, cellular, etc.) networks
     21   static NetworkTypePattern Wireless();
     22 
     23   // Matches cellular or wimax networks.
     24   static NetworkTypePattern Mobile();
     25 
     26   // Matches non virtual networks.
     27   static NetworkTypePattern NonVirtual();
     28 
     29   // Matches ethernet networks (with or without EAP).
     30   static NetworkTypePattern Ethernet();
     31 
     32   static NetworkTypePattern WiFi();
     33   static NetworkTypePattern Cellular();
     34   static NetworkTypePattern VPN();
     35   static NetworkTypePattern Wimax();
     36 
     37   // Matches only networks of exactly the type |shill_network_type|, which must
     38   // be one of the types defined in service_constants.h (e.g.
     39   // shill::kTypeWifi).
     40   // Note: Shill distinguishes Ethernet without EAP from Ethernet with EAP. If
     41   // unsure, better use one of the matchers above.
     42   static NetworkTypePattern Primitive(const std::string& shill_network_type);
     43 
     44   bool Equals(const NetworkTypePattern& other) const;
     45   bool MatchesType(const std::string& shill_network_type) const;
     46 
     47   // Returns true if this pattern matches at least one network type that
     48   // |other_pattern| matches (according to MatchesType). Thus MatchesPattern is
     49   // symmetric and reflexive but not transitive.
     50   // See the unit test for examples.
     51   bool MatchesPattern(const NetworkTypePattern& other_pattern) const;
     52 
     53   std::string ToDebugString() const;
     54 
     55  private:
     56   explicit NetworkTypePattern(int pattern);
     57 
     58   // The bit array of the matching network types.
     59   int pattern_;
     60 
     61   DISALLOW_ASSIGN(NetworkTypePattern);
     62 };
     63 
     64 }  // namespace chromeos
     65 
     66 #endif  // CHROMEOS_NETWORK_NETWORK_TYPE_PATTERN_H_
     67