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

Side by Side Diff: base/path_service.cc

Issue 337054: Allow non-absolute arguments to --user-data-dir. (Closed)
Patch Set: Created 11 years, 1 month 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/path_service.h" 5 #include "base/path_service.h"
6 6
7 #ifdef OS_WIN 7 #ifdef OS_WIN
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 AutoLock scoped_lock(path_data->lock); 207 AutoLock scoped_lock(path_data->lock);
208 return path_data->overrides.find(key) != path_data->overrides.end(); 208 return path_data->overrides.find(key) != path_data->overrides.end();
209 } 209 }
210 210
211 bool PathService::Override(int key, const FilePath& path) { 211 bool PathService::Override(int key, const FilePath& path) {
212 PathData* path_data = GetPathData(); 212 PathData* path_data = GetPathData();
213 DCHECK(path_data); 213 DCHECK(path_data);
214 DCHECK(key > base::DIR_CURRENT) << "invalid path key"; 214 DCHECK(key > base::DIR_CURRENT) << "invalid path key";
215 215
216 FilePath file_path = path; 216 FilePath file_path = path;
217 #if defined(OS_WIN)
218 // On Windows we switch the current working directory to load plugins (at
219 // least). That's not the case on POSIX.
220 // Also, on POSIX, AbsolutePath fails if called on a non-existant path.
221 if (!file_util::AbsolutePath(&file_path))
222 return false;
223 #endif
224 217
225 // make sure the directory exists: 218 // Make sure the directory exists. We need to do this before we make
MAD 2009/10/27 23:22:56 "...before we make translate..."??? Is it just me
219 // translate this to the absolute path because on POSIX, AbsolutePath fails
220 // if called on a non-existant path.
226 if (!file_util::PathExists(file_path) && 221 if (!file_util::PathExists(file_path) &&
227 !file_util::CreateDirectory(file_path)) 222 !file_util::CreateDirectory(file_path))
228 return false; 223 return false;
229 224
225 // We need to have an absolute path, as extensions and plugins don't like
226 // relative paths.
227 if (!file_util::AbsolutePath(&file_path))
228 return false;
229
230 AutoLock scoped_lock(path_data->lock); 230 AutoLock scoped_lock(path_data->lock);
231 path_data->cache[key] = file_path; 231 path_data->cache[key] = file_path;
232 path_data->overrides.insert(key); 232 path_data->overrides.insert(key);
233 return true; 233 return true;
234 } 234 }
235 235
236 void PathService::RegisterProvider(ProviderFunc func, int key_start, 236 void PathService::RegisterProvider(ProviderFunc func, int key_start,
237 int key_end) { 237 int key_end) {
238 PathData* path_data = GetPathData(); 238 PathData* path_data = GetPathData();
239 DCHECK(path_data); 239 DCHECK(path_data);
(...skipping 15 matching lines...) Expand all
255 p = new Provider; 255 p = new Provider;
256 p->is_static = false; 256 p->is_static = false;
257 p->func = func; 257 p->func = func;
258 p->next = path_data->providers; 258 p->next = path_data->providers;
259 #ifndef NDEBUG 259 #ifndef NDEBUG
260 p->key_start = key_start; 260 p->key_start = key_start;
261 p->key_end = key_end; 261 p->key_end = key_end;
262 #endif 262 #endif
263 path_data->providers = p; 263 path_data->providers = p;
264 } 264 }
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