Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/browser/browsing_data_cookie_helper.h

Issue 7355025: Creat BrowsingDataCookieHelper and CannedBrowsingDataCookieHelper for logging cookies at UI thread. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #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.
14 #include "base/memory/scoped_ptr.h"
15 #include "net/base/cookie_monster.h"
16
17 class GURL;
18 class Profile;
19
20 namespace net {
21 class URLRequestContextGetter;
22 }
23
24 // This class fetches cookie information on behalf of a caller
25 // on the UI thread.
26 // A client of this class need to call StartFetching from the UI thread to
27 // initiate the flow, and it'll be notified by the callback in its UI
28 // thread at some later point.
29 // The client must call CancelNotification() if it's destroyed before the
30 // callback is notified.
31 class BrowsingDataCookieHelper
32 : public base::RefCountedThreadSafe<BrowsingDataCookieHelper> {
33 public:
34 explicit BrowsingDataCookieHelper(Profile* profile);
35
36 // Starts the fetching process, which will notify its completion via
37 // callback.
38 // This must be called only in the UI thread.
39 virtual void StartFetching(
40 const base::Callback<void(const net::CookieList& cookies)>& callback);
41
42 // Cancels the notification callback (i.e., the window that created it no
43 // longer exists).
44 // This must be called only in the UI thread.
45 virtual void CancelNotification();
46
47 // Requests a single cookie to be deleted in the IO thread. This must be
48 // called in the UI thread.
49 virtual void DeleteCookie(const net::CookieMonster::CanonicalCookie& cookie);
50
51 protected:
52 friend class base::RefCountedThreadSafe<BrowsingDataCookieHelper>;
53 virtual ~BrowsingDataCookieHelper();
54
55 // net::CookieList cookie_list_;
erikwright (departed) 2011/07/19 14:40:33 Remove this line.
ycxiao1 2011/07/19 22:12:48 Done.
56
57 private:
58 // Fetch the cookies. This must be called in the IO thread.
59 void FetchCookiesOnIOThread();
60
61 // Callback function for get cookie. This must be called in the IO thread.
62 void OnFetchComplete(const net::CookieList& cookies);
63
64 // Notifies the completion callback. This must be called in the UI thread.
65 void NotifyInUIThread(const net::CookieList& cookies);
66
67 // Delete a single cookie. This must be called in IO thread.
68 void DeleteCookieOnIOThread(
69 const net::CookieMonster::CanonicalCookie& cookie);
70
71 // Indicates whether or not we're currently fetching information:
72 // it's true when StartFetching() is called in the UI thread, and it's reset
73 // after we notify the callback in the UI thread.
74 // This only mutates on the UI thread.
75 bool is_fetching_;
76
77 Profile* profile_;
78
79 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
80
81 // This only mutates on the UI thread.
82 base::Callback<void(const net::CookieList& cookies)> completion_callback_;
83
84 DISALLOW_COPY_AND_ASSIGN(BrowsingDataCookieHelper);
85 };
86
87 // This class is a thin wrapper around BrowsingDataCookieHelper that does not
88 // fetch its information from the persistent cookie store, but gets them passed
89 // as a parameter during construction.
90 class CannedBrowsingDataCookieHelper : public BrowsingDataCookieHelper {
91 public:
92 explicit CannedBrowsingDataCookieHelper(Profile* profile);
93
94 // Return a copy of the cookie helper. Only one consumer can use the
95 // StartFetching method at a time, so we need to create a copy of the helper
96 // everytime we instantiate a cookies tree model for it.
97 CannedBrowsingDataCookieHelper* Clone();
98
99 // 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.
100 // Domain or Path.
101 void AddReadCookie(const GURL& url,
102 const net::CookieList& cookie_list);
103
104 // 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.
105 // differernt form the current cookies at Name, Domain or Path.
106 void AddChangeCookie(const GURL& url,
107 const std::string& cookie_line,
108 const net::CookieOptions& options);
109
110 // Clears the list of canned cookies.
111 void Reset();
112
113 // True if no cookie are currently stored.
114 bool empty() const;
115
116 // Return cookies. This is used by tests.
117 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.
118
119 // BrowsingDataCookieHelper methods.
120 virtual void StartFetching(
121 const net::CookieMonster::GetCookieListCallback& callback);
122 virtual void CancelNotification();
123
124 private:
125 bool HasCookie(const net::CookieMonster::CanonicalCookie& add_cookie);
126 virtual ~CannedBrowsingDataCookieHelper();
127
128 net::CookieList cookie_list_;
129
130 Profile* profile_;
131
132 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataCookieHelper);
133 };
134
135 #endif // CHROME_BROWSER_BROWSING_DATA_COOKIE_HELPER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/browsing_data_cookie_helper.cc » ('j') | chrome/browser/browsing_data_cookie_helper.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698