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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_COOKIE_HELPER_H_
6 #define CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_COOKIE_HELPER_H_
8 #include "base/callback_helpers.h"
9 #include "base/memory/ref_counted.h"
10 #include "net/cookies/canonical_cookie.h"
11 #include "net/url_request/url_request_context_getter.h"
14 class URLRequestContextGetter
;
17 // This class fetches GAIA cookie on IO thread on behalf of SigninManager which
18 // only lives on the UI thread.
19 class SigninManagerCookieHelper
20 : public base::RefCountedThreadSafe
<SigninManagerCookieHelper
> {
22 explicit SigninManagerCookieHelper(
23 net::URLRequestContextGetter
* request_context_getter
);
25 // Starts fetching gaia cookies, which will notify its completion via
27 void StartFetchingGaiaCookiesOnUIThread(
28 const base::Callback
<void(const net::CookieList
& cookies
)>& callback
);
30 // Starts fetching cookies for the given URL.
31 void StartFetchingCookiesOnUIThread(
33 const base::Callback
<void(const net::CookieList
& cookies
)>& callback
);
36 friend class base::RefCountedThreadSafe
<SigninManagerCookieHelper
>;
37 ~SigninManagerCookieHelper();
39 // Fetch cookies for the given URL. This must be called in the IO thread.
40 void FetchCookiesOnIOThread(const GURL
& url
);
42 // Callback for fetching cookies. This must be called in the IO thread.
43 void OnCookiesFetched(const net::CookieList
& cookies
);
45 // Notifies the completion callback. This must be called in the UI thread.
46 void NotifyOnUIThread(const net::CookieList
& cookies
);
48 scoped_refptr
<net::URLRequestContextGetter
> request_context_getter_
;
49 // This only mutates on the UI thread.
50 base::Callback
<void(const net::CookieList
& cookies
)> completion_callback_
;
52 DISALLOW_COPY_AND_ASSIGN(SigninManagerCookieHelper
);
55 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_COOKIE_HELPER_H_