| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/web/public/test/response_providers/file_based_response_provider_im
pl.h" | 5 #include "ios/web/public/test/response_providers/file_based_response_provider_im
pl.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "ios/web/public/test/response_providers/response_provider.h" | 8 #include "ios/web/public/test/response_providers/response_provider.h" |
| 9 #include "url/gurl.h" | 9 #include "url/gurl.h" |
| 10 | 10 |
| 11 namespace web { | 11 namespace web { |
| 12 | 12 |
| 13 FileBasedResponseProviderImpl::FileBasedResponseProviderImpl( | 13 FileBasedResponseProviderImpl::FileBasedResponseProviderImpl( |
| 14 const base::FilePath& path) | 14 const base::FilePath& path) |
| 15 : path_(path) {} | 15 : path_(path) {} |
| 16 | 16 |
| 17 FileBasedResponseProviderImpl::~FileBasedResponseProviderImpl() {} | 17 FileBasedResponseProviderImpl::~FileBasedResponseProviderImpl() {} |
| 18 | 18 |
| 19 bool FileBasedResponseProviderImpl::CanHandleRequest( | 19 bool FileBasedResponseProviderImpl::CanHandleRequest( |
| 20 const ResponseProvider::Request& request) { | 20 const ResponseProvider::Request& request) { |
| 21 return base::PathExists(BuildTargetPath(request.url)); | 21 return base::PathExists(BuildTargetPath(request.url)); |
| 22 } | 22 } |
| 23 | 23 |
| 24 base::FilePath FileBasedResponseProviderImpl::BuildTargetPath(const GURL& url) { | 24 base::FilePath FileBasedResponseProviderImpl::BuildTargetPath(const GURL& url) { |
| 25 base::FilePath result = path_; | 25 base::FilePath result = path_; |
| 26 const std::string kLocalhostHost = "localhost"; | 26 const std::string kLocalhostHost = "localhost"; |
| 27 if (url.host() != kLocalhostHost) { | 27 if (url.host() != kLocalhostHost) { |
| 28 result = result.Append(url.host()); | 28 result = result.Append(url.host()); |
| 29 } | 29 } |
| 30 std::string url_path = url.path(); | 30 std::string url_path = url.path().as_string(); |
| 31 // Remove the leading slash in url path. | 31 // Remove the leading slash in url path. |
| 32 if (url_path.length() > 0 && url_path[0] == '/') { | 32 if (url_path.length() > 0 && url_path[0] == '/') { |
| 33 url_path.erase(0, 1); | 33 url_path.erase(0, 1); |
| 34 } | 34 } |
| 35 if (!url_path.empty()) | 35 if (!url_path.empty()) |
| 36 result = result.Append(url_path); | 36 result = result.Append(url_path); |
| 37 return result; | 37 return result; |
| 38 } | 38 } |
| 39 | 39 |
| 40 } // namespace web | 40 } // namespace web |
| OLD | NEW |