13f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file. 4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_COOKIE_FETCHER_H_ 6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define CHROME_BROWSER_CHROMEOS_LOGIN_COOKIE_FETCHER_H_ 73345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once 8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 9c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include <string> 10ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/memory/scoped_ptr.h" 11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/chromeos/login/auth_response_handler.h" 12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/chromeos/login/client_login_response_handler.h" 13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/chromeos/login/issue_response_handler.h" 14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/common/net/url_fetcher.h" 15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 1621d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsenclass Profile; 1721d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen 18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochnamespace chromeos { 19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Given a SID/LSID pair, this class will attempt to turn them into a 21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// full-fledged set of Google AuthN cookies. 22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// 23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// A CookieFetcher manages its own lifecycle. It deletes itself once it's 24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// done attempting to fetch URLs. 25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass CookieFetcher : public URLFetcher::Delegate { 26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public: 27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // |profile| is the Profile whose cookie jar you want the cookies in. 28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch explicit CookieFetcher(Profile* profile); 29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // |profile| is the Profile whose cookie jar you want the cookies in. 31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Takes ownership of |cl_handler|, |i_handler|, and |launcher|. 32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch CookieFetcher(Profile* profile, 33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch AuthResponseHandler* cl_handler, 34731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick AuthResponseHandler* i_handler) 35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch : profile_(profile), 36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch client_login_handler_(cl_handler), 37731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick issue_handler_(i_handler) { 38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } 39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Given a newline-delineated SID/LSID pair of Google cookies (like 41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // those that come back from ClientLogin), try to use them to fetch 42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // a full-fledged set of Google AuthN cookies. These cookies will wind up 43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // stored in the cookie jar associated with |profile_|, if we get them. 44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Either way, we end up by calling launcher_->DoLaunch() 45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void AttemptFetch(const std::string& credentials); 46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Overloaded from URLFetcher::Delegate. 48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void OnURLFetchComplete(const URLFetcher* source, 49c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const GURL& url, 503f50c38dc070f4bb515c1b64450dae14f316474eKristian Monsen const net::URLRequestStatus& status, 51c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch int response_code, 52c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const ResponseCookies& cookies, 53c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const std::string& data); 54c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 55c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private: 56c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual ~CookieFetcher() {} 57c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 58c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch scoped_ptr<URLFetcher> fetcher_; 59c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch Profile* profile_; 60c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch scoped_ptr<AuthResponseHandler> client_login_handler_; 61c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch scoped_ptr<AuthResponseHandler> issue_handler_; 62c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 63c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch DISALLOW_COPY_AND_ASSIGN(CookieFetcher); 64c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}; 65c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 66c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} // namespace chromeos 67c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 68c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif // CHROME_BROWSER_CHROMEOS_LOGIN_COOKIE_FETCHER_H_ 69