Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: net/base/filename_util.cc

Issue 1068793002: Fixed "blocking io" from FixupPath on UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed "blocking io" from FixupURL on UI thread Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« net/base/filename_util.h ('K') | « net/base/filename_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "net/base/filename_util.h" 5 #include "net/base/filename_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 &url_string, 0, FILE_PATH_LITERAL("?"), FILE_PATH_LITERAL("%3F")); 56 &url_string, 0, FILE_PATH_LITERAL("?"), FILE_PATH_LITERAL("%3F"));
57 57
58 #if defined(OS_POSIX) 58 #if defined(OS_POSIX)
59 ReplaceSubstringsAfterOffset( 59 ReplaceSubstringsAfterOffset(
60 &url_string, 0, FILE_PATH_LITERAL("\\"), FILE_PATH_LITERAL("%5C")); 60 &url_string, 0, FILE_PATH_LITERAL("\\"), FILE_PATH_LITERAL("%5C"));
61 #endif 61 #endif
62 62
63 return GURL(url_string); 63 return GURL(url_string);
64 } 64 }
65 65
66 GURL FilePathToFileURLNoCWD(const base::FilePath& path) {
67 // Produce a URL like "file:///C:/foo" for a regular file, or
68 // "file://///server/path" for UNC. The URL canonicalizer will fix up the
69 // latter case to be the canonical UNC form: "file://server/path"
70 base::FilePath::StringType url_string(kFileURLPrefix);
71 url_string.append(path.value());
72 // Do replacement of some characters. Since we assume the input is a
73 // literal filename, anything the URL parser might consider special should
74 // be escaped here.
75
76 // must be the first substitution since others will introduce percents as the
77 // escape character
78 ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("%"),
79 FILE_PATH_LITERAL("%25"));
80
81 // semicolon is supposed to be some kind of separator according to RFC 2396
82 ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL(";"),
83 FILE_PATH_LITERAL("%3B"));
84
85 ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("#"),
86 FILE_PATH_LITERAL("%23"));
87
88 ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("?"),
89 FILE_PATH_LITERAL("%3F"));
90
91 #if defined(OS_POSIX)
92 ReplaceSubstringsAfterOffset(&url_string, 0, FILE_PATH_LITERAL("\\"),
93 FILE_PATH_LITERAL("%5C"));
94 #endif
davidben 2015/04/14 16:26:22 This is too much code to be duplicated. Move thing
95
96 return GURL(url_string);
97 }
98
66 bool FileURLToFilePath(const GURL& url, base::FilePath* file_path) { 99 bool FileURLToFilePath(const GURL& url, base::FilePath* file_path) {
67 *file_path = base::FilePath(); 100 *file_path = base::FilePath();
68 base::FilePath::StringType& file_path_str = 101 base::FilePath::StringType& file_path_str =
69 const_cast<base::FilePath::StringType&>(file_path->value()); 102 const_cast<base::FilePath::StringType&>(file_path->value());
70 file_path_str.clear(); 103 file_path_str.clear();
71 104
72 if (!url.is_valid()) 105 if (!url.is_valid())
73 return false; 106 return false;
74 107
75 #if defined(OS_WIN) 108 #if defined(OS_WIN)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 if (file_path->value() == base::FilePath::kCurrentDirectory) { 186 if (file_path->value() == base::FilePath::kCurrentDirectory) {
154 *file_path = base::FilePath(leaf_name); 187 *file_path = base::FilePath(leaf_name);
155 } else { 188 } else {
156 *file_path = file_path->Append(leaf_name); 189 *file_path = file_path->Append(leaf_name);
157 } 190 }
158 } 191 }
159 #endif 192 #endif
160 } 193 }
161 194
162 } // namespace net 195 } // namespace net
OLDNEW
« net/base/filename_util.h ('K') | « net/base/filename_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698