summaryrefslogtreecommitdiffstats
path: root/chrome_frame
diff options
context:
space:
mode:
authorsatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-08 10:43:08 +0000
committersatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-08 10:43:08 +0000
commit687b96058845cdaa59f9d81c468f81222e60bdfd (patch)
tree9c97670a35e5f6abe40f3c4bf50ee7b5a257a0e3 /chrome_frame
parentd22618c155cd40c5740755a5f0bcaab59f13f9a7 (diff)
downloadchromium_src-687b96058845cdaa59f9d81c468f81222e60bdfd.zip
chromium_src-687b96058845cdaa59f9d81c468f81222e60bdfd.tar.gz
chromium_src-687b96058845cdaa59f9d81c468f81222e60bdfd.tar.bz2
Add a new GetInstance() method for singleton classes, take 2.
This is a small step towards making all singleton classes use the Singleton<T> pattern within their code and not expect the callers to know about it. This CL includes all files except those under chrome/browser, chrome/net, chrome/service and third_party/WebKit (these will be done in future CLs). Suggested files to focus for reviewers: - joi@ for files under src/ceee - tommi@ for files under src/chrome_frame - maruel@ for the rest of the files. BUG=65298 TEST=all existing tests should continue to pass. Review URL: http://codereview.chromium.org/5581008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68577 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame')
-rw-r--r--chrome_frame/chrome_tab.cc4
-rw-r--r--chrome_frame/dll_redirector.cc5
-rw-r--r--chrome_frame/dll_redirector.h3
-rw-r--r--chrome_frame/policy_settings.cc4
-rw-r--r--chrome_frame/policy_settings.h18
-rw-r--r--chrome_frame/protocol_sink_wrap.cc5
-rw-r--r--chrome_frame/simple_resource_loader.cc10
-rw-r--r--chrome_frame/simple_resource_loader.h4
-rw-r--r--chrome_frame/test/policy_settings_unittest.cc90
-rw-r--r--chrome_frame/utils.cc9
10 files changed, 86 insertions, 66 deletions
diff --git a/chrome_frame/chrome_tab.cc b/chrome_frame/chrome_tab.cc
index a08f2b3..f3f4bd1 100644
--- a/chrome_frame/chrome_tab.cc
+++ b/chrome_frame/chrome_tab.cc
@@ -212,7 +212,7 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance,
logging::InitLogging(NULL, logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
logging::LOCK_LOG_FILE, logging::DELETE_OLD_LOG_FILE);
- DllRedirector* dll_redirector = Singleton<DllRedirector>::get();
+ DllRedirector* dll_redirector = DllRedirector::GetInstance();
DCHECK(dll_redirector);
if (!dll_redirector->RegisterAsFirstCFModule()) {
@@ -227,7 +227,7 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance,
// Enable ETW logging.
logging::LogEventProvider::Initialize(kChromeFrameProvider);
} else if (reason == DLL_PROCESS_DETACH) {
- DllRedirector* dll_redirector = Singleton<DllRedirector>::get();
+ DllRedirector* dll_redirector = DllRedirector::GetInstance();
DCHECK(dll_redirector);
dll_redirector->UnregisterAsFirstCFModule();
diff --git a/chrome_frame/dll_redirector.cc b/chrome_frame/dll_redirector.cc
index c6fe8cb..97143a7 100644
--- a/chrome_frame/dll_redirector.cc
+++ b/chrome_frame/dll_redirector.cc
@@ -46,6 +46,11 @@ DllRedirector::~DllRedirector() {
UnregisterAsFirstCFModule();
}
+// static
+DllRedirector* DllRedirector::GetInstance() {
+ return Singleton<DllRedirector>::get();
+}
+
bool DllRedirector::BuildSecurityAttributesForLock(
CSecurityAttributes* sec_attr) {
DCHECK(sec_attr);
diff --git a/chrome_frame/dll_redirector.h b/chrome_frame/dll_redirector.h
index be8a89b..1e12629 100644
--- a/chrome_frame/dll_redirector.h
+++ b/chrome_frame/dll_redirector.h
@@ -33,6 +33,9 @@ class Version;
// 3) The module this is compiled into is built with version info.
class DllRedirector {
public:
+ // Returns the singleton instance.
+ static DllRedirector* GetInstance();
+
virtual ~DllRedirector();
// Attempts to register this Chrome Frame version as the first loaded version
diff --git a/chrome_frame/policy_settings.cc b/chrome_frame/policy_settings.cc
index 1a35d67..50e465f 100644
--- a/chrome_frame/policy_settings.cc
+++ b/chrome_frame/policy_settings.cc
@@ -153,3 +153,7 @@ void PolicySettings::RefreshFromRegistry() {
swap(application_locale_, application_locale);
}
+// static
+PolicySettings* PolicySettings::GetInstance() {
+ return Singleton<PolicySettings>::get();
+}
diff --git a/chrome_frame/policy_settings.h b/chrome_frame/policy_settings.h
index 28182bd..72e32d2 100644
--- a/chrome_frame/policy_settings.h
+++ b/chrome_frame/policy_settings.h
@@ -7,6 +7,7 @@
#include <string>
#include <vector>
+#include "base/singleton.h"
#include "base/basictypes.h"
@@ -21,12 +22,7 @@ class PolicySettings {
RENDER_IN_CHROME_FRAME,
};
- PolicySettings() : default_renderer_(RENDERER_NOT_SPECIFIED) {
- RefreshFromRegistry();
- }
-
- ~PolicySettings() {
- }
+ static PolicySettings* GetInstance();
RendererForUrl default_renderer() const {
return default_renderer_;
@@ -50,6 +46,13 @@ class PolicySettings {
static void ReadApplicationLocaleSetting(std::wstring* application_locale);
protected:
+ PolicySettings() : default_renderer_(RENDERER_NOT_SPECIFIED) {
+ RefreshFromRegistry();
+ }
+
+ ~PolicySettings() {
+ }
+
// Protected for now since the class is not thread safe.
void RefreshFromRegistry();
@@ -60,8 +63,9 @@ class PolicySettings {
std::wstring application_locale_;
private:
+ // This ensures no construction is possible outside of the class itself.
+ friend struct DefaultSingletonTraits<PolicySettings>;
DISALLOW_COPY_AND_ASSIGN(PolicySettings);
};
-
#endif // CHROME_FRAME_POLICY_SETTINGS_H_
diff --git a/chrome_frame/protocol_sink_wrap.cc b/chrome_frame/protocol_sink_wrap.cc
index 0ea330f..64d9048 100644
--- a/chrome_frame/protocol_sink_wrap.cc
+++ b/chrome_frame/protocol_sink_wrap.cc
@@ -232,9 +232,8 @@ bool IsAdditionallySupportedContentType(const wchar_t* status_text) {
return true;
}
- Singleton<PolicySettings> policy;
- if (policy->GetRendererForContentType(status_text) ==
- PolicySettings::RENDER_IN_CHROME_FRAME) {
+ if (PolicySettings::GetInstance()->GetRendererForContentType(
+ status_text) == PolicySettings::RENDER_IN_CHROME_FRAME) {
return true;
}
diff --git a/chrome_frame/simple_resource_loader.cc b/chrome_frame/simple_resource_loader.cc
index 89a51d7..324c5ca 100644
--- a/chrome_frame/simple_resource_loader.cc
+++ b/chrome_frame/simple_resource_loader.cc
@@ -88,8 +88,9 @@ SimpleResourceLoader::SimpleResourceLoader()
std::vector<std::wstring> language_tags;
// First, try the locale dictated by policy and its fallback.
- PushBackWithFallbackIfAbsent(Singleton<PolicySettings>()->ApplicationLocale(),
- &language_tags);
+ PushBackWithFallbackIfAbsent(
+ PolicySettings::GetInstance()->ApplicationLocale(),
+ &language_tags);
// Next, try the thread, process, user, system languages.
GetPreferredLanguages(&language_tags);
@@ -115,6 +116,11 @@ SimpleResourceLoader::~SimpleResourceLoader() {
}
// static
+SimpleResourceLoader* SimpleResourceLoader::instance() {
+ return Singleton<SimpleResourceLoader>::get();
+}
+
+// static
void SimpleResourceLoader::GetPreferredLanguages(
std::vector<std::wstring>* language_tags) {
DCHECK(language_tags);
diff --git a/chrome_frame/simple_resource_loader.h b/chrome_frame/simple_resource_loader.h
index c749052..45d03ed 100644
--- a/chrome_frame/simple_resource_loader.h
+++ b/chrome_frame/simple_resource_loader.h
@@ -21,9 +21,7 @@
class SimpleResourceLoader {
public:
- static SimpleResourceLoader* instance() {
- return Singleton<SimpleResourceLoader>::get();
- }
+ static SimpleResourceLoader* instance();
// Returns the language tag for the active language.
static std::wstring GetLanguage();
diff --git a/chrome_frame/test/policy_settings_unittest.cc b/chrome_frame/test/policy_settings_unittest.cc
index 55a0b32..53c4df0 100644
--- a/chrome_frame/test/policy_settings_unittest.cc
+++ b/chrome_frame/test/policy_settings_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/basictypes.h"
+#include "base/at_exit.h"
#include "base/logging.h"
#include "base/scoped_ptr.h"
#include "base/stringprintf.h"
@@ -132,14 +133,34 @@ bool SetChromeApplicationLocale(HKEY policy_root, const wchar_t* locale) {
} // end namespace
-TEST(PolicySettings, RendererForUrl) {
- TempRegKeyOverride::DeleteAllTempKeys();
+class PolicySettingsTest : public testing::Test {
+ protected:
+ void SetUp() {
+ TempRegKeyOverride::DeleteAllTempKeys();
+
+ hklm_pol_.reset(new TempRegKeyOverride(HKEY_LOCAL_MACHINE, L"hklm_pol"));
+ hkcu_pol_.reset(new TempRegKeyOverride(HKEY_CURRENT_USER, L"hkcu_pol"));
+
+ ResetPolicySettings();
+ }
+
+ void TearDown() {
+ hkcu_pol_.reset(NULL);
+ hklm_pol_.reset(NULL);
+ TempRegKeyOverride::DeleteAllTempKeys();
+ }
+
+ void ResetPolicySettings() {
+ at_exit_manager_.ProcessCallbacksNow();
+ }
- scoped_ptr<TempRegKeyOverride> hklm_pol(
- new TempRegKeyOverride(HKEY_LOCAL_MACHINE, L"hklm_pol"));
- scoped_ptr<TempRegKeyOverride> hkcu_pol(
- new TempRegKeyOverride(HKEY_CURRENT_USER, L"hkcu_pol"));
+ // This is used to manage life cycle of PolicySettings singleton.
+ base::ShadowingAtExitManager at_exit_manager_;
+ scoped_ptr<TempRegKeyOverride> hklm_pol_;
+ scoped_ptr<TempRegKeyOverride> hkcu_pol_;
+};
+TEST_F(PolicySettingsTest, RendererForUrl) {
const wchar_t* kTestUrls[] = {
L"http://www.example.com",
L"http://www.pattern.com",
@@ -152,11 +173,10 @@ TEST(PolicySettings, RendererForUrl) {
};
const wchar_t kNoMatchUrl[] = L"http://www.chromium.org";
- scoped_ptr<PolicySettings> settings(new PolicySettings());
EXPECT_EQ(PolicySettings::RENDERER_NOT_SPECIFIED,
- settings->default_renderer());
+ PolicySettings::GetInstance()->default_renderer());
EXPECT_EQ(PolicySettings::RENDERER_NOT_SPECIFIED,
- settings->GetRendererForUrl(kNoMatchUrl));
+ PolicySettings::GetInstance()->GetRendererForUrl(kNoMatchUrl));
HKEY root[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER };
for (int i = 0; i < arraysize(root); ++i) {
@@ -164,44 +184,33 @@ TEST(PolicySettings, RendererForUrl) {
PolicySettings::RENDER_IN_CHROME_FRAME, kTestFilters,
arraysize(kTestFilters)));
- settings.reset(new PolicySettings());
+ ResetPolicySettings();
EXPECT_EQ(PolicySettings::RENDER_IN_CHROME_FRAME,
- settings->GetRendererForUrl(kNoMatchUrl));
+ PolicySettings::GetInstance()->GetRendererForUrl(kNoMatchUrl));
for (int j = 0; j < arraysize(kTestUrls); ++j) {
EXPECT_EQ(PolicySettings::RENDER_IN_HOST,
- settings->GetRendererForUrl(kTestUrls[j]));
+ PolicySettings::GetInstance()->GetRendererForUrl(kTestUrls[j]));
}
EXPECT_TRUE(SetRendererSettings(root[i],
PolicySettings::RENDER_IN_HOST, NULL, 0));
- settings.reset(new PolicySettings());
+ ResetPolicySettings();
EXPECT_EQ(PolicySettings::RENDER_IN_HOST,
- settings->GetRendererForUrl(kNoMatchUrl));
+ PolicySettings::GetInstance()->GetRendererForUrl(kNoMatchUrl));
for (int j = 0; j < arraysize(kTestUrls); ++j) {
EXPECT_EQ(PolicySettings::RENDER_IN_HOST,
- settings->GetRendererForUrl(kTestUrls[j]));
+ PolicySettings::GetInstance()->GetRendererForUrl(kTestUrls[j]));
}
DeleteChromeFramePolicyEntries(root[i]);
}
-
- hkcu_pol.reset(NULL);
- hklm_pol.reset(NULL);
- TempRegKeyOverride::DeleteAllTempKeys();
}
-TEST(PolicySettings, RendererForContentType) {
- TempRegKeyOverride::DeleteAllTempKeys();
-
- scoped_ptr<TempRegKeyOverride> hklm_pol(
- new TempRegKeyOverride(HKEY_LOCAL_MACHINE, L"hklm_pol"));
- scoped_ptr<TempRegKeyOverride> hkcu_pol(
- new TempRegKeyOverride(HKEY_CURRENT_USER, L"hkcu_pol"));
-
- scoped_ptr<PolicySettings> settings(new PolicySettings());
+TEST_F(PolicySettingsTest, RendererForContentType) {
EXPECT_EQ(PolicySettings::RENDERER_NOT_SPECIFIED,
- settings->GetRendererForContentType(L"text/xml"));
+ PolicySettings::GetInstance()->GetRendererForContentType(
+ L"text/xml"));
const wchar_t* kTestPolicyContentTypes[] = {
L"application/xml",
@@ -213,39 +222,32 @@ TEST(PolicySettings, RendererForContentType) {
for (int i = 0; i < arraysize(root); ++i) {
SetCFContentTypes(root[i], kTestPolicyContentTypes,
arraysize(kTestPolicyContentTypes));
- settings.reset(new PolicySettings());
+ ResetPolicySettings();
for (int type = 0; type < arraysize(kTestPolicyContentTypes); ++type) {
EXPECT_EQ(PolicySettings::RENDER_IN_CHROME_FRAME,
- settings->GetRendererForContentType(
+ PolicySettings::GetInstance()->GetRendererForContentType(
kTestPolicyContentTypes[type]));
}
EXPECT_EQ(PolicySettings::RENDERER_NOT_SPECIFIED,
- settings->GetRendererForContentType(L"text/html"));
+ PolicySettings::GetInstance()->GetRendererForContentType(
+ L"text/html"));
DeleteChromeFramePolicyEntries(root[i]);
}
}
-TEST(PolicySettings, ApplicationLocale) {
- TempRegKeyOverride::DeleteAllTempKeys();
-
- scoped_ptr<TempRegKeyOverride> hklm_pol(
- new TempRegKeyOverride(HKEY_LOCAL_MACHINE, L"hklm_pol"));
- scoped_ptr<TempRegKeyOverride> hkcu_pol(
- new TempRegKeyOverride(HKEY_CURRENT_USER, L"hkcu_pol"));
-
- scoped_ptr<PolicySettings> settings(new PolicySettings());
- EXPECT_TRUE(settings->ApplicationLocale().empty());
+TEST_F(PolicySettingsTest, ApplicationLocale) {
+ EXPECT_TRUE(PolicySettings::GetInstance()->ApplicationLocale().empty());
static const wchar_t kTestApplicationLocale[] = L"fr-CA";
HKEY root[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER };
for (int i = 0; i < arraysize(root); ++i) {
SetChromeApplicationLocale(root[i], kTestApplicationLocale);
- settings.reset(new PolicySettings());
+ ResetPolicySettings();
EXPECT_EQ(std::wstring(kTestApplicationLocale),
- settings->ApplicationLocale());
+ PolicySettings::GetInstance()->ApplicationLocale());
DeleteChromeFramePolicyEntries(root[i]);
}
diff --git a/chrome_frame/utils.cc b/chrome_frame/utils.cc
index e4279a7..781d6d4 100644
--- a/chrome_frame/utils.cc
+++ b/chrome_frame/utils.cc
@@ -723,8 +723,8 @@ bool IsGcfDefaultRenderer() {
DWORD is_default = 0; // NOLINT
// First check policy settings
- Singleton<PolicySettings> policy;
- PolicySettings::RendererForUrl renderer = policy->default_renderer();
+ PolicySettings::RendererForUrl renderer =
+ PolicySettings::GetInstance()->default_renderer();
if (renderer != PolicySettings::RENDERER_NOT_SPECIFIED) {
is_default = (renderer == PolicySettings::RENDER_IN_CHROME_FRAME);
} else {
@@ -742,9 +742,8 @@ bool IsGcfDefaultRenderer() {
RendererType RendererTypeForUrl(const std::wstring& url) {
// First check if the default renderer settings are specified by policy.
// If so, then that overrides the user settings.
- Singleton<PolicySettings> policy;
- PolicySettings::RendererForUrl renderer = policy->GetRendererForUrl(
- url.c_str());
+ PolicySettings::RendererForUrl renderer =
+ PolicySettings::GetInstance()->GetRendererForUrl(url.c_str());
if (renderer != PolicySettings::RENDERER_NOT_SPECIFIED) {
// We may know at this point that policy says do NOT render in Chrome Frame.
// To maintain consistency, we return RENDERER_TYPE_UNDETERMINED so that