| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_ASH_VPN_DELEGATE_CHROMEOS_H_ | 5 #ifndef CHROME_BROWSER_UI_ASH_VPN_LIST_CLIENT_H_ |
| 6 #define CHROME_BROWSER_UI_ASH_VPN_DELEGATE_CHROMEOS_H_ | 6 #define CHROME_BROWSER_UI_ASH_VPN_LIST_CLIENT_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include "ash/public/interfaces/vpn_list.mojom.h" |
| 9 | |
| 10 #include "ash/common/system/chromeos/network/vpn_delegate.h" | |
| 11 #include "base/macros.h" | 9 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 13 #include "content/public/browser/notification_observer.h" | 11 #include "content/public/browser/notification_observer.h" |
| 14 #include "content/public/browser/notification_registrar.h" | 12 #include "content/public/browser/notification_registrar.h" |
| 15 #include "extensions/browser/extension_registry_observer.h" | 13 #include "extensions/browser/extension_registry_observer.h" |
| 14 #include "mojo/public/cpp/bindings/binding.h" |
| 16 | 15 |
| 17 namespace extensions { | 16 namespace extensions { |
| 18 class ExtensionRegistry; | 17 class ExtensionRegistry; |
| 19 } | 18 } |
| 20 | 19 |
| 21 // Chrome OS implementation of a delegate that provides UI code in ash with | 20 // A service that provides UI code in ash with the list of extension-backed |
| 22 // access to the VPN providers enabled in the primary user's profile. | 21 // VPN providers in the primary user's profile. The service also allows ash to |
| 23 class VPNDelegateChromeOS : public ash::VPNDelegate, | 22 // request that chrome show an "add network" page for a VPN provider. |
| 24 public extensions::ExtensionRegistryObserver, | 23 class VpnListClient : public ash::mojom::VpnListClient, |
| 25 public content::NotificationObserver { | 24 public extensions::ExtensionRegistryObserver, |
| 25 public content::NotificationObserver { |
| 26 public: | 26 public: |
| 27 VPNDelegateChromeOS(); | 27 VpnListClient(); |
| 28 ~VPNDelegateChromeOS() override; | 28 ~VpnListClient() override; |
| 29 | 29 |
| 30 // ash::VPNDelegate: | 30 // ash::mojom::VpnListClient: |
| 31 void ShowAddPage(const ash::VPNProvider::Key& key) override; | 31 void ShowBuiltInAddNetworkPage() override; |
| 32 void ShowThirdPartyAddNetworkPage(const std::string& extension_id) override; |
| 32 | 33 |
| 33 // extensions::ExtensionRegistryObserver: | 34 // extensions::ExtensionRegistryObserver: |
| 34 void OnExtensionLoaded(content::BrowserContext* browser_context, | 35 void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 35 const extensions::Extension* extension) override; | 36 const extensions::Extension* extension) override; |
| 36 void OnExtensionUnloaded( | 37 void OnExtensionUnloaded( |
| 37 content::BrowserContext* browser_context, | 38 content::BrowserContext* browser_context, |
| 38 const extensions::Extension* extension, | 39 const extensions::Extension* extension, |
| 39 extensions::UnloadedExtensionInfo::Reason reason) override; | 40 extensions::UnloadedExtensionInfo::Reason reason) override; |
| 40 void OnShutdown(extensions::ExtensionRegistry* registry) override; | 41 void OnShutdown(extensions::ExtensionRegistry* registry) override; |
| 41 | 42 |
| 42 // content::NotificationObserver: | 43 // content::NotificationObserver: |
| 43 void Observe(int type, | 44 void Observe(int type, |
| 44 const content::NotificationSource& source, | 45 const content::NotificationSource& source, |
| 45 const content::NotificationDetails& details) override; | 46 const content::NotificationDetails& details) override; |
| 46 | 47 |
| 47 private: | 48 private: |
| 49 // Connects to the VpnList service in ash and returns the interface pointer. |
| 50 ash::mojom::VpnListPtr ConnectToVpnList(); |
| 51 |
| 48 // Retrieves the current list of VPN providers enabled in the primary user's | 52 // Retrieves the current list of VPN providers enabled in the primary user's |
| 49 // profile and notifies observers that it has changed. Must only be called | 53 // profile and notifies observers that it has changed. Must only be called |
| 50 // when a user is logged in and the primary user's extension registry is being | 54 // when a user is logged in and the primary user's extension registry is being |
| 51 // observed. | 55 // observed. |
| 52 void UpdateVPNProviders(); | 56 void UpdateVPNProviders(); |
| 53 | 57 |
| 54 // Starts observing the primary user's extension registry to detect changes to | 58 // Starts observing the primary user's extension registry to detect changes to |
| 55 // the list of VPN providers enabled in the user's profile and caches the | 59 // the list of VPN providers enabled in the user's profile and caches the |
| 56 // initial list. Must only be called when a user is logged in. | 60 // initial list. Must only be called when a user is logged in. |
| 57 void AttachToPrimaryUserExtensionRegistry(); | 61 void AttachToPrimaryUserExtensionRegistry(); |
| 58 | 62 |
| 63 // Binds this object to the mojo interface. |
| 64 mojo::Binding<ash::mojom::VpnListClient> binding_; |
| 65 |
| 66 // Whether this object has ever sent a third-party provider list to ash. |
| 67 bool sent_providers_ = false; |
| 68 |
| 59 // The primary user's extension registry, if a user is logged in. | 69 // The primary user's extension registry, if a user is logged in. |
| 60 extensions::ExtensionRegistry* extension_registry_ = nullptr; | 70 extensions::ExtensionRegistry* extension_registry_ = nullptr; |
| 61 | 71 |
| 62 content::NotificationRegistrar registrar_; | 72 content::NotificationRegistrar registrar_; |
| 63 | 73 |
| 64 base::WeakPtrFactory<VPNDelegateChromeOS> weak_factory_; | 74 base::WeakPtrFactory<VpnListClient> weak_factory_; |
| 65 | 75 |
| 66 DISALLOW_COPY_AND_ASSIGN(VPNDelegateChromeOS); | 76 DISALLOW_COPY_AND_ASSIGN(VpnListClient); |
| 67 }; | 77 }; |
| 68 | 78 |
| 69 #endif // CHROME_BROWSER_UI_ASH_VPN_DELEGATE_CHROMEOS_H_ | 79 #endif // CHROME_BROWSER_UI_ASH_VPN_LIST_CLIENT_H_ |
| OLD | NEW |