Commit 183d4b83 authored by rsesek@chromium.org's avatar rsesek@chromium.org

Move PluginPrefs to use PluginService instead of PluginList.

BUG=103788,chromium-os:22447
TEST=unit_tests --gtest_filter=PluginPrefs*

Review URL: http://codereview.chromium.org/8515021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109657 0039d316-1c4b-4281-b951-d872f2087c98
parent bc29eb72
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/at_exit.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "chrome/browser/chrome_plugin_service_filter.h" #include "chrome/browser/chrome_plugin_service_filter.h"
...@@ -115,6 +116,7 @@ class GViewRequestInterceptorTest : public testing::Test { ...@@ -115,6 +116,7 @@ class GViewRequestInterceptorTest : public testing::Test {
handler_ = new content::DummyResourceHandler(); handler_ = new content::DummyResourceHandler();
PluginService::GetInstance()->Init();
PluginService::GetInstance()->RefreshPlugins(); PluginService::GetInstance()->RefreshPlugins();
PluginService::GetInstance()->GetPlugins(base::Bind(&QuitMessageLoop)); PluginService::GetInstance()->GetPlugins(base::Bind(&QuitMessageLoop));
MessageLoop::current()->RunAllPending(); MessageLoop::current()->RunAllPending();
...@@ -200,6 +202,7 @@ class GViewRequestInterceptorTest : public testing::Test { ...@@ -200,6 +202,7 @@ class GViewRequestInterceptorTest : public testing::Test {
} }
protected: protected:
base::ShadowingAtExitManager at_exit_manager_; // Deletes PluginService.
MessageLoopForIO message_loop_; MessageLoopForIO message_loop_;
content::TestBrowserThread ui_thread_; content::TestBrowserThread ui_thread_;
content::TestBrowserThread file_thread_; content::TestBrowserThread file_thread_;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <set> #include <set>
#include <vector> #include <vector>
#include "base/at_exit.h"
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
...@@ -60,6 +61,7 @@ ...@@ -60,6 +61,7 @@
#include "content/browser/file_system/browser_file_system_helper.h" #include "content/browser/file_system/browser_file_system_helper.h"
#include "content/browser/in_process_webkit/dom_storage_context.h" #include "content/browser/in_process_webkit/dom_storage_context.h"
#include "content/browser/in_process_webkit/webkit_context.h" #include "content/browser/in_process_webkit/webkit_context.h"
#include "content/browser/plugin_service.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/test/test_browser_thread.h" #include "content/test/test_browser_thread.h"
...@@ -982,6 +984,9 @@ void PackExtensionTestClient::OnPackFailure(const std::string& error_message) { ...@@ -982,6 +984,9 @@ void PackExtensionTestClient::OnPackFailure(const std::string& error_message) {
// Test loading good extensions from the profile directory. // Test loading good extensions from the profile directory.
TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) {
base::ShadowingAtExitManager at_exit_manager;
PluginService::GetInstance()->Init();
// Initialize the test dir with a good Preferences/extensions. // Initialize the test dir with a good Preferences/extensions.
FilePath source_install_dir = data_dir_ FilePath source_install_dir = data_dir_
.AppendASCII("good") .AppendASCII("good")
...@@ -1119,6 +1124,9 @@ TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) { ...@@ -1119,6 +1124,9 @@ TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) {
// Test that partially deleted extensions are cleaned up during startup // Test that partially deleted extensions are cleaned up during startup
// Test loading bad extensions from the profile directory. // Test loading bad extensions from the profile directory.
TEST_F(ExtensionServiceTest, CleanupOnStartup) { TEST_F(ExtensionServiceTest, CleanupOnStartup) {
base::ShadowingAtExitManager at_exit_manager;
PluginService::GetInstance()->Init();
FilePath source_install_dir = data_dir_ FilePath source_install_dir = data_dir_
.AppendASCII("good") .AppendASCII("good")
.AppendASCII("Extensions"); .AppendASCII("Extensions");
...@@ -1452,6 +1460,9 @@ TEST_F(ExtensionServiceTest, GrantedPermissions) { ...@@ -1452,6 +1460,9 @@ TEST_F(ExtensionServiceTest, GrantedPermissions) {
// an extension contains an NPAPI plugin. Don't run this test on Chrome OS // an extension contains an NPAPI plugin. Don't run this test on Chrome OS
// since they don't support plugins. // since they don't support plugins.
TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) {
base::ShadowingAtExitManager at_exit_manager;
PluginService::GetInstance()->Init();
InitializeEmptyExtensionService(); InitializeEmptyExtensionService();
FilePath path = data_dir_ FilePath path = data_dir_
......
...@@ -73,17 +73,15 @@ void PluginPrefs::SetPluginListForTesting( ...@@ -73,17 +73,15 @@ void PluginPrefs::SetPluginListForTesting(
} }
void PluginPrefs::EnablePluginGroup(bool enabled, const string16& group_name) { void PluginPrefs::EnablePluginGroup(bool enabled, const string16& group_name) {
if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { PluginService::GetInstance()->GetPluginGroups(
BrowserThread::PostTask( base::Bind(&PluginPrefs::EnablePluginGroupInternal,
BrowserThread::FILE, FROM_HERE, this, enabled, group_name));
base::Bind(&PluginPrefs::EnablePluginGroup, this, enabled, group_name)); }
return;
}
webkit::npapi::PluginList* plugin_list = GetPluginList();
std::vector<webkit::npapi::PluginGroup> groups;
plugin_list->GetPluginGroups(true, &groups);
void PluginPrefs::EnablePluginGroupInternal(
bool enabled,
const string16& group_name,
const std::vector<webkit::npapi::PluginGroup>& groups) {
base::AutoLock auto_lock(lock_); base::AutoLock auto_lock(lock_);
// Set the desired state for the group. // Set the desired state for the group.
...@@ -124,27 +122,21 @@ bool PluginPrefs::EnablePlugin(bool enabled, const FilePath& path) { ...@@ -124,27 +122,21 @@ bool PluginPrefs::EnablePlugin(bool enabled, const FilePath& path) {
} }
} }
if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { PluginService::GetInstance()->GetPluginGroups(
EnablePluginInternal(enabled, path); base::Bind(&PluginPrefs::EnablePluginInternal, this, enabled, path));
} else {
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&PluginPrefs::EnablePluginInternal, this, enabled, path));
}
return true; return true;
} }
void PluginPrefs::EnablePluginInternal(bool enabled, const FilePath& path) { void PluginPrefs::EnablePluginInternal(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); bool enabled,
const FilePath& path,
const std::vector<webkit::npapi::PluginGroup>& groups) {
{ {
// Set the desired state for the plug-in. // Set the desired state for the plug-in.
base::AutoLock auto_lock(lock_); base::AutoLock auto_lock(lock_);
plugin_state_[path] = enabled; plugin_state_[path] = enabled;
} }
std::vector<webkit::npapi::PluginGroup> groups;
GetPluginList()->GetPluginGroups(true, &groups);
bool found_group = false; bool found_group = false;
for (size_t i = 0; i < groups.size(); ++i) { for (size_t i = 0; i < groups.size(); ++i) {
bool all_disabled = true; bool all_disabled = true;
......
...@@ -117,8 +117,15 @@ class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>, ...@@ -117,8 +117,15 @@ class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>,
// Returns the plugin list to use, either the singleton or the override. // Returns the plugin list to use, either the singleton or the override.
webkit::npapi::PluginList* GetPluginList(); webkit::npapi::PluginList* GetPluginList();
// Called on the file thread to update the plug-in state. // Callback for after the plugin groups have been loaded.
void EnablePluginInternal(bool enabled, const FilePath& path); void EnablePluginGroupInternal(
bool enabled,
const string16& group_name,
const std::vector<webkit::npapi::PluginGroup>& groups);
void EnablePluginInternal(
bool enabled,
const FilePath& path,
const std::vector<webkit::npapi::PluginGroup>& groups);
// Called on the file thread to get the data necessary to update the saved // Called on the file thread to get the data necessary to update the saved
// preferences. // preferences.
......
...@@ -4,10 +4,14 @@ ...@@ -4,10 +4,14 @@
#include "chrome/browser/plugin_prefs.h" #include "chrome/browser/plugin_prefs.h"
#include "base/at_exit.h"
#include "base/bind.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h" #include "chrome/test/base/testing_profile_manager.h"
#include "content/browser/plugin_service.h"
#include "content/test/test_browser_thread.h" #include "content/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "webkit/plugins/npapi/mock_plugin_list.cc" #include "webkit/plugins/npapi/mock_plugin_list.cc"
...@@ -134,10 +138,16 @@ TEST_F(PluginPrefsTest, EnabledAndDisabledByPolicy) { ...@@ -134,10 +138,16 @@ TEST_F(PluginPrefsTest, EnabledAndDisabledByPolicy) {
} }
TEST_F(PluginPrefsTest, DisableGlobally) { TEST_F(PluginPrefsTest, DisableGlobally) {
base::ShadowingAtExitManager at_exit_manager_; // Destroys the PluginService.
MessageLoop message_loop; MessageLoop message_loop;
content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop);
webkit::npapi::MockPluginList plugin_list(NULL, 0);
PluginService::GetInstance()->SetPluginListForTesting(&plugin_list);
PluginService::GetInstance()->Init();
TestingBrowserProcess* browser_process = TestingBrowserProcess* browser_process =
static_cast<TestingBrowserProcess*>(g_browser_process); static_cast<TestingBrowserProcess*>(g_browser_process);
TestingProfileManager profile_manager(browser_process); TestingProfileManager profile_manager(browser_process);
...@@ -147,16 +157,17 @@ TEST_F(PluginPrefsTest, DisableGlobally) { ...@@ -147,16 +157,17 @@ TEST_F(PluginPrefsTest, DisableGlobally) {
profile_manager.CreateTestingProfile("Profile 1"); profile_manager.CreateTestingProfile("Profile 1");
PluginPrefs* plugin_prefs = PluginPrefs::GetForTestingProfile(profile_1); PluginPrefs* plugin_prefs = PluginPrefs::GetForTestingProfile(profile_1);
ASSERT_TRUE(plugin_prefs); ASSERT_TRUE(plugin_prefs);
plugin_prefs->SetPluginListForTesting(&plugin_list);
webkit::WebPluginInfo plugin(ASCIIToUTF16("Foo"), webkit::WebPluginInfo plugin(ASCIIToUTF16("Foo"),
FilePath(FILE_PATH_LITERAL("/path/too/foo")), FilePath(FILE_PATH_LITERAL("/path/too/foo")),
ASCIIToUTF16("1.0.0"), ASCIIToUTF16("1.0.0"),
ASCIIToUTF16("Foo plug-in")); ASCIIToUTF16("Foo plug-in"));
webkit::npapi::MockPluginList plugin_list(NULL, 0);
plugin_list.AddPluginToLoad(plugin); plugin_list.AddPluginToLoad(plugin);
plugin_prefs->SetPluginListForTesting(&plugin_list);
EXPECT_TRUE(PluginPrefs::EnablePluginGlobally(false, plugin.path)); EXPECT_TRUE(PluginPrefs::EnablePluginGlobally(false, plugin.path));
message_loop.RunAllPending();
EXPECT_FALSE(plugin_prefs->IsPluginEnabled(plugin)); EXPECT_FALSE(plugin_prefs->IsPluginEnabled(plugin));
TestingProfile* profile_2 = TestingProfile* profile_2 =
...@@ -165,4 +176,7 @@ TEST_F(PluginPrefsTest, DisableGlobally) { ...@@ -165,4 +176,7 @@ TEST_F(PluginPrefsTest, DisableGlobally) {
ASSERT_TRUE(plugin_prefs); ASSERT_TRUE(plugin_prefs);
plugin_prefs_2->SetPluginListForTesting(&plugin_list); plugin_prefs_2->SetPluginListForTesting(&plugin_list);
EXPECT_FALSE(plugin_prefs_2->IsPluginEnabled(plugin)); EXPECT_FALSE(plugin_prefs_2->IsPluginEnabled(plugin));
profile_manager.DeleteTestingProfile("Profile 1");
profile_manager.DeleteTestingProfile("Profile 2");
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "content/browser/plugin_loader_posix.h" #include "content/browser/plugin_loader_posix.h"
#include "base/at_exit.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/file_path.h" #include "base/file_path.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
...@@ -72,6 +73,10 @@ class PluginLoaderPosixTest : public testing::Test { ...@@ -72,6 +73,10 @@ class PluginLoaderPosixTest : public testing::Test {
plugin_loader_(new MockPluginLoaderPosix) { plugin_loader_(new MockPluginLoaderPosix) {
} }
virtual void SetUp() OVERRIDE {
PluginService::GetInstance()->Init();
}
MessageLoop* message_loop() { return &message_loop_; } MessageLoop* message_loop() { return &message_loop_; }
MockPluginLoaderPosix* plugin_loader() { return plugin_loader_.get(); } MockPluginLoaderPosix* plugin_loader() { return plugin_loader_.get(); }
...@@ -88,6 +93,8 @@ class PluginLoaderPosixTest : public testing::Test { ...@@ -88,6 +93,8 @@ class PluginLoaderPosixTest : public testing::Test {
webkit::WebPluginInfo plugin3_; webkit::WebPluginInfo plugin3_;
private: private:
base::ShadowingAtExitManager at_exit_manager_; // Destroys PluginService.
MessageLoopForIO message_loop_; MessageLoopForIO message_loop_;
BrowserThreadImpl file_thread_; BrowserThreadImpl file_thread_;
BrowserThreadImpl io_thread_; BrowserThreadImpl io_thread_;
......
...@@ -643,10 +643,6 @@ void PluginService::UnregisterInternalPlugin(const FilePath& path) { ...@@ -643,10 +643,6 @@ void PluginService::UnregisterInternalPlugin(const FilePath& path) {
plugin_list()->UnregisterInternalPlugin(path); plugin_list()->UnregisterInternalPlugin(path);
} }
webkit::npapi::PluginList* PluginService::plugin_list() {
return webkit::npapi::PluginList::Singleton();
}
void PluginService::SetPluginListForTesting( void PluginService::SetPluginListForTesting(
webkit::npapi::PluginList* plugin_list) { webkit::npapi::PluginList* plugin_list) {
plugin_list_ = plugin_list; plugin_list_ = plugin_list;
......
...@@ -189,7 +189,7 @@ class CONTENT_EXPORT PluginService ...@@ -189,7 +189,7 @@ class CONTENT_EXPORT PluginService
string16 GetPluginGroupName(const std::string& plugin_name); string16 GetPluginGroupName(const std::string& plugin_name);
// TODO(dpranke): This should be private. // TODO(dpranke): This should be private.
webkit::npapi::PluginList* plugin_list(); webkit::npapi::PluginList* plugin_list() { return plugin_list_; }
void SetPluginListForTesting(webkit::npapi::PluginList* plugin_list); void SetPluginListForTesting(webkit::npapi::PluginList* plugin_list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment