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

Side by Side Diff: base/path_service.cc

Issue 258743005: Enable Enterprise enrollment on desktop builds. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added arg to PathService::OverrideAndCreateIfNeeded, added test for FakeCryptohomeClient::InstallAt… Created 6 years, 7 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 | Annotate | Revision Log
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 "base/path_service.h" 5 #include "base/path_service.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 226
227 base::AutoLock scoped_lock(path_data->lock); 227 base::AutoLock scoped_lock(path_data->lock);
228 if (!path_data->cache_disabled) 228 if (!path_data->cache_disabled)
229 path_data->cache[key] = path; 229 path_data->cache[key] = path;
230 230
231 return true; 231 return true;
232 } 232 }
233 233
234 // static 234 // static
235 bool PathService::Override(int key, const FilePath& path) { 235 bool PathService::Override(int key, const FilePath& path) {
236 // Just call the full function with true for the value of |create|. 236 // Just call the full function with true for the value of |create|, and
237 return OverrideAndCreateIfNeeded(key, path, true); 237 // assume that |path| may not be absolute yet.
238 return OverrideAndCreateIfNeeded(key, path, false, true);
238 } 239 }
239 240
240 // static 241 // static
241 bool PathService::OverrideAndCreateIfNeeded(int key, 242 bool PathService::OverrideAndCreateIfNeeded(int key,
242 const FilePath& path, 243 const FilePath& path,
244 bool is_absolute,
243 bool create) { 245 bool create) {
244 PathData* path_data = GetPathData(); 246 PathData* path_data = GetPathData();
245 DCHECK(path_data); 247 DCHECK(path_data);
246 DCHECK_GT(key, base::DIR_CURRENT) << "invalid path key"; 248 DCHECK_GT(key, base::DIR_CURRENT) << "invalid path key";
247 249
248 FilePath file_path = path; 250 FilePath file_path = path;
249 251
250 // For some locations this will fail if called from inside the sandbox there- 252 // For some locations this will fail if called from inside the sandbox there-
251 // fore we protect this call with a flag. 253 // fore we protect this call with a flag.
252 if (create) { 254 if (create) {
253 // Make sure the directory exists. We need to do this before we translate 255 // Make sure the directory exists. We need to do this before we translate
254 // this to the absolute path because on POSIX, MakeAbsoluteFilePath fails 256 // this to the absolute path because on POSIX, MakeAbsoluteFilePath fails
255 // if called on a non-existent path. 257 // if called on a non-existent path.
256 if (!base::PathExists(file_path) && 258 if (!base::PathExists(file_path) &&
257 !base::CreateDirectory(file_path)) 259 !base::CreateDirectory(file_path))
258 return false; 260 return false;
259 } 261 }
260 262
261 // We need to have an absolute path. 263 // We need to have an absolute path.
262 file_path = MakeAbsoluteFilePath(file_path); 264 if (!is_absolute) {
263 if (file_path.empty()) 265 file_path = MakeAbsoluteFilePath(file_path);
264 return false; 266 if (file_path.empty())
267 return false;
268 }
269 DCHECK(file_path.IsAbsolute());
265 270
266 base::AutoLock scoped_lock(path_data->lock); 271 base::AutoLock scoped_lock(path_data->lock);
267 272
268 // Clear the cache now. Some of its entries could have depended 273 // Clear the cache now. Some of its entries could have depended
269 // on the value we are overriding, and are now out of sync with reality. 274 // on the value we are overriding, and are now out of sync with reality.
270 path_data->cache.clear(); 275 path_data->cache.clear();
271 276
272 path_data->overrides[key] = file_path; 277 path_data->overrides[key] = file_path;
273 278
274 return true; 279 return true;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 332
328 // static 333 // static
329 void PathService::DisableCache() { 334 void PathService::DisableCache() {
330 PathData* path_data = GetPathData(); 335 PathData* path_data = GetPathData();
331 DCHECK(path_data); 336 DCHECK(path_data);
332 337
333 base::AutoLock scoped_lock(path_data->lock); 338 base::AutoLock scoped_lock(path_data->lock);
334 path_data->cache.clear(); 339 path_data->cache.clear();
335 path_data->cache_disabled = true; 340 path_data->cache_disabled = true;
336 } 341 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698