From 864b558217c75dbdebea9db3568056292d4cd274 Mon Sep 17 00:00:00 2001 From: "satish@chromium.org" Date: Sat, 4 Dec 2010 23:00:10 +0000 Subject: This CL add a GetInstance() method to singleton classes instead of relying on the callers to use Singleton. In some cases I have used the LazyInstance pattern as that was simpler. This is a small step towards making all singleton classes use the Singleton 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 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 --- .../browser/printing/print_dialog_cloud_uitest.cc | 46 ++++++++++++++-------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'chrome/browser') 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::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; }; // 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()->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::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; }; } // namespace @@ -141,7 +153,7 @@ class PrintDialogCloudTest : public InProcessBrowserTest { }; virtual void SetUp() { - Singleton()->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()->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()->set_expected_url(cloud_print_dialog_url); - Singleton()->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()->use_delegate()) - request->set_delegate(Singleton()->delegate()); + if (TestController::GetInstance()->use_delegate()) + request->set_delegate(TestController::GetInstance()->delegate()); if (request && - (request->url() == Singleton()->expected_url())) { - Singleton()->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()->set_use_delegate(true); + TestController::GetInstance()->set_use_delegate(true); ui_test_utils::RunMessageLoop(); - ASSERT_TRUE(Singleton()->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()->result()); + ASSERT_TRUE(TestController::GetInstance()->result()); } #endif -- cgit v1.1