| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/shell/loader.h" | 5 #include "mojo/shell/loader.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "mojo/shell/switches.h" | 10 #include "mojo/shell/switches.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 Loader::Job::~Job() { | 28 Loader::Job::~Job() { |
| 29 } | 29 } |
| 30 | 30 |
| 31 void Loader::Job::OnURLFetchComplete(const net::URLFetcher* source) { | 31 void Loader::Job::OnURLFetchComplete(const net::URLFetcher* source) { |
| 32 net::URLRequestStatus status = source->GetStatus(); | 32 net::URLRequestStatus status = source->GetStatus(); |
| 33 if (!status.is_success()) { | 33 if (!status.is_success()) { |
| 34 LOG(ERROR) << "URL fetch didn't succeed: status = " << status.status() | 34 LOG(ERROR) << "URL fetch didn't succeed: status = " << status.status() |
| 35 << ", error = " << status.error(); | 35 << ", error = " << status.error(); |
| 36 } else if (source->GetResponseCode() != 200) { | 36 } else if (source->GetResponseCode() != 200) { |
| 37 LOG(ERROR) << "HTTP response not OK: code = " << source->GetResponseCode(); | 37 // Note: We may not have a response code (e.g., if it wasn't an http: URL). |
| 38 LOG(WARNING) << "HTTP response not OK: code = " |
| 39 << source->GetResponseCode(); |
| 38 } | 40 } |
| 39 // TODO: Do something else in the error cases? | 41 // TODO: Do something else in the error cases? |
| 40 | 42 |
| 41 base::FilePath app_path; | 43 base::FilePath app_path; |
| 42 source->GetResponseAsFilePath(true, &app_path); | 44 source->GetResponseAsFilePath(true, &app_path); |
| 43 std::string mime_type; | 45 std::string mime_type; |
| 44 std::string* passed_mime_type = | 46 // We may not have response headers (e.g., if it was a file: URL). |
| 45 source->GetResponseHeaders()->GetMimeType(&mime_type) ? &mime_type : NULL; | 47 if (source->GetResponseHeaders()) |
| 46 delegate_->DidCompleteLoad(source->GetURL(), app_path, passed_mime_type); | 48 source->GetResponseHeaders()->GetMimeType(&mime_type); |
| 49 delegate_->DidCompleteLoad(source->GetURL(), |
| 50 app_path, |
| 51 mime_type.empty() ? NULL : &mime_type); |
| 47 } | 52 } |
| 48 | 53 |
| 49 Loader::Loader(base::SingleThreadTaskRunner* network_runner, | 54 Loader::Loader(base::SingleThreadTaskRunner* network_runner, |
| 50 base::SingleThreadTaskRunner* file_runner, | 55 base::SingleThreadTaskRunner* file_runner, |
| 51 base::MessageLoopProxy* cache_runner, | 56 base::MessageLoopProxy* cache_runner, |
| 52 scoped_ptr<net::NetworkDelegate> network_delegate, | 57 scoped_ptr<net::NetworkDelegate> network_delegate, |
| 53 base::FilePath base_path) | 58 base::FilePath base_path) |
| 54 : file_runner_(file_runner), | 59 : file_runner_(file_runner), |
| 55 url_request_context_getter_(new URLRequestContextGetter( | 60 url_request_context_getter_(new URLRequestContextGetter( |
| 56 base_path, | 61 base_path, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 79 #endif | 84 #endif |
| 80 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 85 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 81 switches::kDisableCache)) | 86 switches::kDisableCache)) |
| 82 job->fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 87 job->fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 83 job->fetcher_->Start(); | 88 job->fetcher_->Start(); |
| 84 return job.Pass(); | 89 return job.Pass(); |
| 85 } | 90 } |
| 86 | 91 |
| 87 } // namespace shell | 92 } // namespace shell |
| 88 } // namespace mojo | 93 } // namespace mojo |
| OLD | NEW |