Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / signin / signin_manager_cookie_helper.cc
blob642d306e6f27118c9f91d65866d8526dfc323720
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 #include "chrome/browser/signin/signin_manager_cookie_helper.h"
7 #include <vector>
9 #include "content/public/browser/browser_thread.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 using content::BrowserThread;
16 SigninManagerCookieHelper::SigninManagerCookieHelper(
17 net::URLRequestContextGetter* request_context_getter)
18 : request_context_getter_(request_context_getter) {
19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
22 SigninManagerCookieHelper::~SigninManagerCookieHelper() {
25 void SigninManagerCookieHelper::StartFetchingGaiaCookiesOnUIThread(
26 const base::Callback<void(const net::CookieList& cookies)>& callback) {
27 StartFetchingCookiesOnUIThread(
28 GaiaUrls::GetInstance()->gaia_url(), callback);
31 void SigninManagerCookieHelper::StartFetchingCookiesOnUIThread(
32 const GURL& url,
33 const base::Callback<void(const net::CookieList& cookies)>& callback) {
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
35 DCHECK(!callback.is_null());
36 DCHECK(completion_callback_.is_null());
38 completion_callback_ = callback;
39 BrowserThread::PostTask(
40 BrowserThread::IO, FROM_HERE,
41 base::Bind(&SigninManagerCookieHelper::FetchCookiesOnIOThread, this,
42 url));
45 void SigninManagerCookieHelper::FetchCookiesOnIOThread(const GURL& url) {
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
48 scoped_refptr<net::CookieMonster> cookie_monster =
49 request_context_getter_->GetURLRequestContext()->
50 cookie_store()->GetCookieMonster();
51 if (cookie_monster.get()) {
52 cookie_monster->GetAllCookiesForURLAsync(
53 url, base::Bind(&SigninManagerCookieHelper::OnCookiesFetched, this));
54 } else {
55 OnCookiesFetched(net::CookieList());
59 void SigninManagerCookieHelper::OnCookiesFetched(
60 const net::CookieList& cookies) {
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
62 BrowserThread::PostTask(
63 BrowserThread::UI, FROM_HERE,
64 base::Bind(&SigninManagerCookieHelper::NotifyOnUIThread, this, cookies));
67 void SigninManagerCookieHelper::NotifyOnUIThread(
68 const net::CookieList& cookies) {
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
70 base::ResetAndReturn(&completion_callback_).Run(cookies);