| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_ | 5 #ifndef CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_ |
| 6 #define CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_ | 6 #define CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "net/cookies/cookie_monster.h" | 14 #include "net/cookies/cookie_monster.h" |
| 15 | 15 |
| 16 class GURL; | 16 class GURL; |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 class CanonicalCookie; |
| 19 class URLRequestContextGetter; | 20 class URLRequestContextGetter; |
| 20 } | 21 } |
| 21 | 22 |
| 22 // This class fetches cookie information on behalf of a caller | 23 // This class fetches cookie information on behalf of a caller |
| 23 // on the UI thread. | 24 // on the UI thread. |
| 24 // A client of this class need to call StartFetching from the UI thread to | 25 // A client of this class need to call StartFetching from the UI thread to |
| 25 // initiate the flow, and it'll be notified by the callback in its UI | 26 // initiate the flow, and it'll be notified by the callback in its UI |
| 26 // thread at some later point. | 27 // thread at some later point. |
| 27 class BrowsingDataCookieHelper | 28 class BrowsingDataCookieHelper |
| 28 : public base::RefCountedThreadSafe<BrowsingDataCookieHelper> { | 29 : public base::RefCountedThreadSafe<BrowsingDataCookieHelper> { |
| 29 public: | 30 public: |
| 30 explicit BrowsingDataCookieHelper( | 31 explicit BrowsingDataCookieHelper( |
| 31 net::URLRequestContextGetter* request_context_getter); | 32 net::URLRequestContextGetter* request_context_getter); |
| 32 | 33 |
| 33 // Starts the fetching process, which will notify its completion via | 34 // Starts the fetching process, which will notify its completion via |
| 34 // callback. | 35 // callback. |
| 35 // This must be called only in the UI thread. | 36 // This must be called only in the UI thread. |
| 36 virtual void StartFetching( | 37 virtual void StartFetching( |
| 37 const base::Callback<void(const net::CookieList& cookies)>& callback); | 38 const base::Callback<void(const net::CookieList& cookies)>& callback); |
| 38 | 39 |
| 39 // Requests a single cookie to be deleted in the IO thread. This must be | 40 // Requests a single cookie to be deleted in the IO thread. This must be |
| 40 // called in the UI thread. | 41 // called in the UI thread. |
| 41 virtual void DeleteCookie(const net::CookieMonster::CanonicalCookie& cookie); | 42 virtual void DeleteCookie(const net::CanonicalCookie& cookie); |
| 42 | 43 |
| 43 protected: | 44 protected: |
| 44 friend class base::RefCountedThreadSafe<BrowsingDataCookieHelper>; | 45 friend class base::RefCountedThreadSafe<BrowsingDataCookieHelper>; |
| 45 virtual ~BrowsingDataCookieHelper(); | 46 virtual ~BrowsingDataCookieHelper(); |
| 46 | 47 |
| 47 net::URLRequestContextGetter* request_context_getter() { | 48 net::URLRequestContextGetter* request_context_getter() { |
| 48 return request_context_getter_; | 49 return request_context_getter_; |
| 49 } | 50 } |
| 50 | 51 |
| 51 private: | 52 private: |
| 52 // Fetch the cookies. This must be called in the IO thread. | 53 // Fetch the cookies. This must be called in the IO thread. |
| 53 void FetchCookiesOnIOThread(); | 54 void FetchCookiesOnIOThread(); |
| 54 | 55 |
| 55 // Callback function for get cookie. This must be called in the IO thread. | 56 // Callback function for get cookie. This must be called in the IO thread. |
| 56 void OnFetchComplete(const net::CookieList& cookies); | 57 void OnFetchComplete(const net::CookieList& cookies); |
| 57 | 58 |
| 58 // Notifies the completion callback. This must be called in the UI thread. | 59 // Notifies the completion callback. This must be called in the UI thread. |
| 59 void NotifyInUIThread(const net::CookieList& cookies); | 60 void NotifyInUIThread(const net::CookieList& cookies); |
| 60 | 61 |
| 61 // Delete a single cookie. This must be called in IO thread. | 62 // Delete a single cookie. This must be called in IO thread. |
| 62 void DeleteCookieOnIOThread( | 63 void DeleteCookieOnIOThread(const net::CanonicalCookie& cookie); |
| 63 const net::CookieMonster::CanonicalCookie& cookie); | |
| 64 | 64 |
| 65 // Indicates whether or not we're currently fetching information: | 65 // Indicates whether or not we're currently fetching information: |
| 66 // it's true when StartFetching() is called in the UI thread, and it's reset | 66 // it's true when StartFetching() is called in the UI thread, and it's reset |
| 67 // after we notify the callback in the UI thread. | 67 // after we notify the callback in the UI thread. |
| 68 // This only mutates on the UI thread. | 68 // This only mutates on the UI thread. |
| 69 bool is_fetching_; | 69 bool is_fetching_; |
| 70 | 70 |
| 71 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 71 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 72 | 72 |
| 73 // This only mutates on the UI thread. | 73 // This only mutates on the UI thread. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 // Returns the map that contains the cookie lists for all frame urls. | 120 // Returns the map that contains the cookie lists for all frame urls. |
| 121 const OriginCookieListMap& origin_cookie_list_map() { | 121 const OriginCookieListMap& origin_cookie_list_map() { |
| 122 return origin_cookie_list_map_; | 122 return origin_cookie_list_map_; |
| 123 } | 123 } |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 // Check if the cookie list contains a cookie with the same name, | 126 // Check if the cookie list contains a cookie with the same name, |
| 127 // domain, and path as the newly created cookie. Delete the old cookie | 127 // domain, and path as the newly created cookie. Delete the old cookie |
| 128 // if does. | 128 // if does. |
| 129 bool DeleteMatchingCookie( | 129 bool DeleteMatchingCookie(const net::CanonicalCookie& add_cookie, |
| 130 const net::CookieMonster::CanonicalCookie& add_cookie, | 130 net::CookieList* cookie_list); |
| 131 net::CookieList* cookie_list); | |
| 132 | 131 |
| 133 virtual ~CannedBrowsingDataCookieHelper(); | 132 virtual ~CannedBrowsingDataCookieHelper(); |
| 134 | 133 |
| 135 // Returns the |CookieList| for the given |origin|. | 134 // Returns the |CookieList| for the given |origin|. |
| 136 net::CookieList* GetCookiesFor(const GURL& origin); | 135 net::CookieList* GetCookiesFor(const GURL& origin); |
| 137 | 136 |
| 138 // Adds the |cookie| to the cookie list for the given |frame_url|. | 137 // Adds the |cookie| to the cookie list for the given |frame_url|. |
| 139 void AddCookie( | 138 void AddCookie(const GURL& frame_url, |
| 140 const GURL& frame_url, | 139 const net::CanonicalCookie& cookie); |
| 141 const net::CookieMonster::CanonicalCookie& cookie); | |
| 142 | 140 |
| 143 // Map that contains the cookie lists for all frame origins. | 141 // Map that contains the cookie lists for all frame origins. |
| 144 OriginCookieListMap origin_cookie_list_map_; | 142 OriginCookieListMap origin_cookie_list_map_; |
| 145 | 143 |
| 146 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataCookieHelper); | 144 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataCookieHelper); |
| 147 }; | 145 }; |
| 148 | 146 |
| 149 #endif // CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_ | 147 #endif // CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_ |
| OLD | NEW |