summaryrefslogtreecommitdiffstats
path: root/ceee
diff options
context:
space:
mode:
authorsatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-08 10:43:08 +0000
committersatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-08 10:43:08 +0000
commit687b96058845cdaa59f9d81c468f81222e60bdfd (patch)
tree9c97670a35e5f6abe40f3c4bf50ee7b5a257a0e3 /ceee
parentd22618c155cd40c5740755a5f0bcaab59f13f9a7 (diff)
downloadchromium_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')
-rw-r--r--ceee/ie/broker/api_dispatcher.cc33
-rw-r--r--ceee/ie/broker/api_dispatcher.h6
-rw-r--r--ceee/ie/broker/broker.cc5
-rw-r--r--ceee/ie/broker/broker_module.cc3
-rw-r--r--ceee/ie/broker/chrome_postman.cc10
-rw-r--r--ceee/ie/broker/executors_manager.cc5
-rw-r--r--ceee/ie/broker/executors_manager.h5
-rw-r--r--ceee/ie/broker/tab_api_module.cc7
-rw-r--r--ceee/ie/plugin/bho/cookie_accountant.cc7
-rw-r--r--ceee/ie/plugin/bho/cookie_accountant.h6
-rw-r--r--ceee/ie/plugin/bho/web_progress_notifier.cc2
-rw-r--r--ceee/ie/plugin/bho/webrequest_notifier.cc25
-rw-r--r--ceee/ie/plugin/bho/webrequest_notifier.h7
13 files changed, 70 insertions, 51 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;
diff --git a/ceee/ie/plugin/bho/cookie_accountant.cc b/ceee/ie/plugin/bho/cookie_accountant.cc
index 1da3256..3d0f3f1 100644
--- a/ceee/ie/plugin/bho/cookie_accountant.cc
+++ b/ceee/ie/plugin/bho/cookie_accountant.cc
@@ -44,10 +44,15 @@ CookieAccountant::~CookieAccountant() {
ProductionCookieAccountant::ProductionCookieAccountant() {
}
+// static
+ProductionCookieAccountant* ProductionCookieAccountant::GetInstance() {
+ return Singleton<ProductionCookieAccountant>::get();
+}
+
CookieAccountant* CookieAccountant::GetInstance() {
// Unit tests can set singleton_instance_ directly.
if (singleton_instance_ == NULL)
- singleton_instance_ = ProductionCookieAccountant::get();
+ singleton_instance_ = ProductionCookieAccountant::GetInstance();
return singleton_instance_;
}
diff --git a/ceee/ie/plugin/bho/cookie_accountant.h b/ceee/ie/plugin/bho/cookie_accountant.h
index 8e7423b..a2b9de3 100644
--- a/ceee/ie/plugin/bho/cookie_accountant.h
+++ b/ceee/ie/plugin/bho/cookie_accountant.h
@@ -125,8 +125,10 @@ class CookieAccountant {
// A singleton that initializes and keeps the CookieAccountant used by
// production code. This class is separate so that CookieAccountant can still
// be accessed for unit testing.
-class ProductionCookieAccountant : public CookieAccountant,
- public Singleton<ProductionCookieAccountant> {
+class ProductionCookieAccountant : public CookieAccountant {
+ public:
+ static ProductionCookieAccountant* GetInstance();
+
private:
// This ensures no construction is possible outside of the class itself.
friend struct DefaultSingletonTraits<ProductionCookieAccountant>;
diff --git a/ceee/ie/plugin/bho/web_progress_notifier.cc b/ceee/ie/plugin/bho/web_progress_notifier.cc
index 567c543..0984f4d1 100644
--- a/ceee/ie/plugin/bho/web_progress_notifier.cc
+++ b/ceee/ie/plugin/bho/web_progress_notifier.cc
@@ -339,7 +339,7 @@ WebNavigationEventsFunnel* WebProgressNotifier::webnavigation_events_funnel() {
WebRequestNotifier* WebProgressNotifier::webrequest_notifier() {
if (cached_webrequest_notifier_ == NULL) {
- cached_webrequest_notifier_ = ProductionWebRequestNotifier::get();
+ cached_webrequest_notifier_ = ProductionWebRequestNotifier::GetInstance();
}
return cached_webrequest_notifier_;
}
diff --git a/ceee/ie/plugin/bho/webrequest_notifier.cc b/ceee/ie/plugin/bho/webrequest_notifier.cc
index 5f65a8b..c0487a3 100644
--- a/ceee/ie/plugin/bho/webrequest_notifier.cc
+++ b/ceee/ie/plugin/bho/webrequest_notifier.cc
@@ -162,7 +162,7 @@ INTERNET_STATUS_CALLBACK STDAPICALLTYPE
WebRequestNotifier::InternetSetStatusCallbackAPatch(
HINTERNET internet,
INTERNET_STATUS_CALLBACK callback) {
- WebRequestNotifier* instance = ProductionWebRequestNotifier::get();
+ WebRequestNotifier* instance = ProductionWebRequestNotifier::GetInstance();
INTERNET_STATUS_CALLBACK new_callback =
instance->HandleBeforeInternetSetStatusCallback(internet, callback);
return ::InternetSetStatusCallbackA(internet, new_callback);
@@ -172,7 +172,7 @@ INTERNET_STATUS_CALLBACK STDAPICALLTYPE
WebRequestNotifier::InternetSetStatusCallbackWPatch(
HINTERNET internet,
INTERNET_STATUS_CALLBACK callback) {
- WebRequestNotifier* instance = ProductionWebRequestNotifier::get();
+ WebRequestNotifier* instance = ProductionWebRequestNotifier::GetInstance();
INTERNET_STATUS_CALLBACK new_callback =
instance->HandleBeforeInternetSetStatusCallback(internet, callback);
return ::InternetSetStatusCallbackW(internet, new_callback);
@@ -187,7 +187,7 @@ HINTERNET STDAPICALLTYPE WebRequestNotifier::InternetConnectAPatch(
DWORD service,
DWORD flags,
DWORD_PTR context) {
- WebRequestNotifier* instance = ProductionWebRequestNotifier::get();
+ WebRequestNotifier* instance = ProductionWebRequestNotifier::GetInstance();
instance->HandleBeforeInternetConnect(internet);
HINTERNET server = ::InternetConnectA(internet, server_name, server_port,
@@ -208,7 +208,7 @@ HINTERNET STDAPICALLTYPE WebRequestNotifier::InternetConnectWPatch(
DWORD service,
DWORD flags,
DWORD_PTR context) {
- WebRequestNotifier* instance = ProductionWebRequestNotifier::get();
+ WebRequestNotifier* instance = ProductionWebRequestNotifier::GetInstance();
instance->HandleBeforeInternetConnect(internet);
HINTERNET server = ::InternetConnectW(internet, server_name, server_port,
@@ -233,7 +233,7 @@ HINTERNET STDAPICALLTYPE WebRequestNotifier::HttpOpenRequestAPatch(
referrer, accept_types, flags,
context);
- WebRequestNotifier* instance = ProductionWebRequestNotifier::get();
+ WebRequestNotifier* instance = ProductionWebRequestNotifier::GetInstance();
instance->HandleAfterHttpOpenRequest(connect, request, verb,
CA2W(object_name), flags);
return request;
@@ -252,7 +252,7 @@ HINTERNET STDAPICALLTYPE WebRequestNotifier::HttpOpenRequestWPatch(
referrer, accept_types, flags,
context);
- WebRequestNotifier* instance = ProductionWebRequestNotifier::get();
+ WebRequestNotifier* instance = ProductionWebRequestNotifier::GetInstance();
instance->HandleAfterHttpOpenRequest(connect, request, CW2A(verb),
object_name, flags);
return request;
@@ -264,7 +264,7 @@ BOOL STDAPICALLTYPE WebRequestNotifier::HttpSendRequestAPatch(
DWORD headers_length,
LPVOID optional,
DWORD optional_length) {
- WebRequestNotifier* instance = ProductionWebRequestNotifier::get();
+ WebRequestNotifier* instance = ProductionWebRequestNotifier::GetInstance();
instance->HandleBeforeHttpSendRequest(request);
return ::HttpSendRequestA(request, headers, headers_length, optional,
optional_length);
@@ -276,7 +276,7 @@ BOOL STDAPICALLTYPE WebRequestNotifier::HttpSendRequestWPatch(
DWORD headers_length,
LPVOID optional,
DWORD optional_length) {
- WebRequestNotifier* instance = ProductionWebRequestNotifier::get();
+ WebRequestNotifier* instance = ProductionWebRequestNotifier::GetInstance();
instance->HandleBeforeHttpSendRequest(request);
return ::HttpSendRequestW(request, headers, headers_length, optional,
optional_length);
@@ -289,7 +289,7 @@ void CALLBACK WebRequestNotifier::InternetStatusCallbackPatch(
DWORD internet_status,
LPVOID status_information,
DWORD status_information_length) {
- WebRequestNotifier* instance = ProductionWebRequestNotifier::get();
+ WebRequestNotifier* instance = ProductionWebRequestNotifier::GetInstance();
instance->HandleBeforeInternetStatusCallback(original, internet, context,
internet_status,
status_information,
@@ -305,7 +305,7 @@ BOOL STDAPICALLTYPE WebRequestNotifier::InternetReadFilePatch(
LPDWORD number_of_bytes_read) {
BOOL result = ::InternetReadFile(file, buffer, number_of_bytes_to_read,
number_of_bytes_read);
- WebRequestNotifier* instance = ProductionWebRequestNotifier::get();
+ WebRequestNotifier* instance = ProductionWebRequestNotifier::GetInstance();
instance->HandleAfterInternetReadFile(file, result, number_of_bytes_read);
return result;
@@ -813,3 +813,8 @@ void WebRequestNotifier::TransitRequestToNextState(
}
info->state = next_state;
}
+
+// static
+ProductionWebRequestNotifier* ProductionWebRequestNotifier::GetInstance() {
+ return Singleton<ProductionWebRequestNotifier>::get();
+}
diff --git a/ceee/ie/plugin/bho/webrequest_notifier.h b/ceee/ie/plugin/bho/webrequest_notifier.h
index 0676bf65..d7c1227 100644
--- a/ceee/ie/plugin/bho/webrequest_notifier.h
+++ b/ceee/ie/plugin/bho/webrequest_notifier.h
@@ -443,9 +443,10 @@ class WebRequestNotifier {
};
// A singleton that keeps the WebRequestNotifier used by production code.
-class ProductionWebRequestNotifier
- : public WebRequestNotifier,
- public Singleton<ProductionWebRequestNotifier> {
+class ProductionWebRequestNotifier : public WebRequestNotifier {
+ public:
+ static ProductionWebRequestNotifier* GetInstance();
+
private:
ProductionWebRequestNotifier() {}