OLD | NEW |
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/file_util.h" | 5 #include "base/file_util.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <libgen.h> | 10 #include <libgen.h> |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } | 474 } |
475 if (use_dev_shm) { | 475 if (use_dev_shm) { |
476 *path = FilePath("/dev/shm"); | 476 *path = FilePath("/dev/shm"); |
477 return true; | 477 return true; |
478 } | 478 } |
479 #endif | 479 #endif |
480 return GetTempDir(path); | 480 return GetTempDir(path); |
481 } | 481 } |
482 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID) | 482 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID) |
483 | 483 |
484 #if !defined(OS_MACOSX) | 484 #if !defined(OS_MACOSX) // Mac implementation is in file_util_mac.mm. |
485 FilePath GetHomeDir() { | 485 FilePath GetHomeDir() { |
486 #if defined(OS_CHROMEOS) | 486 #if defined(OS_CHROMEOS) |
487 if (SysInfo::IsRunningOnChromeOS()) | 487 if (SysInfo::IsRunningOnChromeOS()) |
488 return FilePath("/home/chronos/user"); | 488 return FilePath("/home/chronos/user"); |
489 #endif | 489 #endif |
490 | 490 |
491 const char* home_dir = getenv("HOME"); | 491 const char* home_dir = getenv("HOME"); |
492 if (home_dir && home_dir[0]) | 492 if (home_dir && home_dir[0]) |
493 return FilePath(home_dir); | 493 return FilePath(home_dir); |
494 | 494 |
495 #if defined(OS_ANDROID) | 495 #if defined(OS_ANDROID) |
496 DLOG(WARNING) << "OS_ANDROID: Home directory lookup not yet implemented."; | 496 DLOG(WARNING) << "OS_ANDROID: Home directory lookup not yet implemented."; |
497 #elif defined(USE_GLIB) && !defined(OS_CHROMEOS) | 497 #elif defined(USE_GLIB) && !defined(OS_CHROMEOS) |
498 // g_get_home_dir calls getpwent, which can fall through to LDAP calls. | 498 // g_get_home_dir calls getpwent, which can fall through to LDAP calls so |
499 ThreadRestrictions::AssertIOAllowed(); | 499 // this may do I/O. However, it should be rare that $HOME is not defined and |
500 | 500 // this is typically called from the path service which has no threading |
| 501 // restrictions. The path service will cache the result which limits the |
| 502 // badness of blocking on I/O. As a result, we don't have a thread |
| 503 // restriction here. |
501 home_dir = g_get_home_dir(); | 504 home_dir = g_get_home_dir(); |
502 if (home_dir && home_dir[0]) | 505 if (home_dir && home_dir[0]) |
503 return FilePath(home_dir); | 506 return FilePath(home_dir); |
504 #endif | 507 #endif |
505 | 508 |
506 FilePath rv; | 509 FilePath rv; |
507 if (GetTempDir(&rv)) | 510 if (GetTempDir(&rv)) |
508 return rv; | 511 return rv; |
509 | 512 |
510 // Last resort. | 513 // Last resort. |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 result = false; | 960 result = false; |
958 if (IGNORE_EINTR(close(outfile)) < 0) | 961 if (IGNORE_EINTR(close(outfile)) < 0) |
959 result = false; | 962 result = false; |
960 | 963 |
961 return result; | 964 return result; |
962 } | 965 } |
963 #endif // !defined(OS_MACOSX) | 966 #endif // !defined(OS_MACOSX) |
964 | 967 |
965 } // namespace internal | 968 } // namespace internal |
966 } // namespace base | 969 } // namespace base |
OLD | NEW |