OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_MANAGER_COOKIE_HELPER_H_ | 5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_MANAGER_COOKIE_HELPER_H_ |
6 #define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_MANAGER_COOKIE_HELPER_H_ | 6 #define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_MANAGER_COOKIE_HELPER_H_ |
7 | 7 |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "net/cookies/canonical_cookie.h" | 10 #include "net/cookies/canonical_cookie.h" |
11 #include "net/url_request/url_request_context_getter.h" | 11 #include "net/url_request/url_request_context_getter.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 class MessageLoopProxy; | 14 class SingleThreadTaskRunner; |
15 } | 15 } |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 class URLRequestContextGetter; | 18 class URLRequestContextGetter; |
19 } | 19 } |
20 | 20 |
21 // This class fetches GAIA cookie on IO thread on behalf of SigninManager which | 21 // This class fetches GAIA cookie on IO thread on behalf of SigninManager which |
22 // only lives on the UI thread. | 22 // only lives on the UI thread. |
23 class SigninManagerCookieHelper | 23 class SigninManagerCookieHelper |
24 : public base::RefCountedThreadSafe<SigninManagerCookieHelper> { | 24 : public base::RefCountedThreadSafe<SigninManagerCookieHelper> { |
25 public: | 25 public: |
26 explicit SigninManagerCookieHelper( | 26 explicit SigninManagerCookieHelper( |
27 net::URLRequestContextGetter* request_context_getter, | 27 net::URLRequestContextGetter* request_context_getter, |
28 scoped_refptr<base::MessageLoopProxy> ui_thread, | 28 scoped_refptr<base::SingleThreadTaskRunner> ui_thread, |
29 scoped_refptr<base::MessageLoopProxy> io_thread); | 29 scoped_refptr<base::SingleThreadTaskRunner> io_thread); |
30 | 30 |
31 // Starts fetching gaia cookies, which will notify its completion via | 31 // Starts fetching gaia cookies, which will notify its completion via |
32 // callback. | 32 // callback. |
33 void StartFetchingGaiaCookiesOnUIThread( | 33 void StartFetchingGaiaCookiesOnUIThread( |
34 const base::Callback<void(const net::CookieList& cookies)>& callback); | 34 const base::Callback<void(const net::CookieList& cookies)>& callback); |
35 | 35 |
36 // Starts fetching cookies for the given URL. This must be called on | 36 // Starts fetching cookies for the given URL. This must be called on |
37 // |ui_thread_|. | 37 // |ui_thread_|. |
38 void StartFetchingCookiesOnUIThread( | 38 void StartFetchingCookiesOnUIThread( |
39 const GURL& url, | 39 const GURL& url, |
40 const base::Callback<void(const net::CookieList& cookies)>& callback); | 40 const base::Callback<void(const net::CookieList& cookies)>& callback); |
41 | 41 |
42 private: | 42 private: |
43 friend class base::RefCountedThreadSafe<SigninManagerCookieHelper>; | 43 friend class base::RefCountedThreadSafe<SigninManagerCookieHelper>; |
44 ~SigninManagerCookieHelper(); | 44 ~SigninManagerCookieHelper(); |
45 | 45 |
46 // Fetch cookies for the given URL. This must be called on |io_thread_|. | 46 // Fetch cookies for the given URL. This must be called on |io_thread_|. |
47 void FetchCookiesOnIOThread(const GURL& url); | 47 void FetchCookiesOnIOThread(const GURL& url); |
48 | 48 |
49 // Callback for fetching cookies. This must be called on |io_thread_|. | 49 // Callback for fetching cookies. This must be called on |io_thread_|. |
50 void OnCookiesFetched(const net::CookieList& cookies); | 50 void OnCookiesFetched(const net::CookieList& cookies); |
51 | 51 |
52 // Notifies the completion callback. This must be called on |ui_thread_|. | 52 // Notifies the completion callback. This must be called on |ui_thread_|. |
53 void NotifyOnUIThread(const net::CookieList& cookies); | 53 void NotifyOnUIThread(const net::CookieList& cookies); |
54 | 54 |
55 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 55 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
56 // This only mutates on |ui_thread_|. | 56 // This only mutates on |ui_thread_|. |
57 base::Callback<void(const net::CookieList& cookies)> completion_callback_; | 57 base::Callback<void(const net::CookieList& cookies)> completion_callback_; |
58 | 58 |
59 // The MessageLoopProxy that this class uses as its UI thread. | 59 // The task runner that this class uses as its UI thread. |
60 scoped_refptr<base::MessageLoopProxy> ui_thread_; | 60 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_; |
61 // The MessageLoopProxy that this class uses as its IO thread. | 61 // The task runner that this class uses as its IO thread. |
62 scoped_refptr<base::MessageLoopProxy> io_thread_; | 62 scoped_refptr<base::SingleThreadTaskRunner> io_thread_; |
63 DISALLOW_COPY_AND_ASSIGN(SigninManagerCookieHelper); | 63 DISALLOW_COPY_AND_ASSIGN(SigninManagerCookieHelper); |
64 }; | 64 }; |
65 | 65 |
66 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_MANAGER_COOKIE_HELPER_H_ | 66 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_MANAGER_COOKIE_HELPER_H_ |
OLD | NEW |