Fix infinite recursion on hiding panel when created during fullscreen mode.
[chromium-blink-merge.git] / components / signin / core / browser / signin_manager_cookie_helper.cc
blob8a6c355998a4e1b7afa6ab13f3d9f75f0a4b76ca
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
3 // found in the LICENSE file.
5 #include "components/signin/core/browser/signin_manager_cookie_helper.h"
7 #include <vector>
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "google_apis/gaia/gaia_urls.h"
11 #include "net/cookies/cookie_monster.h"
12 #include "net/url_request/url_request_context.h"
14 SigninManagerCookieHelper::SigninManagerCookieHelper(
15 net::URLRequestContextGetter* request_context_getter,
16 scoped_refptr<base::MessageLoopProxy> ui_thread,
17 scoped_refptr<base::MessageLoopProxy> io_thread)
18 : request_context_getter_(request_context_getter),
19 ui_thread_(ui_thread),
20 io_thread_(io_thread) {
21 DCHECK(ui_thread_->BelongsToCurrentThread());
24 SigninManagerCookieHelper::~SigninManagerCookieHelper() {
27 void SigninManagerCookieHelper::StartFetchingGaiaCookiesOnUIThread(
28 const base::Callback<void(const net::CookieList& cookies)>& callback) {
29 StartFetchingCookiesOnUIThread(
30 GaiaUrls::GetInstance()->gaia_url(), callback);
33 void SigninManagerCookieHelper::StartFetchingCookiesOnUIThread(
34 const GURL& url,
35 const base::Callback<void(const net::CookieList& cookies)>& callback) {
36 DCHECK(ui_thread_->BelongsToCurrentThread());
37 DCHECK(!callback.is_null());
38 DCHECK(completion_callback_.is_null());
40 completion_callback_ = callback;
41 io_thread_->PostTask(FROM_HERE,
42 base::Bind(&SigninManagerCookieHelper::FetchCookiesOnIOThread,
43 this,
44 url));
47 void SigninManagerCookieHelper::FetchCookiesOnIOThread(const GURL& url) {
48 DCHECK(io_thread_->BelongsToCurrentThread());
50 scoped_refptr<net::CookieMonster> cookie_monster =
51 request_context_getter_->GetURLRequestContext()->
52 cookie_store()->GetCookieMonster();
53 if (cookie_monster.get()) {
54 cookie_monster->GetAllCookiesForURLAsync(
55 url, base::Bind(&SigninManagerCookieHelper::OnCookiesFetched, this));
56 } else {
57 OnCookiesFetched(net::CookieList());
61 void SigninManagerCookieHelper::OnCookiesFetched(
62 const net::CookieList& cookies) {
63 DCHECK(io_thread_->BelongsToCurrentThread());
64 ui_thread_->PostTask(FROM_HERE,
65 base::Bind(&SigninManagerCookieHelper::NotifyOnUIThread, this, cookies));
68 void SigninManagerCookieHelper::NotifyOnUIThread(
69 const net::CookieList& cookies) {
70 DCHECK(ui_thread_->BelongsToCurrentThread());
71 base::ResetAndReturn(&completion_callback_).Run(cookies);