diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-08 10:43:08 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-08 10:43:08 +0000 |
commit | 687b96058845cdaa59f9d81c468f81222e60bdfd (patch) | |
tree | 9c97670a35e5f6abe40f3c4bf50ee7b5a257a0e3 /ceee/ie/broker | |
parent | d22618c155cd40c5740755a5f0bcaab59f13f9a7 (diff) | |
download | chromium_src-687b96058845cdaa59f9d81c468f81222e60bdfd.zip chromium_src-687b96058845cdaa59f9d81c468f81222e60bdfd.tar.gz chromium_src-687b96058845cdaa59f9d81c468f81222e60bdfd.tar.bz2 |
Add a new GetInstance() method for singleton classes, take 2.
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.
This CL includes all files except those under chrome/browser, chrome/net, chrome/service and third_party/WebKit (these will be done in future CLs).
Suggested files to focus for reviewers:
- joi@ for files under src/ceee
- tommi@ for files under src/chrome_frame
- maruel@ for the rest of the files.
BUG=65298
TEST=all existing tests should continue to pass.
Review URL: http://codereview.chromium.org/5581008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68577 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ceee/ie/broker')
-rw-r--r-- | ceee/ie/broker/api_dispatcher.cc | 33 | ||||
-rw-r--r-- | ceee/ie/broker/api_dispatcher.h | 6 | ||||
-rw-r--r-- | ceee/ie/broker/broker.cc | 5 | ||||
-rw-r--r-- | ceee/ie/broker/broker_module.cc | 3 | ||||
-rw-r--r-- | ceee/ie/broker/chrome_postman.cc | 10 | ||||
-rw-r--r-- | ceee/ie/broker/executors_manager.cc | 5 | ||||
-rw-r--r-- | ceee/ie/broker/executors_manager.h | 5 | ||||
-rw-r--r-- | ceee/ie/broker/tab_api_module.cc | 7 |
8 files changed, 40 insertions, 34 deletions
diff --git a/ceee/ie/broker/api_dispatcher.cc b/ceee/ie/broker/api_dispatcher.cc index 6590379..b0917a2 100644 --- a/ceee/ie/broker/api_dispatcher.cc +++ b/ceee/ie/broker/api_dispatcher.cc @@ -142,26 +142,23 @@ void ApiDispatcher::FireEvent(const char* event_name, const char* event_args) { void ApiDispatcher::GetExecutor(HWND window, REFIID iid, void** executor) { DWORD thread_id = ::GetWindowThreadProcessId(window, NULL); - HRESULT hr = Singleton<ExecutorsManager, - ExecutorsManager::SingletonTraits>::get()-> - GetExecutor(thread_id, window, iid, executor); + HRESULT hr = ExecutorsManager::GetInstance()->GetExecutor(thread_id, window, + iid, executor); DLOG_IF(INFO, FAILED(hr)) << "Failed to get executor for window: " << window << ". In thread: " << thread_id << ". " << com::LogHr(hr); } bool ApiDispatcher::IsTabIdValid(int tab_id) const { - return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> - IsTabIdValid(tab_id); + return ExecutorsManager::GetInstance()->IsTabIdValid(tab_id); } HWND ApiDispatcher::GetTabHandleFromId(int tab_id) const { - return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> - GetTabHandleFromId(tab_id); + return ExecutorsManager::GetInstance()->GetTabHandleFromId(tab_id); } HWND ApiDispatcher::GetTabHandleFromToolBandId(int tool_band_id) const { - return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> - GetTabHandleFromToolBandId(tool_band_id); + return ExecutorsManager::GetInstance()->GetTabHandleFromToolBandId( + tool_band_id); } HWND ApiDispatcher::GetWindowHandleFromId(int window_id) const { @@ -169,13 +166,11 @@ HWND ApiDispatcher::GetWindowHandleFromId(int window_id) const { } bool ApiDispatcher::IsTabHandleValid(HWND tab_handle) const { - return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> - IsTabHandleValid(tab_handle); + return ExecutorsManager::GetInstance()->IsTabHandleValid(tab_handle); } int ApiDispatcher::GetTabIdFromHandle(HWND tab_handle) const { - return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> - GetTabIdFromHandle(tab_handle); + return ExecutorsManager::GetInstance()->GetTabIdFromHandle(tab_handle); } int ApiDispatcher::GetWindowIdFromHandle(HWND window_handle) const { @@ -183,8 +178,7 @@ int ApiDispatcher::GetWindowIdFromHandle(HWND window_handle) const { } void ApiDispatcher::DeleteTabHandle(HWND handle) { - Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> - DeleteTabHandle(handle); + ExecutorsManager::GetInstance()->DeleteTabHandle(handle); } void ApiDispatcher::RegisterInvocation(const char* function_name, @@ -297,11 +291,11 @@ const Value* ApiDispatcher::InvocationResult::GetValue(const char* name) { } ApiDispatcher* ApiDispatcher::InvocationResult::GetDispatcher() { - return ProductionApiDispatcher::get(); + return ProductionApiDispatcher::GetInstance(); } ApiDispatcher* ApiDispatcher::Invocation::GetDispatcher() { - return ProductionApiDispatcher::get(); + return ProductionApiDispatcher::GetInstance(); } // Function registration preprocessor magic. See api_registration.h for details. @@ -322,3 +316,8 @@ ApiDispatcher* ApiDispatcher::Invocation::GetDispatcher() { ProductionApiDispatcher::ProductionApiDispatcher() { REGISTER_ALL_API_FUNCTIONS(); } + +// static +ProductionApiDispatcher* ProductionApiDispatcher::GetInstance() { + return Singleton<ProductionApiDispatcher>::get(); +} diff --git a/ceee/ie/broker/api_dispatcher.h b/ceee/ie/broker/api_dispatcher.h index 6f6a86a..ce51dfb 100644 --- a/ceee/ie/broker/api_dispatcher.h +++ b/ceee/ie/broker/api_dispatcher.h @@ -307,8 +307,10 @@ ApiDispatcher::Invocation* NewApiInvocation() { // A singleton that initializes and keeps the ApiDispatcher used by production // code. -class ProductionApiDispatcher : public ApiDispatcher, - public Singleton<ProductionApiDispatcher> { +class ProductionApiDispatcher : public ApiDispatcher { + public: + static ProductionApiDispatcher* GetInstance(); + private: // This ensures no construction is possible outside of the class itself. friend struct DefaultSingletonTraits<ProductionApiDispatcher>; diff --git a/ceee/ie/broker/broker.cc b/ceee/ie/broker/broker.cc index 36e8bc8..65ea376 100644 --- a/ceee/ie/broker/broker.cc +++ b/ceee/ie/broker/broker.cc @@ -16,9 +16,8 @@ HRESULT CeeeBroker::FinalConstruct() { // So that we get a pointer to the ExecutorsManager and let tests override it. - executors_manager_ = Singleton<ExecutorsManager, - ExecutorsManager::SingletonTraits>::get(); - api_dispatcher_ = ProductionApiDispatcher::get(); + executors_manager_ = ExecutorsManager::GetInstance(); + api_dispatcher_ = ProductionApiDispatcher::GetInstance(); return S_OK; } diff --git a/ceee/ie/broker/broker_module.cc b/ceee/ie/broker/broker_module.cc index 252e6a4..6728c06 100644 --- a/ceee/ie/broker/broker_module.cc +++ b/ceee/ie/broker/broker_module.cc @@ -197,8 +197,7 @@ HRESULT CeeeBrokerModule::PostMessageLoop() { void CeeeBrokerModule::TearDown() { rpc_server_.Stop(); - Singleton<ExecutorsManager, - ExecutorsManager::SingletonTraits>()->Terminate(); + ExecutorsManager::GetInstance()->Terminate(); WindowEventsFunnel::Terminate(); // Upload data if necessary. diff --git a/ceee/ie/broker/chrome_postman.cc b/ceee/ie/broker/chrome_postman.cc index 9a9562d..430446a 100644 --- a/ceee/ie/broker/chrome_postman.cc +++ b/ceee/ie/broker/chrome_postman.cc @@ -60,7 +60,7 @@ class ApiExecutionTask : public Task { explicit ApiExecutionTask(BSTR message) : message_(message) {} virtual void Run() { - ProductionApiDispatcher::get()->HandleApiRequest(message_, NULL); + ProductionApiDispatcher::GetInstance()->HandleApiRequest(message_, NULL); } private: CComBSTR message_; @@ -72,8 +72,8 @@ class FireEventTask : public Task { : event_name_(event_name), event_args_(event_args) {} virtual void Run() { - ProductionApiDispatcher::get()->FireEvent(event_name_.c_str(), - event_args_.c_str()); + ProductionApiDispatcher::GetInstance()->FireEvent(event_name_.c_str(), + event_args_.c_str()); } private: std::string event_name_; @@ -318,11 +318,11 @@ ChromePostman::ApiInvocationWorkerThread::ApiInvocationWorkerThread() void ChromePostman::ApiInvocationWorkerThread::Init() { ::CoInitializeEx(0, COINIT_MULTITHREADED); - ProductionApiDispatcher::get()->SetApiInvocationThreadId( + ProductionApiDispatcher::GetInstance()->SetApiInvocationThreadId( ::GetCurrentThreadId()); } void ChromePostman::ApiInvocationWorkerThread::CleanUp() { ::CoUninitialize(); - ProductionApiDispatcher::get()->SetApiInvocationThreadId(0); + ProductionApiDispatcher::GetInstance()->SetApiInvocationThreadId(0); } diff --git a/ceee/ie/broker/executors_manager.cc b/ceee/ie/broker/executors_manager.cc index a221eb6..4e2c32d 100644 --- a/ceee/ie/broker/executors_manager.cc +++ b/ceee/ie/broker/executors_manager.cc @@ -69,6 +69,11 @@ ExecutorsManager::ExecutorsManager(bool no_thread) } } +// static +ExecutorsManager* ExecutorsManager::GetInstance() { + return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get(); +} + bool ExecutorsManager::IsKnownWindow(HWND window) { return Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> IsKnownWindowImpl(window); diff --git a/ceee/ie/broker/executors_manager.h b/ceee/ie/broker/executors_manager.h index 48a15f9..48925d5 100644 --- a/ceee/ie/broker/executors_manager.h +++ b/ceee/ie/broker/executors_manager.h @@ -34,6 +34,9 @@ class ExecutorsManager { // Identifiers for destination threads where to run executors. typedef DWORD ThreadId; + // Returns the singleton instance. + static ExecutorsManager* GetInstance(); + // To avoid lint errors, even though we are only virtual for unittests. virtual ~ExecutorsManager() {} @@ -125,6 +128,7 @@ class ExecutorsManager { // thread id. virtual void CleanupMapsForThread(DWORD thread_id); + protected: // Traits for Singleton<ExecutorsManager> so that we can pass an argument // to the constructor. struct SingletonTraits : public DefaultSingletonTraits<ExecutorsManager> { @@ -136,7 +140,6 @@ class ExecutorsManager { } }; - protected: // The data we pass to start our worker thread. // THERE IS A COPY OF THIS CLASS IN THE UNITTEST WHICH YOU NEED TO UPDATE IF // you change this one... diff --git a/ceee/ie/broker/tab_api_module.cc b/ceee/ie/broker/tab_api_module.cc index c2ac61f..49f92b5 100644 --- a/ceee/ie/broker/tab_api_module.cc +++ b/ceee/ie/broker/tab_api_module.cc @@ -153,8 +153,7 @@ bool CeeeMapTabIdToHandle(const std::string& input_args, int tab_id = kInvalidChromeSessionId; HWND tab_handle = NULL; if (GetIdAndHandleFromArgs(input_args, &tab_id, &tab_handle)) { - Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> - SetTabIdForHandle(tab_id, tab_handle); + ExecutorsManager::GetInstance()->SetTabIdForHandle(tab_id, tab_handle); return true; } return false; @@ -166,8 +165,8 @@ bool CeeeMapToolbandIdToHandle(const std::string& input_args, int toolband_id = kInvalidChromeSessionId; HWND tab_handle = NULL; if (GetIdAndHandleFromArgs(input_args, &toolband_id, &tab_handle)) { - Singleton<ExecutorsManager, ExecutorsManager::SingletonTraits>::get()-> - SetTabToolBandIdForHandle(toolband_id, tab_handle); + ExecutorsManager::GetInstance()->SetTabToolBandIdForHandle(toolband_id, + tab_handle); return true; } return false; |