summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ceee/ie/plugin/bho/cookie_accountant.cc10
-rw-r--r--ceee/ie/plugin/bho/cookie_accountant.h16
2 files changed, 25 insertions, 1 deletions
diff --git a/ceee/ie/plugin/bho/cookie_accountant.cc b/ceee/ie/plugin/bho/cookie_accountant.cc
index cf2d780..1da3256 100644
--- a/ceee/ie/plugin/bho/cookie_accountant.cc
+++ b/ceee/ie/plugin/bho/cookie_accountant.cc
@@ -222,6 +222,12 @@ void CookieAccountant::RecordHttpResponseCookies(
}
void CookieAccountant::PatchWininetFunctions() {
+ {
+ AutoLock lock(lock_);
+ if (patching_wininet_functions_)
+ return;
+ patching_wininet_functions_ = true;
+ }
if (!internet_set_cookie_ex_a_patch_.is_patched()) {
DWORD error = internet_set_cookie_ex_a_patch_.Patch(
kMsHtmlModuleName, kWinInetModuleName,
@@ -236,4 +242,8 @@ void CookieAccountant::PatchWininetFunctions() {
}
DCHECK(internet_set_cookie_ex_a_patch_.is_patched() ||
internet_set_cookie_ex_w_patch_.is_patched());
+ {
+ AutoLock lock(lock_);
+ patching_wininet_functions_ = false;
+ }
}
diff --git a/ceee/ie/plugin/bho/cookie_accountant.h b/ceee/ie/plugin/bho/cookie_accountant.h
index 7b6c1b2..6ae0703 100644
--- a/ceee/ie/plugin/bho/cookie_accountant.h
+++ b/ceee/ie/plugin/bho/cookie_accountant.h
@@ -13,6 +13,7 @@
#include <string>
#include "app/win/iat_patch_function.h"
+#include "base/lock.h"
#include "base/singleton.h"
#include "base/time.h"
#include "ceee/ie/plugin/bho/cookie_events_funnel.h"
@@ -52,7 +53,11 @@ class CookieAccountant {
// Since this class has one instance per window, not per tab, we cannot
// queue the events sent to the broker. They don't need to be sent to the BHO
// because they don't need tab_id anyway.
- CookieAccountant() : cookie_events_funnel_(new BrokerRpcClient) {}
+ CookieAccountant()
+ : cookie_events_funnel_(new BrokerRpcClient),
+ patching_wininet_functions_(false) {
+ }
+
virtual ~CookieAccountant();
// Records the modification or creation of a cookie. Fires off a
@@ -70,6 +75,15 @@ class CookieAccountant {
app::win::IATPatchFunction internet_set_cookie_ex_a_patch_;
app::win::IATPatchFunction internet_set_cookie_ex_w_patch_;
+ // Used to allow exactly one thread to attempt to apply function patches.
+ // We use this boolean instead of a simple lock so that threads that lose
+ // the race will return immediately instead of blocking on the lock.
+ // Protected by CookieAccountant::lock_.
+ bool patching_wininet_functions_;
+
+ // A lock that protects access to the function patches.
+ Lock lock_;
+
// Cached singleton instance. Useful for unit testing.
static CookieAccountant* singleton_instance_;