diff options
author | cindylau@google.com <cindylau@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-02 01:07:22 +0000 |
---|---|---|
committer | cindylau@google.com <cindylau@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-02 01:07:22 +0000 |
commit | f93b79ac79567d4329894de6df2d500a218b5ebe (patch) | |
tree | 2aa97e1e93fbc613c0cbb835c6d4b809a0c09f8d /ceee | |
parent | fff574b23338309ce493edd63a2f8bd854df1c94 (diff) | |
download | chromium_src-f93b79ac79567d4329894de6df2d500a218b5ebe.zip chromium_src-f93b79ac79567d4329894de6df2d500a218b5ebe.tar.gz chromium_src-f93b79ac79567d4329894de6df2d500a218b5ebe.tar.bz2 |
Add a lock to the cookie accountant to prevent race conditions in patching
functions from different threads.
BUG=64844
TEST=Run integration tests.
Review URL: http://codereview.chromium.org/5290011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67926 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ceee')
-rw-r--r-- | ceee/ie/plugin/bho/cookie_accountant.cc | 10 | ||||
-rw-r--r-- | ceee/ie/plugin/bho/cookie_accountant.h | 16 |
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_; |