• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "chrome/browser/chromeos/login/cookie_fetcher.h"
6 
7 #include "base/command_line.h"
8 #include "base/path_service.h"
9 #include "chrome/browser/chromeos/boot_times_loader.h"
10 #include "chrome/browser/chromeos/login/client_login_response_handler.h"
11 #include "chrome/browser/chromeos/login/issue_response_handler.h"
12 #include "chrome/browser/chromeos/login/login_utils.h"
13 #include "chrome/browser/net/chrome_url_request_context.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/net/url_fetcher.h"
18 #include "net/url_request/url_request_status.h"
19 
20 namespace chromeos {
21 
CookieFetcher(Profile * profile)22 CookieFetcher::CookieFetcher(Profile* profile) : profile_(profile) {
23   CHECK(profile_);
24   client_login_handler_.reset(
25       new ClientLoginResponseHandler(profile_->GetRequestContext()));
26   issue_handler_.reset(
27       new IssueResponseHandler(profile_->GetRequestContext()));
28 }
29 
AttemptFetch(const std::string & credentials)30 void CookieFetcher::AttemptFetch(const std::string& credentials) {
31   VLOG(1) << "Getting auth token...";
32   fetcher_.reset(client_login_handler_->Handle(credentials, this));
33 }
34 
OnURLFetchComplete(const URLFetcher * source,const GURL & url,const net::URLRequestStatus & status,int response_code,const ResponseCookies & cookies,const std::string & data)35 void CookieFetcher::OnURLFetchComplete(const URLFetcher* source,
36                                        const GURL& url,
37                                        const net::URLRequestStatus& status,
38                                        int response_code,
39                                        const ResponseCookies& cookies,
40                                        const std::string& data) {
41   if (status.is_success() && response_code == kHttpSuccess) {
42     if (issue_handler_->CanHandle(url)) {
43       VLOG(1) << "Handling auth token";
44       fetcher_.reset(issue_handler_->Handle(data, this));
45       return;
46     }
47   }
48   BootTimesLoader::Get()->AddLoginTimeMarker("CookiesFetched", false);
49   delete this;
50 }
51 
52 }  // namespace chromeos
53