OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/json/json_value_serializer.h" | |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
17 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
19 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
20 #include "base/string16.h" | 21 #include "base/string16.h" |
21 #include "base/string_number_conversions.h" | 22 #include "base/string_number_conversions.h" |
22 #include "base/string_util.h" | 23 #include "base/string_util.h" |
23 #include "base/stringprintf.h" | 24 #include "base/stringprintf.h" |
24 #include "base/threading/thread_restrictions.h" | 25 #include "base/threading/thread_restrictions.h" |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
681 | 682 |
682 if (out_crx_installer) | 683 if (out_crx_installer) |
683 *out_crx_installer = installer; | 684 *out_crx_installer = installer; |
684 | 685 |
685 return true; | 686 return true; |
686 } | 687 } |
687 | 688 |
688 void ExtensionService::ReloadExtension(const std::string& extension_id) { | 689 void ExtensionService::ReloadExtension(const std::string& extension_id) { |
689 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 690 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
690 FilePath path; | 691 FilePath path; |
691 const Extension* current_extension = GetExtensionById(extension_id, false); | 692 const Extension* current_extension = GetExtensionByIdInternal(extension_id, |
693 true, | |
694 true, | |
Yoyo Zhou
2012/02/09 22:18:03
I don't think we should we be including disabled e
rkc
2012/02/10 00:35:42
Done.
| |
695 true); | |
696 | |
697 // We have no knowledge of this extension ever having even existed, | |
698 // we can't 'reload' it. | |
699 if (!current_extension) | |
700 return; | |
692 | 701 |
693 // Disable the extension if it's loaded. It might not be loaded if it crashed. | 702 // Disable the extension if it's loaded. It might not be loaded if it crashed. |
694 if (current_extension) { | 703 if (IsExtensionEnabled(extension_id)) { |
Yoyo Zhou
2012/02/09 22:18:03
Likewise, this is probably incorrect -- we only wa
rkc
2012/02/10 00:35:42
Done.
| |
695 // If the extension has an inspector open for its background page, detach | 704 // If the extension has an inspector open for its background page, detach |
696 // the inspector and hang onto a cookie for it, so that we can reattach | 705 // the inspector and hang onto a cookie for it, so that we can reattach |
697 // later. | 706 // later. |
698 ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); | 707 ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); |
699 ExtensionHost* host = manager->GetBackgroundHostForExtension(extension_id); | 708 ExtensionHost* host = manager->GetBackgroundHostForExtension(extension_id); |
700 if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost( | 709 if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost( |
701 host->render_view_host())) { | 710 host->render_view_host())) { |
702 // Look for an open inspector for the background page. | 711 // Look for an open inspector for the background page. |
703 DevToolsAgentHost* agent = | 712 DevToolsAgentHost* agent = |
704 DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 713 DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
705 host->render_view_host()); | 714 host->render_view_host()); |
706 int devtools_cookie = | 715 int devtools_cookie = |
707 content::DevToolsManager::GetInstance()->DetachClientHost(agent); | 716 content::DevToolsManager::GetInstance()->DetachClientHost(agent); |
708 if (devtools_cookie >= 0) | 717 if (devtools_cookie >= 0) |
709 orphaned_dev_tools_[extension_id] = devtools_cookie; | 718 orphaned_dev_tools_[extension_id] = devtools_cookie; |
710 } | 719 } |
711 | 720 |
712 path = current_extension->path(); | 721 path = current_extension->path(); |
713 DisableExtension(extension_id); | 722 DisableExtension(extension_id); |
714 disabled_extension_paths_[extension_id] = path; | 723 disabled_extension_paths_[extension_id] = path; |
715 } else { | 724 } else { |
716 path = unloaded_extension_paths_[extension_id]; | 725 path = unloaded_extension_paths_[extension_id]; |
717 } | 726 } |
718 | 727 |
728 // If we're reloading a component extension, use the component extension | |
729 // loader's reloader. | |
730 if (current_extension->location() == Extension::COMPONENT) { | |
Yoyo Zhou
2012/02/09 22:18:03
You could use ComponentLoader::Exists(extension_id
rkc
2012/02/10 00:35:42
Done.
| |
731 component_loader_->Reload(extension_id); | |
732 return; | |
733 } | |
734 | |
719 // Check the installed extensions to see if what we're reloading was already | 735 // Check the installed extensions to see if what we're reloading was already |
720 // installed. | 736 // installed. |
721 scoped_ptr<ExtensionInfo> installed_extension( | 737 scoped_ptr<ExtensionInfo> installed_extension( |
722 extension_prefs_->GetInstalledExtensionInfo(extension_id)); | 738 extension_prefs_->GetInstalledExtensionInfo(extension_id)); |
723 if (installed_extension.get() && | 739 if (installed_extension.get() && |
724 installed_extension->extension_manifest.get()) { | 740 installed_extension->extension_manifest.get()) { |
725 extensions::InstalledLoader(this).Load(*installed_extension, false); | 741 extensions::InstalledLoader(this).Load(*installed_extension, false); |
726 } else { | 742 } else { |
727 // Otherwise, the extension is unpacked (location LOAD). | 743 // Otherwise, the extension is unpacked (location LOAD). |
728 // We should always be able to remember the extension's path. If it's not in | 744 // We should always be able to remember the extension's path. If it's not in |
(...skipping 1963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2692 // | 2708 // |
2693 // To coexist with certain unit tests that don't have an IO thread message | 2709 // To coexist with certain unit tests that don't have an IO thread message |
2694 // loop available at ExtensionService shutdown, we lazy-initialize this | 2710 // loop available at ExtensionService shutdown, we lazy-initialize this |
2695 // object so that those cases neither create nor destroy a SocketController. | 2711 // object so that those cases neither create nor destroy a SocketController. |
2696 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2712 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2697 if (!socket_controller_) { | 2713 if (!socket_controller_) { |
2698 socket_controller_ = new extensions::SocketController(); | 2714 socket_controller_ = new extensions::SocketController(); |
2699 } | 2715 } |
2700 return socket_controller_; | 2716 return socket_controller_; |
2701 } | 2717 } |
OLD | NEW |