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

Unified Diff: chrome/browser/ui/webui/test_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: Adjusted comment to describe decision to keep registry add/remove in the 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/test_chrome_web_ui_factory.cc
diff --git a/chrome/browser/ui/webui/test_chrome_web_ui_factory.cc b/chrome/browser/ui/webui/test_chrome_web_ui_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..199e965e71a1dd8fd418951803171e23f6595a3d
--- /dev/null
+++ b/chrome/browser/ui/webui/test_chrome_web_ui_factory.cc
@@ -0,0 +1,55 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h"
+
+#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
Lei Zhang 2011/05/25 21:21:18 nit: You don't need to include this and web_ui.h a
+#include "content/browser/tab_contents/tab_contents.h"
+#include "content/browser/webui/web_ui.h"
+
+TestChromeWebUIFactory::WebUIProvider::~WebUIProvider() {
+}
+
+TestChromeWebUIFactory::TestChromeWebUIFactory() {
+}
+
+TestChromeWebUIFactory::~TestChromeWebUIFactory() {
+}
+
+void TestChromeWebUIFactory::AddFactoryOverride(const std::string& host,
+ WebUIProvider* provider) {
+ DCHECK_EQ(0U, GetInstance()->factory_overrides_.count(host));
+ GetInstance()->factory_overrides_[host] = provider;
+}
+
+void TestChromeWebUIFactory::RemoveFactoryOverride(const std::string& host) {
+ DCHECK_EQ(1U, GetInstance()->factory_overrides_.count(host));
+ GetInstance()->factory_overrides_.erase(host);
+}
+
+WebUI::TypeID TestChromeWebUIFactory::GetWebUIType(
+ Profile* profile, const GURL& url) const {
+ WebUIProvider* provider = GetWebUIProvider(profile, url);
+ return provider ? reinterpret_cast<WebUI::TypeID>(provider) :
+ ChromeWebUIFactory::GetWebUIType(profile, url);
+}
+
+WebUI* TestChromeWebUIFactory::CreateWebUIForURL(TabContents* tab_contents,
+ const GURL& url) const {
+ WebUIProvider* provider = GetWebUIProvider(tab_contents->profile(), url);
+ return provider ? provider->NewWebUI(tab_contents, url) :
+ ChromeWebUIFactory::CreateWebUIForURL(tab_contents, url);
+}
+
+TestChromeWebUIFactory* TestChromeWebUIFactory::GetInstance() {
+ return static_cast<TestChromeWebUIFactory*>(
+ ChromeWebUIFactory::GetInstance());
+}
+
+TestChromeWebUIFactory::WebUIProvider* TestChromeWebUIFactory::GetWebUIProvider(
+ Profile* profile, const GURL& url) const {
+ FactoryOverridesMap::const_iterator found =
+ factory_overrides_.find(url.host());
+ return (found == factory_overrides_.end()) ? NULL : found->second;
+}

Powered by Google App Engine
This is Rietveld 408576698