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 |
| 16 DCHECK(url.is_valid()); |
| 17 if (!url.is_valid()) { |
| 18 response_code_ = 404; |
| 19 return; |
| 20 } |
| 21 |
| 22 if (url.SchemeIsFile()) { |
| 23 LOG(INFO) << url.path(); |
| 24 if (file_util::ReadFileToString(FilePath(url.path()), &result_)) { |
| 25 response_code_ = 200; |
| 26 } else { |
| 27 response_code_ = 404; |
| 28 } |
| 29 return; |
| 30 } |
| 31 url_fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this)); |
| 32 url_fetcher_->set_request_context( |
| 33 ProfileManager::GetDefaultProfile()->GetRequestContext()); |
| 34 url_fetcher_->Start(); |
| 35 } |
| 36 |
| 37 void StringFetcher::OnURLFetchComplete(const URLFetcher* source, |
| 38 const GURL& url, |
| 39 const URLRequestStatus& status, |
| 40 int response_code, |
| 41 const ResponseCookies& cookies, |
| 42 const std::string& data) { |
| 43 response_code_ = response_code; |
| 44 if (response_code != 200) { |
| 45 LOG(ERROR) << "Response code is " << response_code; |
| 46 LOG(ERROR) << "Url is " << url.spec(); |
| 47 LOG(ERROR) << "Data is " << data; |
| 48 return; |
| 49 } |
| 50 result_ = data; |
| 51 } |
OLD | NEW |