Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / ash / vpn_delegate_chromeos.h
blobb4271c4b6e4c30373956cfc93e37e3a02f75e07e
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 CHROME_BROWSER_UI_ASH_VPN_DELEGATE_CHROMEOS_H_
6 #define CHROME_BROWSER_UI_ASH_VPN_DELEGATE_CHROMEOS_H_
8 #include <vector>
10 #include "ash/system/chromeos/network/vpn_delegate.h"
11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "extensions/browser/extension_registry_observer.h"
17 namespace extensions {
18 class ExtensionRegistry;
21 // Chrome OS implementation of a delegate that provides UI code in ash with
22 // access to the VPN providers enabled in the primary user's profile.
23 class VPNDelegateChromeOS : public ash::VPNDelegate,
24 public extensions::ExtensionRegistryObserver,
25 public content::NotificationObserver {
26 public:
27 VPNDelegateChromeOS();
28 ~VPNDelegateChromeOS() override;
30 // ash::VPNDelegate:
31 bool HaveThirdPartyVPNProviders() const override;
32 const std::vector<ash::VPNProvider>& GetVPNProviders() const override;
33 void ShowAddPage(const ash::VPNProvider::Key& key) override;
35 // extensions::ExtensionRegistryObserver:
36 void OnExtensionLoaded(content::BrowserContext* browser_context,
37 const extensions::Extension* extension) override;
38 void OnExtensionUnloaded(
39 content::BrowserContext* browser_context,
40 const extensions::Extension* extension,
41 extensions::UnloadedExtensionInfo::Reason reason) override;
42 void OnShutdown(extensions::ExtensionRegistry* registry) override;
44 // content::NotificationObserver:
45 void Observe(int type,
46 const content::NotificationSource& source,
47 const content::NotificationDetails& details) override;
49 private:
50 // Retrieves the current list of VPN providers enabled in the primary user's
51 // profile and notifies observers that it has changed. Must only be called
52 // when a user is logged in and the primary user's extension registry is being
53 // observed.
54 void UpdateVPNProviders();
56 // Starts observing the primary user's extension registry to detect changes to
57 // the list of VPN providers enabled in the user's profile and caches the
58 // initial list. Must only be called when a user is logged in.
59 void AttachToPrimaryUserExtensionRegistry();
61 // The primary user's extension registry, if a user is logged in.
62 extensions::ExtensionRegistry* extension_registry_ = nullptr;
64 // A cache of the VPN providers enabled in the primary user's profile.
65 std::vector<ash::VPNProvider> vpn_providers_;
67 content::NotificationRegistrar registrar_;
69 base::WeakPtrFactory<VPNDelegateChromeOS> weak_factory_;
71 DISALLOW_COPY_AND_ASSIGN(VPNDelegateChromeOS);
74 #endif // CHROME_BROWSER_UI_ASH_VPN_DELEGATE_CHROMEOS_H_