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

Side by Side Diff: chrome/test/base/test_chrome_web_ui_controller_factory.cc

Issue 12084029: Simplify how TestChromeWebUIControllerFactory is registered now that multiple WebUIControllerFactor… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync to head Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/test_chrome_web_ui_controller_factory.h" 5 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "content/public/browser/web_contents.h" 8 #include "content/public/browser/web_contents.h"
9 9
10 using content::WebContents; 10 using content::WebContents;
11 using content::WebUI; 11 using content::WebUI;
12 using content::WebUIController; 12 using content::WebUIController;
13 13
14 TestChromeWebUIControllerFactory::WebUIProvider::~WebUIProvider() { 14 TestChromeWebUIControllerFactory::WebUIProvider::~WebUIProvider() {
15 } 15 }
16 16
17 TestChromeWebUIControllerFactory::TestChromeWebUIControllerFactory() { 17 TestChromeWebUIControllerFactory::TestChromeWebUIControllerFactory() {
18 } 18 }
19 19
20 TestChromeWebUIControllerFactory::~TestChromeWebUIControllerFactory() { 20 TestChromeWebUIControllerFactory::~TestChromeWebUIControllerFactory() {
21 } 21 }
22 22
23 void TestChromeWebUIControllerFactory::AddFactoryOverride( 23 void TestChromeWebUIControllerFactory::AddFactoryOverride(
24 const std::string& host, WebUIProvider* provider) { 24 const std::string& host, WebUIProvider* provider) {
25 DCHECK_EQ(0U, GetInstance()->factory_overrides_.count(host)); 25 DCHECK_EQ(0U, factory_overrides_.count(host));
26 GetInstance()->factory_overrides_[host] = provider; 26 factory_overrides_[host] = provider;
27 } 27 }
28 28
29 void TestChromeWebUIControllerFactory::RemoveFactoryOverride( 29 void TestChromeWebUIControllerFactory::RemoveFactoryOverride(
30 const std::string& host) { 30 const std::string& host) {
31 DCHECK_EQ(1U, GetInstance()->factory_overrides_.count(host)); 31 DCHECK_EQ(1U, factory_overrides_.count(host));
32 GetInstance()->factory_overrides_.erase(host); 32 factory_overrides_.erase(host);
33 } 33 }
34 34
35 WebUI::TypeID TestChromeWebUIControllerFactory::GetWebUIType( 35 WebUI::TypeID TestChromeWebUIControllerFactory::GetWebUIType(
36 content::BrowserContext* browser_context, const GURL& url) const { 36 content::BrowserContext* browser_context, const GURL& url) const {
37 Profile* profile = Profile::FromBrowserContext(browser_context); 37 Profile* profile = Profile::FromBrowserContext(browser_context);
38 WebUIProvider* provider = GetWebUIProvider(profile, url); 38 WebUIProvider* provider = GetWebUIProvider(profile, url);
39 return provider ? reinterpret_cast<WebUI::TypeID>(provider) : 39 return provider ? reinterpret_cast<WebUI::TypeID>(provider) :
40 ChromeWebUIControllerFactory::GetWebUIType(profile, url); 40 ChromeWebUIControllerFactory::GetWebUIType(profile, url);
41 } 41 }
42 42
43 WebUIController* TestChromeWebUIControllerFactory::CreateWebUIControllerForURL( 43 WebUIController* TestChromeWebUIControllerFactory::CreateWebUIControllerForURL(
44 content::WebUI* web_ui, const GURL& url) const { 44 content::WebUI* web_ui, const GURL& url) const {
45 Profile* profile = Profile::FromWebUI(web_ui); 45 Profile* profile = Profile::FromWebUI(web_ui);
46 WebUIProvider* provider = GetWebUIProvider(profile, url); 46 WebUIProvider* provider = GetWebUIProvider(profile, url);
47 return provider ? provider->NewWebUI(web_ui, url) : 47 return provider ? provider->NewWebUI(web_ui, url) :
48 ChromeWebUIControllerFactory::CreateWebUIControllerForURL(web_ui, url); 48 ChromeWebUIControllerFactory::CreateWebUIControllerForURL(web_ui, url);
49 } 49 }
50 50
51 TestChromeWebUIControllerFactory*
52 TestChromeWebUIControllerFactory::GetInstance() {
53 return static_cast<TestChromeWebUIControllerFactory*>(
54 ChromeWebUIControllerFactory::GetInstance());
55 }
56
57 TestChromeWebUIControllerFactory::WebUIProvider* 51 TestChromeWebUIControllerFactory::WebUIProvider*
58 TestChromeWebUIControllerFactory::GetWebUIProvider( 52 TestChromeWebUIControllerFactory::GetWebUIProvider(
59 Profile* profile, const GURL& url) const { 53 Profile* profile, const GURL& url) const {
60 FactoryOverridesMap::const_iterator found = 54 FactoryOverridesMap::const_iterator found =
61 factory_overrides_.find(url.host()); 55 factory_overrides_.find(url.host());
62 return (found == factory_overrides_.end()) ? NULL : found->second; 56 return (found == factory_overrides_.end()) ? NULL : found->second;
63 } 57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698