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. 4 5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_COOKIE_HELPER_H_ 6 #define CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_COOKIE_HELPER_H_ 7 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" 12 13 namespace net { 14 class URLRequestContextGetter; 15 } 16 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> { 21 public: 22 explicit SigninManagerCookieHelper( 23 net::URLRequestContextGetter* request_context_getter); 24 25 // Starts fetching gaia cookies, which will notify its completion via 26 // callback. 27 void StartFetchingGaiaCookiesOnUIThread( 28 const base::Callback<void(const net::CookieList& cookies)>& callback); 29 30 // Starts fetching cookies for the given URL. 31 void StartFetchingCookiesOnUIThread( 32 const GURL& url, 33 const base::Callback<void(const net::CookieList& cookies)>& callback); 34 35 private: 36 friend class base::RefCountedThreadSafe<SigninManagerCookieHelper>; 37 ~SigninManagerCookieHelper(); 38 39 // Fetch cookies for the given URL. This must be called in the IO thread. 40 void FetchCookiesOnIOThread(const GURL& url); 41 42 // Callback for fetching cookies. This must be called in the IO thread. 43 void OnCookiesFetched(const net::CookieList& cookies); 44 45 // Notifies the completion callback. This must be called in the UI thread. 46 void NotifyOnUIThread(const net::CookieList& cookies); 47 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_; 51 52 DISALLOW_COPY_AND_ASSIGN(SigninManagerCookieHelper); 53 }; 54 55 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_COOKIE_HELPER_H_ 56