OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "extensions/browser/api/vpn_provider/vpn_service.h" | 5 #include "extensions/browser/api/vpn_provider/vpn_service.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 const std::string& configuration_name) { | 424 const std::string& configuration_name) { |
425 const std::string key = GetKey(extension_id, configuration_name); | 425 const std::string key = GetKey(extension_id, configuration_name); |
426 return ContainsKey(key_to_configuration_map_, key); | 426 return ContainsKey(key_to_configuration_map_, key); |
427 } | 427 } |
428 | 428 |
429 bool VpnService::VerifyConfigIsConnectedForTesting( | 429 bool VpnService::VerifyConfigIsConnectedForTesting( |
430 const std::string& extension_id) { | 430 const std::string& extension_id) { |
431 return DoesActiveConfigurationExistAndIsAccessAuthorized(extension_id); | 431 return DoesActiveConfigurationExistAndIsAccessAuthorized(extension_id); |
432 } | 432 } |
433 | 433 |
434 void VpnService::OnExtensionUninstalled( | 434 void VpnService::DestroyConfigurationsForExtension( |
435 content::BrowserContext* browser_context, | 435 const extensions::Extension* extension) { |
436 const extensions::Extension* extension, | |
437 extensions::UninstallReason reason) { | |
438 if (browser_context != browser_context_) { | |
439 NOTREACHED(); | |
440 return; | |
441 } | |
442 | |
443 std::vector<VpnConfiguration*> to_be_destroyed; | 436 std::vector<VpnConfiguration*> to_be_destroyed; |
444 for (const auto& iter : key_to_configuration_map_) { | 437 for (const auto& iter : key_to_configuration_map_) { |
445 if (iter.second->extension_id() == extension->id()) { | 438 if (iter.second->extension_id() == extension->id()) { |
446 to_be_destroyed.push_back(iter.second); | 439 to_be_destroyed.push_back(iter.second); |
447 } | 440 } |
448 } | 441 } |
449 | 442 |
450 for (auto& iter : to_be_destroyed) { | 443 for (auto& iter : to_be_destroyed) { |
451 DestroyConfiguration(extension->id(), // Extension ID | 444 DestroyConfiguration(extension->id(), // Extension ID |
452 iter->configuration_name(), // Configuration name | 445 iter->configuration_name(), // Configuration name |
453 base::Bind(base::DoNothing), | 446 base::Bind(base::DoNothing), |
454 base::Bind(DoNothingFailureCallback)); | 447 base::Bind(DoNothingFailureCallback)); |
455 } | 448 } |
456 } | 449 } |
457 | 450 |
| 451 void VpnService::OnExtensionUninstalled( |
| 452 content::BrowserContext* browser_context, |
| 453 const extensions::Extension* extension, |
| 454 extensions::UninstallReason reason) { |
| 455 if (browser_context != browser_context_) { |
| 456 NOTREACHED(); |
| 457 return; |
| 458 } |
| 459 |
| 460 DestroyConfigurationsForExtension(extension); |
| 461 } |
| 462 |
458 void VpnService::OnExtensionUnloaded( | 463 void VpnService::OnExtensionUnloaded( |
459 content::BrowserContext* browser_context, | 464 content::BrowserContext* browser_context, |
460 const extensions::Extension* extension, | 465 const extensions::Extension* extension, |
461 extensions::UnloadedExtensionInfo::Reason reason) { | 466 extensions::UnloadedExtensionInfo::Reason reason) { |
462 if (browser_context != browser_context_) { | 467 if (browser_context != browser_context_) { |
463 NOTREACHED(); | 468 NOTREACHED(); |
464 return; | 469 return; |
465 } | 470 } |
466 | 471 |
467 if (active_configuration_ && | 472 if (active_configuration_ && |
468 active_configuration_->extension_id() == extension->id()) { | 473 active_configuration_->extension_id() == extension->id()) { |
469 shill_client_->UpdateConnectionState( | 474 shill_client_->UpdateConnectionState( |
470 active_configuration_->object_path(), | 475 active_configuration_->object_path(), |
471 static_cast<uint32_t>(api_vpn::VPN_CONNECTION_STATE_FAILURE), | 476 static_cast<uint32_t>(api_vpn::VPN_CONNECTION_STATE_FAILURE), |
472 base::Bind(base::DoNothing), base::Bind(DoNothingFailureCallback)); | 477 base::Bind(base::DoNothing), base::Bind(DoNothingFailureCallback)); |
473 } | 478 } |
| 479 if (reason == extensions::UnloadedExtensionInfo::REASON_DISABLE || |
| 480 reason == extensions::UnloadedExtensionInfo::REASON_BLACKLIST) { |
| 481 DestroyConfigurationsForExtension(extension); |
| 482 } |
474 } | 483 } |
475 | 484 |
476 void VpnService::OnCreateConfigurationSuccess( | 485 void VpnService::OnCreateConfigurationSuccess( |
477 const VpnService::SuccessCallback& callback, | 486 const VpnService::SuccessCallback& callback, |
478 VpnConfiguration* configuration, | 487 VpnConfiguration* configuration, |
479 const std::string& service_path) { | 488 const std::string& service_path) { |
480 configuration->set_service_path(service_path); | 489 configuration->set_service_path(service_path); |
481 service_path_to_configuration_map_[service_path] = configuration; | 490 service_path_to_configuration_map_[service_path] = configuration; |
482 shill_client_->AddShillThirdPartyVpnObserver(configuration->object_path(), | 491 shill_client_->AddShillThirdPartyVpnObserver(configuration->object_path(), |
483 configuration); | 492 configuration); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 delete configuration; | 552 delete configuration; |
544 } | 553 } |
545 | 554 |
546 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( | 555 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( |
547 const std::string& extension_id) { | 556 const std::string& extension_id) { |
548 return active_configuration_ && | 557 return active_configuration_ && |
549 active_configuration_->extension_id() == extension_id; | 558 active_configuration_->extension_id() == extension_id; |
550 } | 559 } |
551 | 560 |
552 } // namespace chromeos | 561 } // namespace chromeos |
OLD | NEW |