diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-04 23:00:10 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-04 23:00:10 +0000 |
commit | 864b558217c75dbdebea9db3568056292d4cd274 (patch) | |
tree | 06bd9f240065ed47fab9ff415ae4cd49f21facf1 /chrome/browser/printing | |
parent | 8c9e61a02aad4d8baa0f75ae7ac2f2f1963fffd6 (diff) | |
download | chromium_src-864b558217c75dbdebea9db3568056292d4cd274.zip chromium_src-864b558217c75dbdebea9db3568056292d4cd274.tar.gz chromium_src-864b558217c75dbdebea9db3568056292d4cd274.tar.bz2 |
This CL add a GetInstance() method to singleton classes instead of relying on the callers to use Singleton<T>.
In some cases I have used the LazyInstance<T> pattern as that was simpler.
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.
I have selected all files under src/app and src/base which use Singleton<T> in this CL. Once this CL goes in I'll work on the rest of the files.
BUG=65298
TEST=all existing tests should continue to pass.
Review URL: http://codereview.chromium.org/5527004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68300 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/printing')
-rw-r--r-- | chrome/browser/printing/print_dialog_cloud_uitest.cc | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/chrome/browser/printing/print_dialog_cloud_uitest.cc b/chrome/browser/printing/print_dialog_cloud_uitest.cc index e13c792..e4c8804 100644 --- a/chrome/browser/printing/print_dialog_cloud_uitest.cc +++ b/chrome/browser/printing/print_dialog_cloud_uitest.cc @@ -31,7 +31,9 @@ namespace { class TestData { public: - TestData() {} + static TestData* GetInstance() { + return Singleton<TestData>::get(); + } const char* GetTestData() { // Fetching this data blocks the IO thread, but we don't really care because @@ -48,7 +50,11 @@ class TestData { return test_data_.c_str(); } private: + TestData() {} + std::string test_data_; + + friend struct DefaultSingletonTraits<TestData>; }; // A simple test URLRequestJob. We don't care what it does, only that @@ -57,7 +63,7 @@ class SimpleTestJob : public URLRequestTestJob { public: explicit SimpleTestJob(net::URLRequest* request) : URLRequestTestJob(request, test_headers(), - Singleton<TestData>()->GetTestData(), true) {} + TestData::GetInstance()->GetTestData(), true) {} virtual void GetResponseInfo(net::HttpResponseInfo* info) { URLRequestTestJob::GetResponseInfo(info); @@ -84,10 +90,9 @@ class SimpleTestJob : public URLRequestTestJob { class TestController { public: - TestController() - : result_(false), - use_delegate_(false), - delegate_(NULL) {} + static TestController* GetInstance() { + return Singleton<TestController>::get(); + } void set_result(bool value) { result_ = value; } @@ -113,10 +118,17 @@ class TestController { return use_delegate_; } private: + TestController() + : result_(false), + use_delegate_(false), + delegate_(NULL) {} + bool result_; bool use_delegate_; GURL expected_url_; TestDelegate* delegate_; + + friend struct DefaultSingletonTraits<TestController>; }; } // namespace @@ -141,7 +153,7 @@ class PrintDialogCloudTest : public InProcessBrowserTest { }; virtual void SetUp() { - Singleton<TestController>()->set_result(false); + TestController::GetInstance()->set_result(false); InProcessBrowserTest::SetUp(); } @@ -150,7 +162,7 @@ class PrintDialogCloudTest : public InProcessBrowserTest { URLRequestFilter* filter = URLRequestFilter::GetInstance(); filter->RemoveHostnameHandler(scheme_, host_name_); handler_added_ = false; - Singleton<TestController>()->set_delegate(NULL); + TestController::GetInstance()->set_delegate(NULL); } InProcessBrowserTest::TearDown(); } @@ -174,8 +186,8 @@ class PrintDialogCloudTest : public InProcessBrowserTest { GURL cloud_print_dialog_url = CloudPrintURL(browser()->profile()). GetCloudPrintServiceDialogURL(); - Singleton<TestController>()->set_expected_url(cloud_print_dialog_url); - Singleton<TestController>()->set_delegate(&delegate_); + TestController::GetInstance()->set_expected_url(cloud_print_dialog_url); + TestController::GetInstance()->set_delegate(&delegate_); } CreateDialogForTest(); @@ -198,11 +210,11 @@ class PrintDialogCloudTest : public InProcessBrowserTest { URLRequestJob* PrintDialogCloudTest::Factory(net::URLRequest* request, const std::string& scheme) { - if (Singleton<TestController>()->use_delegate()) - request->set_delegate(Singleton<TestController>()->delegate()); + if (TestController::GetInstance()->use_delegate()) + request->set_delegate(TestController::GetInstance()->delegate()); if (request && - (request->url() == Singleton<TestController>()->expected_url())) { - Singleton<TestController>()->set_result(true); + (request->url() == TestController::GetInstance()->expected_url())) { + TestController::GetInstance()->set_result(true); } return new SimpleTestJob(request); } @@ -213,11 +225,11 @@ IN_PROC_BROWSER_TEST_F(PrintDialogCloudTest, HandlersRegistered) { AddTestHandlers(); - Singleton<TestController>()->set_use_delegate(true); + TestController::GetInstance()->set_use_delegate(true); ui_test_utils::RunMessageLoop(); - ASSERT_TRUE(Singleton<TestController>()->result()); + ASSERT_TRUE(TestController::GetInstance()->result()); } #if defined(OS_CHROMEOS) @@ -240,6 +252,6 @@ IN_PROC_BROWSER_TEST_F(PrintDialogCloudTest, DISABLED_DialogGrabbed) { ui_test_utils::RunMessageLoop(); - ASSERT_TRUE(Singleton<TestController>()->result()); + ASSERT_TRUE(TestController::GetInstance()->result()); } #endif |