Index: chrome/browser/browsing_data_cookie_helper.h |
=================================================================== |
--- chrome/browser/browsing_data_cookie_helper.h (revision 0) |
+++ chrome/browser/browsing_data_cookie_helper.h (revision 0) |
@@ -0,0 +1,135 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_ |
+#define CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_ |
+#pragma once |
+ |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/callback.h" |
+#include "base/memory/ref_counted.h" |
erikwright (departed)
2011/07/19 14:40:33
I think you only use scoped_ptr in the .cc. Can yo
ycxiao1
2011/07/19 22:12:48
Done.
|
+#include "base/memory/scoped_ptr.h" |
+#include "net/base/cookie_monster.h" |
+ |
+class GURL; |
+class Profile; |
+ |
+namespace net { |
+class URLRequestContextGetter; |
+} |
+ |
+// This class fetches cookie information on behalf of a caller |
+// on the UI thread. |
+// A client of this class need to call StartFetching from the UI thread to |
+// initiate the flow, and it'll be notified by the callback in its UI |
+// thread at some later point. |
+// The client must call CancelNotification() if it's destroyed before the |
+// callback is notified. |
+class BrowsingDataCookieHelper |
+ : public base::RefCountedThreadSafe<BrowsingDataCookieHelper> { |
+ public: |
+ explicit BrowsingDataCookieHelper(Profile* profile); |
+ |
+ // Starts the fetching process, which will notify its completion via |
+ // callback. |
+ // This must be called only in the UI thread. |
+ virtual void StartFetching( |
+ const base::Callback<void(const net::CookieList& cookies)>& callback); |
+ |
+ // Cancels the notification callback (i.e., the window that created it no |
+ // longer exists). |
+ // This must be called only in the UI thread. |
+ virtual void CancelNotification(); |
+ |
+ // Requests a single cookie to be deleted in the IO thread. This must be |
+ // called in the UI thread. |
+ virtual void DeleteCookie(const net::CookieMonster::CanonicalCookie& cookie); |
+ |
+ protected: |
+ friend class base::RefCountedThreadSafe<BrowsingDataCookieHelper>; |
+ virtual ~BrowsingDataCookieHelper(); |
+ |
+ // net::CookieList cookie_list_; |
erikwright (departed)
2011/07/19 14:40:33
Remove this line.
ycxiao1
2011/07/19 22:12:48
Done.
|
+ |
+ private: |
+ // Fetch the cookies. This must be called in the IO thread. |
+ void FetchCookiesOnIOThread(); |
+ |
+ // Callback function for get cookie. This must be called in the IO thread. |
+ void OnFetchComplete(const net::CookieList& cookies); |
+ |
+ // Notifies the completion callback. This must be called in the UI thread. |
+ void NotifyInUIThread(const net::CookieList& cookies); |
+ |
+ // Delete a single cookie. This must be called in IO thread. |
+ void DeleteCookieOnIOThread( |
+ const net::CookieMonster::CanonicalCookie& cookie); |
+ |
+ // Indicates whether or not we're currently fetching information: |
+ // it's true when StartFetching() is called in the UI thread, and it's reset |
+ // after we notify the callback in the UI thread. |
+ // This only mutates on the UI thread. |
+ bool is_fetching_; |
+ |
+ Profile* profile_; |
+ |
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
+ |
+ // This only mutates on the UI thread. |
+ base::Callback<void(const net::CookieList& cookies)> completion_callback_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BrowsingDataCookieHelper); |
+}; |
+ |
+// This class is a thin wrapper around BrowsingDataCookieHelper that does not |
+// fetch its information from the persistent cookie store, but gets them passed |
+// as a parameter during construction. |
+class CannedBrowsingDataCookieHelper : public BrowsingDataCookieHelper { |
+ public: |
+ explicit CannedBrowsingDataCookieHelper(Profile* profile); |
+ |
+ // Return a copy of the cookie helper. Only one consumer can use the |
+ // StartFetching method at a time, so we need to create a copy of the helper |
+ // everytime we instantiate a cookies tree model for it. |
+ CannedBrowsingDataCookieHelper* Clone(); |
+ |
+ // Add those cookies which are differnet from the current cookies at Name, |
erikwright (departed)
2011/07/19 14:40:33
"Adds those cookie which differ from the current c
ycxiao1
2011/07/19 22:12:48
Done.
|
+ // Domain or Path. |
+ void AddReadCookie(const GURL& url, |
+ const net::CookieList& cookie_list); |
+ |
+ // Parses the cookie line, adds all successfully parsed cookies that are |
erikwright (departed)
2011/07/19 14:40:33
"Parses the cookie line and ... that differ from .
ycxiao1
2011/07/19 22:12:48
Done.
|
+ // differernt form the current cookies at Name, Domain or Path. |
+ void AddChangeCookie(const GURL& url, |
+ const std::string& cookie_line, |
+ const net::CookieOptions& options); |
+ |
+ // Clears the list of canned cookies. |
+ void Reset(); |
+ |
+ // True if no cookie are currently stored. |
+ bool empty() const; |
+ |
+ // Return cookies. This is used by tests. |
+ const net::CookieList& cookie_list(); |
erikwright (departed)
2011/07/19 14:40:33
Remove this. See my comment in the test for furthe
ycxiao1
2011/07/19 22:12:48
Done.
|
+ |
+ // BrowsingDataCookieHelper methods. |
+ virtual void StartFetching( |
+ const net::CookieMonster::GetCookieListCallback& callback); |
+ virtual void CancelNotification(); |
+ |
+ private: |
+ bool HasCookie(const net::CookieMonster::CanonicalCookie& add_cookie); |
+ virtual ~CannedBrowsingDataCookieHelper(); |
+ |
+ net::CookieList cookie_list_; |
+ |
+ Profile* profile_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataCookieHelper); |
+}; |
+ |
+#endif // CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_ |
Property changes on: chrome/browser/browsing_data_cookie_helper.h |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |