summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-11 18:50:26 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-11 18:50:26 +0000
commit183d4b83abbb1a3f0128a03a6450695626d043a3 (patch)
tree00b0104642cf5c39e8398d42dee55b0c2c5c9fb2 /chrome/browser
parentbc29eb72f36c87c85388aa9d1cc978552be1d2cc (diff)
downloadchromium_src-183d4b83abbb1a3f0128a03a6450695626d043a3.zip
chromium_src-183d4b83abbb1a3f0128a03a6450695626d043a3.tar.gz
chromium_src-183d4b83abbb1a3f0128a03a6450695626d043a3.tar.bz2
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
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/chromeos/gview_request_interceptor_unittest.cc3
-rw-r--r--chrome/browser/extensions/extension_service_unittest.cc11
-rw-r--r--chrome/browser/plugin_prefs.cc36
-rw-r--r--chrome/browser/plugin_prefs.h11
-rw-r--r--chrome/browser/plugin_prefs_unittest.cc18
5 files changed, 53 insertions, 26 deletions
diff --git a/chrome/browser/chromeos/gview_request_interceptor_unittest.cc b/chrome/browser/chromeos/gview_request_interceptor_unittest.cc
index 9c5aed1..ea119a9 100644
--- a/chrome/browser/chromeos/gview_request_interceptor_unittest.cc
+++ b/chrome/browser/chromeos/gview_request_interceptor_unittest.cc
@@ -5,6 +5,7 @@
#include <string>
#include <vector>
+#include "base/at_exit.h"
#include "base/bind.h"
#include "base/message_loop.h"
#include "chrome/browser/chrome_plugin_service_filter.h"
@@ -115,6 +116,7 @@ class GViewRequestInterceptorTest : public testing::Test {
handler_ = new content::DummyResourceHandler();
+ PluginService::GetInstance()->Init();
PluginService::GetInstance()->RefreshPlugins();
PluginService::GetInstance()->GetPlugins(base::Bind(&QuitMessageLoop));
MessageLoop::current()->RunAllPending();
@@ -200,6 +202,7 @@ class GViewRequestInterceptorTest : public testing::Test {
}
protected:
+ base::ShadowingAtExitManager at_exit_manager_; // Deletes PluginService.
MessageLoopForIO message_loop_;
content::TestBrowserThread ui_thread_;
content::TestBrowserThread file_thread_;
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index 914271b..17160bf 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -8,6 +8,7 @@
#include <set>
#include <vector>
+#include "base/at_exit.h"
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/command_line.h"
@@ -60,6 +61,7 @@
#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/webkit_context.h"
+#include "content/browser/plugin_service.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "content/test/test_browser_thread.h"
@@ -982,6 +984,9 @@ void PackExtensionTestClient::OnPackFailure(const std::string& error_message) {
// Test loading good extensions from the profile directory.
TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) {
+ base::ShadowingAtExitManager at_exit_manager;
+ PluginService::GetInstance()->Init();
+
// Initialize the test dir with a good Preferences/extensions.
FilePath source_install_dir = data_dir_
.AppendASCII("good")
@@ -1119,6 +1124,9 @@ TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectoryFail) {
// Test that partially deleted extensions are cleaned up during startup
// Test loading bad extensions from the profile directory.
TEST_F(ExtensionServiceTest, CleanupOnStartup) {
+ base::ShadowingAtExitManager at_exit_manager;
+ PluginService::GetInstance()->Init();
+
FilePath source_install_dir = data_dir_
.AppendASCII("good")
.AppendASCII("Extensions");
@@ -1452,6 +1460,9 @@ TEST_F(ExtensionServiceTest, GrantedPermissions) {
// an extension contains an NPAPI plugin. Don't run this test on Chrome OS
// since they don't support plugins.
TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) {
+ base::ShadowingAtExitManager at_exit_manager;
+ PluginService::GetInstance()->Init();
+
InitializeEmptyExtensionService();
FilePath path = data_dir_
diff --git a/chrome/browser/plugin_prefs.cc b/chrome/browser/plugin_prefs.cc
index 94ecb6e..f4923f1 100644
--- a/chrome/browser/plugin_prefs.cc
+++ b/chrome/browser/plugin_prefs.cc
@@ -73,17 +73,15 @@ void PluginPrefs::SetPluginListForTesting(
}
void PluginPrefs::EnablePluginGroup(bool enabled, const string16& group_name) {
- if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) {
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- 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);
+ PluginService::GetInstance()->GetPluginGroups(
+ base::Bind(&PluginPrefs::EnablePluginGroupInternal,
+ this, enabled, group_name));
+}
+void PluginPrefs::EnablePluginGroupInternal(
+ bool enabled,
+ const string16& group_name,
+ const std::vector<webkit::npapi::PluginGroup>& groups) {
base::AutoLock auto_lock(lock_);
// Set the desired state for the group.
@@ -124,27 +122,21 @@ bool PluginPrefs::EnablePlugin(bool enabled, const FilePath& path) {
}
}
- if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) {
- EnablePluginInternal(enabled, path);
- } else {
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- base::Bind(&PluginPrefs::EnablePluginInternal, this, enabled, path));
- }
+ PluginService::GetInstance()->GetPluginGroups(
+ base::Bind(&PluginPrefs::EnablePluginInternal, this, enabled, path));
return true;
}
-void PluginPrefs::EnablePluginInternal(bool enabled, const FilePath& path) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+void PluginPrefs::EnablePluginInternal(
+ bool enabled,
+ const FilePath& path,
+ const std::vector<webkit::npapi::PluginGroup>& groups) {
{
// Set the desired state for the plug-in.
base::AutoLock auto_lock(lock_);
plugin_state_[path] = enabled;
}
- std::vector<webkit::npapi::PluginGroup> groups;
- GetPluginList()->GetPluginGroups(true, &groups);
-
bool found_group = false;
for (size_t i = 0; i < groups.size(); ++i) {
bool all_disabled = true;
diff --git a/chrome/browser/plugin_prefs.h b/chrome/browser/plugin_prefs.h
index e6afa45..3792dfd 100644
--- a/chrome/browser/plugin_prefs.h
+++ b/chrome/browser/plugin_prefs.h
@@ -117,8 +117,15 @@ class PluginPrefs : public base::RefCountedThreadSafe<PluginPrefs>,
// Returns the plugin list to use, either the singleton or the override.
webkit::npapi::PluginList* GetPluginList();
- // Called on the file thread to update the plug-in state.
- void EnablePluginInternal(bool enabled, const FilePath& path);
+ // Callback for after the plugin groups have been loaded.
+ 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
// preferences.
diff --git a/chrome/browser/plugin_prefs_unittest.cc b/chrome/browser/plugin_prefs_unittest.cc
index 20acd5e..e045a16 100644
--- a/chrome/browser/plugin_prefs_unittest.cc
+++ b/chrome/browser/plugin_prefs_unittest.cc
@@ -4,10 +4,14 @@
#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 "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
+#include "content/browser/plugin_service.h"
#include "content/test/test_browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/plugins/npapi/mock_plugin_list.cc"
@@ -134,10 +138,16 @@ TEST_F(PluginPrefsTest, EnabledAndDisabledByPolicy) {
}
TEST_F(PluginPrefsTest, DisableGlobally) {
+ base::ShadowingAtExitManager at_exit_manager_; // Destroys the PluginService.
+
MessageLoop message_loop;
content::TestBrowserThread ui_thread(BrowserThread::UI, &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 =
static_cast<TestingBrowserProcess*>(g_browser_process);
TestingProfileManager profile_manager(browser_process);
@@ -147,16 +157,17 @@ TEST_F(PluginPrefsTest, DisableGlobally) {
profile_manager.CreateTestingProfile("Profile 1");
PluginPrefs* plugin_prefs = PluginPrefs::GetForTestingProfile(profile_1);
ASSERT_TRUE(plugin_prefs);
+ plugin_prefs->SetPluginListForTesting(&plugin_list);
webkit::WebPluginInfo plugin(ASCIIToUTF16("Foo"),
FilePath(FILE_PATH_LITERAL("/path/too/foo")),
ASCIIToUTF16("1.0.0"),
ASCIIToUTF16("Foo plug-in"));
- webkit::npapi::MockPluginList plugin_list(NULL, 0);
plugin_list.AddPluginToLoad(plugin);
- plugin_prefs->SetPluginListForTesting(&plugin_list);
EXPECT_TRUE(PluginPrefs::EnablePluginGlobally(false, plugin.path));
+ message_loop.RunAllPending();
+
EXPECT_FALSE(plugin_prefs->IsPluginEnabled(plugin));
TestingProfile* profile_2 =
@@ -165,4 +176,7 @@ TEST_F(PluginPrefsTest, DisableGlobally) {
ASSERT_TRUE(plugin_prefs);
plugin_prefs_2->SetPluginListForTesting(&plugin_list);
EXPECT_FALSE(plugin_prefs_2->IsPluginEnabled(plugin));
+
+ profile_manager.DeleteTestingProfile("Profile 1");
+ profile_manager.DeleteTestingProfile("Profile 2");
}