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