summaryrefslogtreecommitdiffstats
path: root/ash/system/chromeos/network/vpn_delegate.h
blob: fd6fe72972e8e88fd3cf42b635291a651ed0f9c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_VPN_DELEGATE_H
#define ASH_SYSTEM_CHROMEOS_NETWORK_VPN_DELEGATE_H

#include <string>
#include <vector>

#include "ash/ash_export.h"
#include "base/macros.h"
#include "base/observer_list.h"

namespace chromeos {
class NetworkState;
}

namespace ash {

// Describes a VPN provider.
struct ASH_EXPORT VPNProvider {
  struct Key {
    // Constructs a key for the built-in VPN provider.
    Key();

    // Constructs a key for a third-party VPN provider.
    explicit Key(const std::string& extension_id);

    bool operator==(const Key& other) const;

    // Indicates whether |network| belongs to this VPN provider.
    bool MatchesNetwork(const chromeos::NetworkState& network) const;

    // Whether this key represents a built-in or third-party VPN provider.
    bool third_party;

    // ID of the extension that implements this provider. Used for third-party
    // VPN providers only.
    std::string extension_id;
  };

  VPNProvider(const Key& key, const std::string& name);

  // Key that uniquely identifies this VPN provider.
  Key key;

  // Human-readable name.
  std::string name;
};

// This delegate provides UI code in ash, e.g. |VPNList|, with access to the
// list of VPN providers enabled in the primary user's profile. The delegate
// furthermore allows the UI code to request that a VPN provider show its "add
// network" dialog.
class ASH_EXPORT VPNDelegate {
 public:
  // An observer that is notified whenever the list of VPN providers enabled in
  // the primary user's profile changes.
  class Observer {
   public:
    virtual void OnVPNProvidersChanged() = 0;

   protected:
    virtual ~Observer();

   private:
    DISALLOW_ASSIGN(Observer);
  };

  VPNDelegate();
  virtual ~VPNDelegate();

  // Returns |true| if at least one third-party VPN provider is enabled in the
  // primary user's profile, in addition to the built-in OpenVPN/L2TP provider.
  virtual bool HaveThirdPartyVPNProviders() const = 0;

  // Returns the list of VPN providers enabled in the primary user's profile.
  virtual const std::vector<VPNProvider>& GetVPNProviders() const = 0;

  // Requests that the VPN provider identified by |key| show its "add network"
  // dialog.
  virtual void ShowAddPage(const VPNProvider::Key& key) = 0;

  void AddObserver(Observer* observer);
  void RemoveObserver(Observer* observer);

 protected:
  // Notify observers that the list of VPN providers enabled in the primary
  // user's profile has changed.
  void NotifyObservers();

 private:
  base::ObserverList<Observer> observer_list_;

  DISALLOW_COPY_AND_ASSIGN(VPNDelegate);
};

}  // namespace ash

#endif  // ASH_SYSTEM_CHROMEOS_NETWORK_VPN_DELEGATE_H