Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1057)

Unified Diff: chrome/browser/ui/webui/chrome_web_ui_factory.cc

Issue 6992019: Allow overriding WebUIFactory when test flag is set. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nit from review. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/chrome_web_ui_factory.cc
diff --git a/chrome/browser/ui/webui/chrome_web_ui_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_factory.cc
index 71931fa327f22e02321d9aedf49a32bbfd5f4943..208e265b20e4519b6c4ff1067d907c0cd66812c7 100644
--- a/chrome/browser/ui/webui/chrome_web_ui_factory.cc
+++ b/chrome/browser/ui/webui/chrome_web_ui_factory.cc
@@ -27,6 +27,7 @@
#include "chrome/browser/ui/webui/plugins_ui.h"
#include "chrome/browser/ui/webui/print_preview_ui.h"
#include "chrome/browser/ui/webui/sync_internals_ui.h"
+#include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h"
#include "chrome/browser/ui/webui/textfields_ui.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
@@ -217,6 +218,20 @@ static WebUIFactoryFunction GetWebUIFactoryFunction(Profile* profile,
return NULL;
}
+// When the test-type switch is set, return a TestType object, which should be a
+// subclass of Type. The logic is provided here in the traits class, rather than
+// in GetInstance() so that the choice is made only once, when the Singleton is
+// first instantiated, rather than every time GetInstance() is called.
+template<typename Type, typename TestType>
+struct PossibleTestSingletonTraits : public DefaultSingletonTraits<Type> {
+ static Type* New() {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType))
+ return DefaultSingletonTraits<TestType>::New();
+ else
+ return DefaultSingletonTraits<Type>::New();
+ }
+};
+
} // namespace
WebUI::TypeID ChromeWebUIFactory::GetWebUIType(Profile* profile,
@@ -286,7 +301,8 @@ void ChromeWebUIFactory::GetFaviconForURL(
// static
ChromeWebUIFactory* ChromeWebUIFactory::GetInstance() {
- return Singleton<ChromeWebUIFactory>::get();
+ return Singleton<ChromeWebUIFactory, PossibleTestSingletonTraits<
+ ChromeWebUIFactory, TestChromeWebUIFactory> >::get();
}
ChromeWebUIFactory::ChromeWebUIFactory() {
« no previous file with comments | « chrome/browser/ui/webui/chrome_web_ui_factory.h ('k') | chrome/browser/ui/webui/test_chrome_web_ui_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698