| OLD | NEW |
| 1 // Copyright (c) 2011 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 "chrome/common/chrome_paths_internal.h" | 5 #include "chrome/common/chrome_paths_internal.h" |
| 6 | 6 |
| 7 #include "base/environment.h" | 7 #include "base/environment.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/nix/xdg_util.h" | 11 #include "base/nix/xdg_util.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 #endif | 77 #endif |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool GetUserDocumentsDirectory(FilePath* result) { | 81 bool GetUserDocumentsDirectory(FilePath* result) { |
| 82 scoped_ptr<base::Environment> env(base::Environment::Create()); | 82 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 83 *result = base::nix::GetXDGUserDirectory(env.get(), "DOCUMENTS", "Documents"); | 83 *result = base::nix::GetXDGUserDirectory(env.get(), "DOCUMENTS", "Documents"); |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 | 86 |
| 87 // We respect the user's preferred download location, unless it is | 87 bool GetUserDownloadsDirectorySafe(FilePath* result) { |
| 88 // ~ or their desktop directory, in which case we default to ~/Downloads. | 88 FilePath home = file_util::GetHomeDir(); |
| 89 *result = home.Append(kDownloadsDir); |
| 90 return true; |
| 91 } |
| 92 |
| 89 bool GetUserDownloadsDirectory(FilePath* result) { | 93 bool GetUserDownloadsDirectory(FilePath* result) { |
| 90 scoped_ptr<base::Environment> env(base::Environment::Create()); | 94 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 91 *result = base::nix::GetXDGUserDirectory(env.get(), "DOWNLOAD", | 95 *result = base::nix::GetXDGUserDirectory(env.get(), "DOWNLOAD", |
| 92 kDownloadsDir); | 96 kDownloadsDir); |
| 93 | |
| 94 FilePath home = file_util::GetHomeDir(); | |
| 95 if (*result == home) { | |
| 96 *result = home.Append(kDownloadsDir); | |
| 97 return true; | |
| 98 } | |
| 99 | |
| 100 FilePath desktop; | |
| 101 GetUserDesktop(&desktop); | |
| 102 if (*result == desktop) { | |
| 103 *result = home.Append(kDownloadsDir); | |
| 104 } | |
| 105 | |
| 106 return true; | 97 return true; |
| 107 } | 98 } |
| 108 | 99 |
| 109 bool GetUserDesktop(FilePath* result) { | 100 bool GetUserDesktop(FilePath* result) { |
| 110 scoped_ptr<base::Environment> env(base::Environment::Create()); | 101 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 111 *result = base::nix::GetXDGUserDirectory(env.get(), "DESKTOP", "Desktop"); | 102 *result = base::nix::GetXDGUserDirectory(env.get(), "DESKTOP", "Desktop"); |
| 112 return true; | 103 return true; |
| 113 } | 104 } |
| 114 | 105 |
| 115 } // namespace chrome | 106 } // namespace chrome |
| OLD | NEW |