OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Defines the CookieAccountant class, which is responsible for observing | 5 // Defines the CookieAccountant class, which is responsible for observing |
6 // and recording all cookie-related information generated by a particular | 6 // and recording all cookie-related information generated by a particular |
7 // IE browser session. It records and fires cookie change events, it provides | 7 // IE browser session. It records and fires cookie change events, it provides |
8 // access to session and persistent cookies. | 8 // access to session and persistent cookies. |
9 | 9 |
10 #ifndef CEEE_IE_PLUGIN_BHO_COOKIE_ACCOUNTANT_H_ | 10 #ifndef CEEE_IE_PLUGIN_BHO_COOKIE_ACCOUNTANT_H_ |
11 #define CEEE_IE_PLUGIN_BHO_COOKIE_ACCOUNTANT_H_ | 11 #define CEEE_IE_PLUGIN_BHO_COOKIE_ACCOUNTANT_H_ |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "app/win/iat_patch_function.h" | 15 #include "app/win/iat_patch_function.h" |
| 16 #include "base/lock.h" |
16 #include "base/singleton.h" | 17 #include "base/singleton.h" |
17 #include "base/time.h" | 18 #include "base/time.h" |
18 #include "ceee/ie/plugin/bho/cookie_events_funnel.h" | 19 #include "ceee/ie/plugin/bho/cookie_events_funnel.h" |
19 #include "net/base/cookie_monster.h" | 20 #include "net/base/cookie_monster.h" |
20 | 21 |
21 // The class that accounts for all cookie-related activity for a single IE | 22 // The class that accounts for all cookie-related activity for a single IE |
22 // browser session context. There should only need to be one of these allocated | 23 // browser session context. There should only need to be one of these allocated |
23 // per process; use ProductionCookieAccountant instead of using this class | 24 // per process; use ProductionCookieAccountant instead of using this class |
24 // directly. | 25 // directly. |
25 class CookieAccountant { | 26 class CookieAccountant { |
(...skipping 19 matching lines...) Expand all Loading... |
45 static DWORD WINAPI InternetSetCookieExWPatch( | 46 static DWORD WINAPI InternetSetCookieExWPatch( |
46 LPCWSTR lpszURL, LPCWSTR lpszCookieName, LPCWSTR lpszCookieData, | 47 LPCWSTR lpszURL, LPCWSTR lpszCookieName, LPCWSTR lpszCookieData, |
47 DWORD dwFlags, DWORD_PTR dwReserved); | 48 DWORD dwFlags, DWORD_PTR dwReserved); |
48 | 49 |
49 protected: | 50 protected: |
50 // Exposed to subclasses mainly for unit testing purposes; production code | 51 // Exposed to subclasses mainly for unit testing purposes; production code |
51 // should use the ProductionCookieAccountant class instead. | 52 // should use the ProductionCookieAccountant class instead. |
52 // Since this class has one instance per window, not per tab, we cannot | 53 // Since this class has one instance per window, not per tab, we cannot |
53 // queue the events sent to the broker. They don't need to be sent to the BHO | 54 // queue the events sent to the broker. They don't need to be sent to the BHO |
54 // because they don't need tab_id anyway. | 55 // because they don't need tab_id anyway. |
55 CookieAccountant() : cookie_events_funnel_(new BrokerRpcClient) {} | 56 CookieAccountant() |
| 57 : cookie_events_funnel_(new BrokerRpcClient), |
| 58 patching_wininet_functions_(false) { |
| 59 } |
| 60 |
56 virtual ~CookieAccountant(); | 61 virtual ~CookieAccountant(); |
57 | 62 |
58 // Records the modification or creation of a cookie. Fires off a | 63 // Records the modification or creation of a cookie. Fires off a |
59 // cookies.onChanged event to Chrome Frame. | 64 // cookies.onChanged event to Chrome Frame. |
60 virtual void RecordCookie( | 65 virtual void RecordCookie( |
61 const std::string& url, const std::string& cookie_data, | 66 const std::string& url, const std::string& cookie_data, |
62 const base::Time& current_time); | 67 const base::Time& current_time); |
63 | 68 |
64 // Unit test seam. | 69 // Unit test seam. |
65 virtual CookieEventsFunnel& cookie_events_funnel() { | 70 virtual CookieEventsFunnel& cookie_events_funnel() { |
66 return cookie_events_funnel_; | 71 return cookie_events_funnel_; |
67 } | 72 } |
68 | 73 |
69 // Function patches that allow us to intercept scripted cookie changes. | 74 // Function patches that allow us to intercept scripted cookie changes. |
70 app::win::IATPatchFunction internet_set_cookie_ex_a_patch_; | 75 app::win::IATPatchFunction internet_set_cookie_ex_a_patch_; |
71 app::win::IATPatchFunction internet_set_cookie_ex_w_patch_; | 76 app::win::IATPatchFunction internet_set_cookie_ex_w_patch_; |
72 | 77 |
| 78 // Used to allow exactly one thread to attempt to apply function patches. |
| 79 // We use this boolean instead of a simple lock so that threads that lose |
| 80 // the race will return immediately instead of blocking on the lock. |
| 81 // Protected by CookieAccountant::lock_. |
| 82 bool patching_wininet_functions_; |
| 83 |
| 84 // A lock that protects access to the function patches. |
| 85 Lock lock_; |
| 86 |
73 // Cached singleton instance. Useful for unit testing. | 87 // Cached singleton instance. Useful for unit testing. |
74 static CookieAccountant* singleton_instance_; | 88 static CookieAccountant* singleton_instance_; |
75 | 89 |
76 private: | 90 private: |
77 // Helper functions for extracting cookie information from a scripted cookie | 91 // Helper functions for extracting cookie information from a scripted cookie |
78 // being set, to pass to the cookie onChanged event. | 92 // being set, to pass to the cookie onChanged event. |
79 | 93 |
80 // Sets the cookie domain for a script cookie event. | 94 // Sets the cookie domain for a script cookie event. |
81 void SetScriptCookieDomain( | 95 void SetScriptCookieDomain( |
82 const net::CookieMonster::ParsedCookie& parsed_cookie, | 96 const net::CookieMonster::ParsedCookie& parsed_cookie, |
(...skipping 24 matching lines...) Expand all Loading... |
107 // be accessed for unit testing. | 121 // be accessed for unit testing. |
108 class ProductionCookieAccountant : public CookieAccountant, | 122 class ProductionCookieAccountant : public CookieAccountant, |
109 public Singleton<ProductionCookieAccountant> { | 123 public Singleton<ProductionCookieAccountant> { |
110 private: | 124 private: |
111 // This ensures no construction is possible outside of the class itself. | 125 // This ensures no construction is possible outside of the class itself. |
112 friend struct DefaultSingletonTraits<ProductionCookieAccountant>; | 126 friend struct DefaultSingletonTraits<ProductionCookieAccountant>; |
113 DISALLOW_IMPLICIT_CONSTRUCTORS(ProductionCookieAccountant); | 127 DISALLOW_IMPLICIT_CONSTRUCTORS(ProductionCookieAccountant); |
114 }; | 128 }; |
115 | 129 |
116 #endif // CEEE_IE_PLUGIN_BHO_COOKIE_ACCOUNTANT_H_ | 130 #endif // CEEE_IE_PLUGIN_BHO_COOKIE_ACCOUNTANT_H_ |
OLD | NEW |