summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/base/net_util.cc12
-rw-r--r--net/base/net_util.h4
-rw-r--r--net/base/net_util_unittest.cc95
-rw-r--r--net/base/upload_data.h13
-rw-r--r--net/base/upload_data_stream.cc12
-rw-r--r--net/url_request/url_request.cc4
-rw-r--r--net/url_request/url_request.h5
-rw-r--r--net/url_request/url_request_file_job.cc2
-rw-r--r--net/url_request/url_request_unittest.cc25
9 files changed, 80 insertions, 92 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 7865b4e..9610e40 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -673,10 +673,6 @@ GURL FilePathToFileURL(const FilePath& path) {
return GURL(url_string);
}
-GURL FilePathToFileURL(const std::wstring& path_str) {
- return FilePathToFileURL(FilePath::FromWStringHack(path_str));
-}
-
std::wstring GetSpecificHeader(const std::wstring& headers,
const std::wstring& name) {
return GetSpecificHeaderT(headers, name);
@@ -945,14 +941,6 @@ int SetNonBlocking(int fd) {
#endif
}
-// Deprecated.
-bool FileURLToFilePath(const GURL& gurl, std::wstring* file_path) {
- FilePath path;
- bool rv = FileURLToFilePath(gurl, &path);
- *file_path = path.ToWStringHack();
- return rv;
-}
-
bool GetHostAndPort(std::string::const_iterator host_and_port_begin,
std::string::const_iterator host_and_port_end,
std::string* host,
diff --git a/net/base/net_util.h b/net/base/net_util.h
index 3305f49..2ad81bf 100644
--- a/net/base/net_util.h
+++ b/net/base/net_util.h
@@ -28,16 +28,12 @@ namespace net {
// Given the full path to a file name, creates a file: URL. The returned URL
// may not be valid if the input is malformed.
GURL FilePathToFileURL(const FilePath& path);
-// Deprecated temporary compatibility function.
-GURL FilePathToFileURL(const std::wstring& file_path);
// Converts a file: URL back to a filename that can be passed to the OS. The
// file URL must be well-formed (GURL::is_valid() must return true); we don't
// handle degenerate cases here. Returns true on success, false if it isn't a
// valid file URL. On failure, *file_path will be empty.
bool FileURLToFilePath(const GURL& url, FilePath* file_path);
-// Deprecated temporary compatibility function.
-bool FileURLToFilePath(const GURL& url, std::wstring* file_path);
// Split an input of the form <host>[":"<port>] into its consitituent parts.
// Saves the result into |*host| and |*port|. If the input did not have
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index 423c62c..f9bc7f7 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/basictypes.h"
+#include "base/file_path.h"
#include "base/string_util.h"
#include "base/time.h"
#include "googleurl/src/gurl.h"
@@ -22,7 +23,7 @@ class NetUtilTest : public testing::Test {
struct FileCase {
const wchar_t* file;
- const wchar_t* url;
+ const char* url;
};
struct HeaderCase {
@@ -114,76 +115,76 @@ TEST(NetUtilTest, FileURLConversion) {
// a list of test file names and the corresponding URLs
const FileCase round_trip_cases[] = {
#if defined(OS_WIN)
- {L"C:\\foo\\bar.txt", L"file:///C:/foo/bar.txt"},
+ {L"C:\\foo\\bar.txt", "file:///C:/foo/bar.txt"},
{L"\\\\some computer\\foo\\bar.txt",
- L"file://some%20computer/foo/bar.txt"}, // UNC
+ "file://some%20computer/foo/bar.txt"}, // UNC
{L"D:\\Name;with%some symbols*#",
- L"file:///D:/Name%3Bwith%25some%20symbols*%23"},
+ "file:///D:/Name%3Bwith%25some%20symbols*%23"},
{L"D:\\Chinese\\\x6240\x6709\x4e2d\x6587\x7f51\x9875.doc",
- L"file:///D:/Chinese/%E6%89%80%E6%9C%89%E4%B8%AD%E6%96%87%E7%BD%91"
- L"%E9%A1%B5.doc"},
+ "file:///D:/Chinese/%E6%89%80%E6%9C%89%E4%B8%AD%E6%96%87%E7%BD%91"
+ "%E9%A1%B5.doc"},
#elif defined(OS_POSIX)
- {L"/foo/bar.txt", L"file:///foo/bar.txt"},
- {L"/foo/BAR.txt", L"file:///foo/BAR.txt"},
- {L"/C:/foo/bar.txt", L"file:///C:/foo/bar.txt"},
- {L"/some computer/foo/bar.txt", L"file:///some%20computer/foo/bar.txt"},
- {L"/Name;with%some symbols*#", L"file:///Name%3Bwith%25some%20symbols*%23"},
+ {L"/foo/bar.txt", "file:///foo/bar.txt"},
+ {L"/foo/BAR.txt", "file:///foo/BAR.txt"},
+ {L"/C:/foo/bar.txt", "file:///C:/foo/bar.txt"},
+ {L"/some computer/foo/bar.txt", "file:///some%20computer/foo/bar.txt"},
+ {L"/Name;with%some symbols*#", "file:///Name%3Bwith%25some%20symbols*%23"},
{L"/Chinese/\x6240\x6709\x4e2d\x6587\x7f51\x9875.doc",
- L"file:///Chinese/%E6%89%80%E6%9C%89%E4%B8%AD%E6%96%87%E7%BD"
- L"%91%E9%A1%B5.doc"},
+ "file:///Chinese/%E6%89%80%E6%9C%89%E4%B8%AD%E6%96%87%E7%BD"
+ "%91%E9%A1%B5.doc"},
#endif
};
// First, we'll test that we can round-trip all of the above cases of URLs
- std::wstring output;
+ FilePath output;
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(round_trip_cases); i++) {
// convert to the file URL
- GURL file_url(net::FilePathToFileURL(round_trip_cases[i].file));
- EXPECT_EQ(std::wstring(round_trip_cases[i].url),
- UTF8ToWide(file_url.spec()));
+ GURL file_url(net::FilePathToFileURL(
+ FilePath::FromWStringHack(round_trip_cases[i].file)));
+ EXPECT_EQ(round_trip_cases[i].url, file_url.spec());
// Back to the filename.
EXPECT_TRUE(net::FileURLToFilePath(file_url, &output));
- EXPECT_EQ(std::wstring(round_trip_cases[i].file), output);
+ EXPECT_EQ(round_trip_cases[i].file, output.ToWStringHack());
}
// Test that various file: URLs get decoded into the correct file type
FileCase url_cases[] = {
#if defined(OS_WIN)
- {L"C:\\foo\\bar.txt", L"file:c|/foo\\bar.txt"},
- {L"C:\\foo\\bar.txt", L"file:/c:/foo/bar.txt"},
- {L"\\\\foo\\bar.txt", L"file://foo\\bar.txt"},
- {L"C:\\foo\\bar.txt", L"file:///c:/foo/bar.txt"},
- {L"\\\\foo\\bar.txt", L"file:////foo\\bar.txt"},
- {L"\\\\foo\\bar.txt", L"file:/foo/bar.txt"},
- {L"\\\\foo\\bar.txt", L"file://foo\\bar.txt"},
- {L"C:\\foo\\bar.txt", L"file:\\\\\\c:/foo/bar.txt"},
+ {L"C:\\foo\\bar.txt", "file:c|/foo\\bar.txt"},
+ {L"C:\\foo\\bar.txt", "file:/c:/foo/bar.txt"},
+ {L"\\\\foo\\bar.txt", "file://foo\\bar.txt"},
+ {L"C:\\foo\\bar.txt", "file:///c:/foo/bar.txt"},
+ {L"\\\\foo\\bar.txt", "file:////foo\\bar.txt"},
+ {L"\\\\foo\\bar.txt", "file:/foo/bar.txt"},
+ {L"\\\\foo\\bar.txt", "file://foo\\bar.txt"},
+ {L"C:\\foo\\bar.txt", "file:\\\\\\c:/foo/bar.txt"},
#elif defined(OS_POSIX)
- {L"/c:/foo/bar.txt", L"file:/c:/foo/bar.txt"},
- {L"/c:/foo/bar.txt", L"file:///c:/foo/bar.txt"},
- {L"/foo/bar.txt", L"file:/foo/bar.txt"},
- {L"/c:/foo/bar.txt", L"file:\\\\\\c:/foo/bar.txt"},
- {L"/foo/bar.txt", L"file:foo/bar.txt"},
- {L"/bar.txt", L"file://foo/bar.txt"},
- {L"/foo/bar.txt", L"file:///foo/bar.txt"},
- {L"/foo/bar.txt", L"file:////foo/bar.txt"},
- {L"/foo/bar.txt", L"file:////foo//bar.txt"},
- {L"/foo/bar.txt", L"file:////foo///bar.txt"},
- {L"/foo/bar.txt", L"file:////foo////bar.txt"},
- {L"/c:/foo/bar.txt", L"file:\\\\\\c:/foo/bar.txt"},
- {L"/c:/foo/bar.txt", L"file:c:/foo/bar.txt"},
+ {L"/c:/foo/bar.txt", "file:/c:/foo/bar.txt"},
+ {L"/c:/foo/bar.txt", "file:///c:/foo/bar.txt"},
+ {L"/foo/bar.txt", "file:/foo/bar.txt"},
+ {L"/c:/foo/bar.txt", "file:\\\\\\c:/foo/bar.txt"},
+ {L"/foo/bar.txt", "file:foo/bar.txt"},
+ {L"/bar.txt", "file://foo/bar.txt"},
+ {L"/foo/bar.txt", "file:///foo/bar.txt"},
+ {L"/foo/bar.txt", "file:////foo/bar.txt"},
+ {L"/foo/bar.txt", "file:////foo//bar.txt"},
+ {L"/foo/bar.txt", "file:////foo///bar.txt"},
+ {L"/foo/bar.txt", "file:////foo////bar.txt"},
+ {L"/c:/foo/bar.txt", "file:\\\\\\c:/foo/bar.txt"},
+ {L"/c:/foo/bar.txt", "file:c:/foo/bar.txt"},
// We get these wrong because GURL turns back slashes into forward
// slashes.
- //{L"/foo%5Cbar.txt", L"file://foo\\bar.txt"},
- //{L"/c|/foo%5Cbar.txt", L"file:c|/foo\\bar.txt"},
- //{L"/foo%5Cbar.txt", L"file://foo\\bar.txt"},
- //{L"/foo%5Cbar.txt", L"file:////foo\\bar.txt"},
- //{L"/foo%5Cbar.txt", L"file://foo\\bar.txt"},
+ //{L"/foo%5Cbar.txt", "file://foo\\bar.txt"},
+ //{L"/c|/foo%5Cbar.txt", "file:c|/foo\\bar.txt"},
+ //{L"/foo%5Cbar.txt", "file://foo\\bar.txt"},
+ //{L"/foo%5Cbar.txt", "file:////foo\\bar.txt"},
+ //{L"/foo%5Cbar.txt", "file://foo\\bar.txt"},
#endif
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_cases); i++) {
- net::FileURLToFilePath(GURL(WideToUTF8(url_cases[i].url)), &output);
- EXPECT_EQ(std::wstring(url_cases[i].file), output);
+ net::FileURLToFilePath(GURL(url_cases[i].url), &output);
+ EXPECT_EQ(url_cases[i].file, output.ToWStringHack());
}
// Here, we test that UTF-8 encoded strings get decoded properly, even when
@@ -199,7 +200,7 @@ TEST(NetUtilTest, FileURLConversion) {
L"\x96\x87\xe7\xbd\x91\xe9\xa1\xb5.doc";
#endif
EXPECT_TRUE(net::FileURLToFilePath(GURL(WideToUTF8(utf8)), &output));
- EXPECT_EQ(std::wstring(wide), output);
+ EXPECT_EQ(wide, output.ToWStringHack());
// Unfortunately, UTF8ToWide discards invalid UTF8 input.
#ifdef BUG_878908_IS_FIXED
diff --git a/net/base/upload_data.h b/net/base/upload_data.h
index 231b40b..56a1339 100644
--- a/net/base/upload_data.h
+++ b/net/base/upload_data.h
@@ -8,6 +8,7 @@
#include <string>
#include <vector>
+#include "base/file_path.h"
#include "base/ref_counted.h"
namespace net {
@@ -29,7 +30,7 @@ class UploadData : public base::RefCounted<UploadData> {
Type type() const { return type_; }
const std::vector<char>& bytes() const { return bytes_; }
- const std::wstring& file_path() const { return file_path_; }
+ const FilePath& file_path() const { return file_path_; }
uint64 file_range_offset() const { return file_range_offset_; }
uint64 file_range_length() const { return file_range_length_; }
@@ -38,11 +39,11 @@ class UploadData : public base::RefCounted<UploadData> {
bytes_.assign(bytes, bytes + bytes_len);
}
- void SetToFilePath(const std::wstring& path) {
+ void SetToFilePath(const FilePath& path) {
SetToFilePathRange(path, 0, kuint64max);
}
- void SetToFilePathRange(const std::wstring& path,
+ void SetToFilePathRange(const FilePath& path,
uint64 offset, uint64 length) {
type_ = TYPE_FILE;
file_path_ = path;
@@ -57,7 +58,7 @@ class UploadData : public base::RefCounted<UploadData> {
private:
Type type_;
std::vector<char> bytes_;
- std::wstring file_path_;
+ FilePath file_path_;
uint64 file_range_offset_;
uint64 file_range_length_;
};
@@ -69,12 +70,12 @@ class UploadData : public base::RefCounted<UploadData> {
}
}
- void AppendFile(const std::wstring& file_path) {
+ void AppendFile(const FilePath& file_path) {
elements_.push_back(Element());
elements_.back().SetToFilePath(file_path);
}
- void AppendFileRange(const std::wstring& file_path,
+ void AppendFileRange(const FilePath& file_path,
uint64 offset, uint64 length) {
elements_.push_back(Element());
elements_.back().SetToFilePathRange(file_path, offset, length);
diff --git a/net/base/upload_data_stream.cc b/net/base/upload_data_stream.cc
index 1438e20..0a41a13 100644
--- a/net/base/upload_data_stream.cc
+++ b/net/base/upload_data_stream.cc
@@ -65,19 +65,19 @@ void UploadDataStream::FillBuf() {
if (!next_element_stream_.IsOpen()) {
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ;
- int rv = next_element_stream_.Open(
- FilePath::FromWStringHack(element.file_path()), flags);
+ int rv = next_element_stream_.Open(element.file_path(), flags);
// If the file does not exist, that's technically okay.. we'll just
// upload an empty file. This is for consistency with Mozilla.
- DLOG_IF(WARNING, rv != OK) << "Failed to open \"" <<
- element.file_path() << "\" for reading: " << rv;
+ DLOG_IF(WARNING, rv != OK) << "Failed to open \""
+ << element.file_path().value()
+ << "\" for reading: " << rv;
next_element_remaining_ = 0; // Default to reading nothing.
if (rv == OK) {
uint64 offset = element.file_range_offset();
if (offset && next_element_stream_.Seek(FROM_BEGIN, offset) < 0) {
- DLOG(WARNING) << "Failed to seek \"" << element.file_path() <<
- "\" to offset: " << offset;
+ DLOG(WARNING) << "Failed to seek \"" << element.file_path().value()
+ << "\" to offset: " << offset;
} else {
next_element_remaining_ = element.file_range_length();
}
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index d6c34f1..acf70dd 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -94,9 +94,9 @@ void URLRequest::AppendBytesToUpload(const char* bytes, int bytes_len) {
upload_->AppendBytes(bytes, bytes_len);
}
-void URLRequest::AppendFileRangeToUpload(const wstring& file_path,
+void URLRequest::AppendFileRangeToUpload(const FilePath& file_path,
uint64 offset, uint64 length) {
- DCHECK(file_path.length() > 0 && length > 0);
+ DCHECK(file_path.value().length() > 0 && length > 0);
if (!upload_)
upload_ = new UploadData();
upload_->AppendFileRange(file_path, offset, length);
diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h
index d45e510..a075764 100644
--- a/net/url_request/url_request.h
+++ b/net/url_request/url_request.h
@@ -8,6 +8,7 @@
#include <string>
#include <vector>
+#include "base/file_path.h"
#include "base/logging.h"
#include "base/ref_counted.h"
#include "googleurl/src/gurl.h"
@@ -236,9 +237,9 @@ class URLRequest {
// When uploading a file range, length must be non-zero. If length
// exceeds the end-of-file, the upload is clipped at end-of-file.
void AppendBytesToUpload(const char* bytes, int bytes_len);
- void AppendFileRangeToUpload(const std::wstring& file_path,
+ void AppendFileRangeToUpload(const FilePath& file_path,
uint64 offset, uint64 length);
- void AppendFileToUpload(const std::wstring& file_path) {
+ void AppendFileToUpload(const FilePath& file_path) {
AppendFileRangeToUpload(file_path, 0, kuint64max);
}
diff --git a/net/url_request/url_request_file_job.cc b/net/url_request/url_request_file_job.cc
index 097169f..db3ff13 100644
--- a/net/url_request/url_request_file_job.cc
+++ b/net/url_request/url_request_file_job.cc
@@ -238,7 +238,7 @@ bool URLRequestFileJob::IsRedirectResponse(
if (!resolved)
return false;
- *location = net::FilePathToFileURL(new_path);
+ *location = net::FilePathToFileURL(FilePath(new_path));
*http_status_code = 301;
return true;
#else
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index fbfaafe..372ff43 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -16,6 +16,7 @@
#include <algorithm>
#include <string>
+#include "base/file_path.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/process_util.h"
@@ -526,16 +527,17 @@ TEST_F(URLRequestTest, PostFileTest) {
PathService::Get(base::DIR_EXE, &dir);
file_util::SetCurrentDirectory(dir);
- std::wstring path;
+ FilePath path;
PathService::Get(base::DIR_SOURCE_ROOT, &path);
- file_util::AppendToPath(&path, L"net");
- file_util::AppendToPath(&path, L"data");
- file_util::AppendToPath(&path, L"url_request_unittest");
- file_util::AppendToPath(&path, L"with-headers.html");
+ path = path.Append(FILE_PATH_LITERAL("net"));
+ path = path.Append(FILE_PATH_LITERAL("data"));
+ path = path.Append(FILE_PATH_LITERAL("url_request_unittest"));
+ path = path.Append(FILE_PATH_LITERAL("with-headers.html"));
r.AppendFileToUpload(path);
// This file should just be ignored in the upload stream.
- r.AppendFileToUpload(L"c:\\path\\to\\non\\existant\\file.randomness.12345");
+ r.AppendFileToUpload(FilePath(FILE_PATH_LITERAL(
+ "c:\\path\\to\\non\\existant\\file.randomness.12345")));
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -586,7 +588,7 @@ TEST_F(URLRequestTest, AboutBlankTest) {
TEST_F(URLRequestTest, FileTest) {
FilePath app_path;
PathService::Get(base::FILE_EXE, &app_path);
- GURL app_url = net::FilePathToFileURL(app_path.ToWStringHack());
+ GURL app_url = net::FilePathToFileURL(app_path);
TestDelegate d;
{
@@ -760,7 +762,7 @@ TEST_F(URLRequestTest, ResolveShortcutTest) {
TestDelegate d;
{
- TestURLRequest r(net::FilePathToFileURL(lnk_path), &d);
+ TestURLRequest r(net::FilePathToFileURL(FilePath(lnk_path)), &d);
r.Start();
EXPECT_TRUE(r.is_pending());
@@ -823,11 +825,10 @@ TEST_F(URLRequestTest, FileDirCancelTest) {
TestDelegate d;
{
- std::wstring file_path;
+ FilePath file_path;
PathService::Get(base::DIR_SOURCE_ROOT, &file_path);
- file_util::AppendToPath(&file_path, L"net");
- file_util::AppendToPath(&file_path, L"data");
- file_util::AppendToPath(&file_path, L"");
+ file_path = file_path.Append(FILE_PATH_LITERAL("net"));
+ file_path = file_path.Append(FILE_PATH_LITERAL("data"));
TestURLRequest req(net::FilePathToFileURL(file_path), &d);
req.Start();