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

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: fix linkage visibility of policy protobufs 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
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|.
237 return OverrideAndCreateIfNeeded(key, path, true); 237 return OverrideAndCreateIfNeeded(key, path, true);
238 } 238 }
239 239
240 // static 240 // static
241 bool PathService::OverrideAndCreateIfNeeded(int key, 241 bool PathService::OverrideAndCreateIfNeeded(int key,
242 const FilePath& path, 242 const FilePath& path,
243 bool create) { 243 bool create) {
244 PathData* path_data = GetPathData();
245 DCHECK(path_data);
246 DCHECK_GT(key, base::DIR_CURRENT) << "invalid path key";
247
248 FilePath file_path = path; 244 FilePath file_path = path;
249 245
250 // For some locations this will fail if called from inside the sandbox there- 246 // For some locations this will fail if called from inside the sandbox there-
251 // fore we protect this call with a flag. 247 // fore we protect this call with a flag.
252 if (create) { 248 if (create) {
253 // Make sure the directory exists. We need to do this before we translate 249 // Make sure the directory exists. We need to do this before we translate
254 // this to the absolute path because on POSIX, MakeAbsoluteFilePath fails 250 // this to the absolute path because on POSIX, MakeAbsoluteFilePath fails
255 // if called on a non-existent path. 251 // if called on a non-existent path.
256 if (!base::PathExists(file_path) && 252 if (!base::PathExists(file_path) &&
257 !base::CreateDirectory(file_path)) 253 !base::CreateDirectory(file_path))
258 return false; 254 return false;
259 } 255 }
260 256
261 // We need to have an absolute path. 257 // We need to have an absolute path.
262 file_path = MakeAbsoluteFilePath(file_path); 258 file_path = MakeAbsoluteFilePath(file_path);
263 if (file_path.empty()) 259 if (file_path.empty())
264 return false; 260 return false;
265 261
262 OverrideWithAbsolutePath(key, file_path);
263 return true;
264 }
265
266 // static
267 void PathService::OverrideWithAbsolutePath(int key, const FilePath& path) {
268 DCHECK_GT(key, base::DIR_CURRENT) << "invalid path key";
269 DCHECK(path.IsAbsolute());
270
271 PathData* path_data = GetPathData();
272 DCHECK(path_data);
273
266 base::AutoLock scoped_lock(path_data->lock); 274 base::AutoLock scoped_lock(path_data->lock);
267 275
268 // Clear the cache now. Some of its entries could have depended 276 // 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. 277 // on the value we are overriding, and are now out of sync with reality.
270 path_data->cache.clear(); 278 path_data->cache.clear();
271 279
272 path_data->overrides[key] = file_path; 280 path_data->overrides[key] = path;
273
274 return true;
275 } 281 }
276 282
277 // static 283 // static
278 bool PathService::RemoveOverride(int key) { 284 bool PathService::RemoveOverride(int key) {
279 PathData* path_data = GetPathData(); 285 PathData* path_data = GetPathData();
280 DCHECK(path_data); 286 DCHECK(path_data);
281 287
282 base::AutoLock scoped_lock(path_data->lock); 288 base::AutoLock scoped_lock(path_data->lock);
283 289
284 if (path_data->overrides.find(key) == path_data->overrides.end()) 290 if (path_data->overrides.find(key) == path_data->overrides.end())
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 333
328 // static 334 // static
329 void PathService::DisableCache() { 335 void PathService::DisableCache() {
330 PathData* path_data = GetPathData(); 336 PathData* path_data = GetPathData();
331 DCHECK(path_data); 337 DCHECK(path_data);
332 338
333 base::AutoLock scoped_lock(path_data->lock); 339 base::AutoLock scoped_lock(path_data->lock);
334 path_data->cache.clear(); 340 path_data->cache.clear();
335 path_data->cache_disabled = true; 341 path_data->cache_disabled = true;
336 } 342 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698