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

Side by Side Diff: components/url_fixer/url_fixer.cc

Issue 515973003: Fixed problem with incorrect use of $HOME (breaking multi user ChromeOS) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing unit test Created 6 years, 3 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
« no previous file with comments | « no previous file | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/url_fixer/url_fixer.h" 5 #include "components/url_fixer/url_fixer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/file_util.h"
10 #include "base/files/file_path.h"
11 #include "base/logging.h"
9 #if defined(OS_POSIX) 12 #if defined(OS_POSIX)
10 #include "base/environment.h" 13 #include "base/path_service.h"
11 #endif 14 #endif
12 #include "base/file_util.h"
13 #include "base/logging.h"
14 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
16 #include "net/base/escape.h" 17 #include "net/base/escape.h"
17 #include "net/base/filename_util.h" 18 #include "net/base/filename_util.h"
18 #include "net/base/net_util.h" 19 #include "net/base/net_util.h"
19 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 20 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
20 #include "url/url_file.h" 21 #include "url/url_file.h"
21 #include "url/url_parse.h" 22 #include "url/url_parse.h"
22 #include "url/url_util.h" 23 #include "url/url_util.h"
23 24
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 return true; 116 return true;
116 } 117 }
117 118
118 #if defined(OS_POSIX) 119 #if defined(OS_POSIX)
119 // Given a path that starts with ~, return a path that starts with an 120 // Given a path that starts with ~, return a path that starts with an
120 // expanded-out /user/foobar directory. 121 // expanded-out /user/foobar directory.
121 std::string FixupHomedir(const std::string& text) { 122 std::string FixupHomedir(const std::string& text) {
122 DCHECK(text.length() > 0 && text[0] == '~'); 123 DCHECK(text.length() > 0 && text[0] == '~');
123 124
124 if (text.length() == 1 || text[1] == '/') { 125 if (text.length() == 1 || text[1] == '/') {
125 const char* home = getenv(base::env_vars::kHome); 126 base::FilePath file_path;
126 if (url_fixer::home_directory_override) 127 if (url_fixer::home_directory_override)
127 home = url_fixer::home_directory_override; 128 file_path = base::FilePath(url_fixer::home_directory_override);
129 else
130 PathService::Get(base::DIR_HOME, &file_path);
131
128 // We'll probably break elsewhere if $HOME is undefined, but check here 132 // We'll probably break elsewhere if $HOME is undefined, but check here
129 // just in case. 133 // just in case.
130 if (!home) 134 if (file_path.value().empty())
131 return text; 135 return text;
132 return home + text.substr(1); 136 // Append requires to be a relative path, so we have to cut all preceeding
137 // '/' characters.
138 size_t i = 1;
139 while (i < text.length() && text[i] == '/')
140 ++i;
141 return file_path.Append(text.substr(i)).value();
133 } 142 }
134 143
135 // Otherwise, this is a path like ~foobar/baz, where we must expand to 144 // Otherwise, this is a path like ~foobar/baz, where we must expand to
136 // user foobar's home directory. Officially, we should use getpwent(), 145 // user foobar's home directory. Officially, we should use getpwent(),
137 // but that is a nasty blocking call. 146 // but that is a nasty blocking call.
138 147
139 #if defined(OS_MACOSX) 148 #if defined(OS_MACOSX)
140 static const char kHome[] = "/Users/"; 149 static const char kHome[] = "/Users/";
141 #else 150 #else
142 static const char kHome[] = "/home/"; 151 static const char kHome[] = "/home/";
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 part->reset(); 669 part->reset();
661 } 670 }
662 } 671 }
663 672
664 bool url_fixer::IsEquivalentScheme(const std::string& scheme1, 673 bool url_fixer::IsEquivalentScheme(const std::string& scheme1,
665 const std::string& scheme2) { 674 const std::string& scheme2) {
666 return scheme1 == scheme2 || 675 return scheme1 == scheme2 ||
667 (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) || 676 (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) ||
668 (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme); 677 (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme);
669 } 678 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698