Logo Search packages:      
Sourcecode: chromium-browser version File versions  Download package


// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


#include <string>
#include "base/scoped_ptr.h"
#include "chrome/browser/chromeos/login/auth_response_handler.h"
#include "chrome/browser/chromeos/login/client_login_response_handler.h"
#include "chrome/browser/chromeos/login/issue_response_handler.h"
#include "chrome/browser/net/url_fetcher.h"
#include "chrome/browser/profile.h"

namespace chromeos {

// Given a SID/LSID pair, this class will attempt to turn them into a
// full-fledged set of Google AuthN cookies.
// A CookieFetcher manages its own lifecycle.  It deletes itself once it's
// done attempting to fetch URLs.
class CookieFetcher : public URLFetcher::Delegate {
  // This class is a very thin wrapper around posting a task to the UI thread
  // to call LoginUtils::DoBrowserLaunch().  It's here to allow mocking.
  // In normal usage, instances of this class are owned by a CookieFetcher.
  class Delegate {
    Delegate() {}
    virtual ~Delegate() {}
    virtual void DoLaunch(Profile* profile) = 0;

  // |profile| is the Profile whose cookie jar you want the cookies in.
  explicit CookieFetcher(Profile* profile);

  // |profile| is the Profile whose cookie jar you want the cookies in.
  // Takes ownership of |cl_handler|, |i_handler|, and |launcher|.
  CookieFetcher(Profile* profile,
                AuthResponseHandler* cl_handler,
                AuthResponseHandler* i_handler,
                Delegate* launcher)
      : profile_(profile),
        launcher_(launcher) {

  // Given a newline-delineated SID/LSID pair of Google cookies (like
  // those that come back from ClientLogin), try to use them to fetch
  // a full-fledged set of Google AuthN cookies.  These cookies will wind up
  // stored in the cookie jar associated with |profile_|, if we get them.
  // Either way, we end up by calling launcher_->DoLaunch()
  void AttemptFetch(const std::string& credentials);

  // Overloaded from URLFetcher::Delegate.
  virtual void OnURLFetchComplete(const URLFetcher* source,
                                  const GURL& url,
                                  const URLRequestStatus& status,
                                  int response_code,
                                  const ResponseCookies& cookies,
                                  const std::string& data);

  class DelegateImpl : public Delegate {
    DelegateImpl() {}
    ~DelegateImpl() {}
    void DoLaunch(Profile* profile);

  virtual ~CookieFetcher() {}

  scoped_ptr<URLFetcher> fetcher_;
  Profile* profile_;
  scoped_ptr<AuthResponseHandler> client_login_handler_;
  scoped_ptr<AuthResponseHandler> issue_handler_;
  scoped_ptr<Delegate> launcher_;


}  // namespace chromeos


Generated by  Doxygen 1.6.0   Back to index