OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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/string_fetcher.h" |
| 6 |
| 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" |
| 10 #include "chrome/browser/profile_manager.h" |
| 11 #include "googleurl/src/gurl.h" |
| 12 |
| 13 StringFetcher::StringFetcher(const std::string& url_str) { |
| 14 GURL url(url_str); |
| 15 if (url.SchemeIsFile()) { |
| 16 LOG(INFO) << url.path(); |
| 17 if (file_util::ReadFileToString(FilePath(url.path()), &result_)) { |
| 18 response_code_ = 200; |
| 19 } else { |
| 20 response_code_ = 404; |
| 21 } |
| 22 return; |
| 23 } |
| 24 url_fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this)); |
| 25 url_fetcher_->set_request_context( |
| 26 ProfileManager::GetDefaultProfile()->GetRequestContext()); |
| 27 url_fetcher_->Start(); |
| 28 } |
| 29 |
| 30 void StringFetcher::OnURLFetchComplete(const URLFetcher* source, |
| 31 const GURL& url, |
| 32 const URLRequestStatus& status, |
| 33 int response_code, |
| 34 const ResponseCookies& cookies, |
| 35 const std::string& data) { |
| 36 response_code_ = response_code; |
| 37 if (response_code != 200) { |
| 38 LOG(ERROR) << "Response code is " << response_code; |
| 39 LOG(ERROR) << "Url is " << url.spec(); |
| 40 LOG(ERROR) << "Data is " << data; |
| 41 return; |
| 42 } |
| 43 result_ = data; |
| 44 } |
OLD | NEW |