Skip to content

Commit

Permalink
Cleanup: Make chrome paths code more consistent and use more constant…
Browse files Browse the repository at this point in the history
…s when possible.

BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6528028

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75289 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
thestig@chromium.org committed Feb 17, 2011
1 parent 557205c commit 16404c5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 25 deletions.
38 changes: 23 additions & 15 deletions chrome/common/chrome_paths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ const FilePath::CharType kInternalFlashPluginFileName[] =
FILE_PATH_LITERAL("libgcflashplayer.so");
#endif

// File name of the internal PDF plugin on different platforms.
const FilePath::CharType kInternalPDFPluginFileName[] =
#if defined(OS_WIN)
FILE_PATH_LITERAL("pdf.dll");
#elif defined(OS_MACOSX)
FILE_PATH_LITERAL("PDF.plugin");
#else // Linux and Chrome OS
FILE_PATH_LITERAL("libpdf.so");
#endif

// File name of the internal NaCl plugin on different platforms.
const FilePath::CharType kInternalNaClPluginFileName[] =
#if defined(OS_WIN)
FILE_PATH_LITERAL("ppGoogleNaClPluginChrome.dll");
#elif defined(OS_MACOSX)
// TODO(noelallen) Please verify this extention name is correct.
FILE_PATH_LITERAL("ppGoogleNaClPluginChrome.plugin");
#else // Linux and Chrome OS
FILE_PATH_LITERAL("libppGoogleNaClPluginChrome.so");
#endif

} // namespace

namespace chrome {
Expand Down Expand Up @@ -230,25 +251,12 @@ bool PathProvider(int key, FilePath* result) {
case chrome::FILE_PDF_PLUGIN:
if (!GetInternalPluginsDirectory(&cur))
return false;
#if defined(OS_WIN)
cur = cur.Append(FILE_PATH_LITERAL("pdf.dll"));
#elif defined(OS_MACOSX)
cur = cur.Append(FILE_PATH_LITERAL("PDF.plugin"));
#else // Linux and Chrome OS
cur = cur.Append(FILE_PATH_LITERAL("libpdf.so"));
#endif
cur = cur.Append(kInternalPDFPluginFileName);
break;
case chrome::FILE_NACL_PLUGIN:
if (!GetInternalPluginsDirectory(&cur))
return false;
#if defined(OS_WIN)
cur = cur.Append(FILE_PATH_LITERAL("ppGoogleNaClPluginChrome.dll"));
#elif defined(OS_MACOSX)
// TODO(noelallen) Please verify this extention name is correct.
cur = cur.Append(FILE_PATH_LITERAL("ppGoogleNaClPluginChrome.plugin"));
#else // Linux and Chrome OS
cur = cur.Append(FILE_PATH_LITERAL("libppGoogleNaClPluginChrome.so"));
#endif
cur = cur.Append(kInternalNaClPluginFileName);
break;
case chrome::FILE_RESOURCES_PACK:
#if defined(OS_MACOSX)
Expand Down
32 changes: 22 additions & 10 deletions chrome/common/chrome_paths_linux.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand All @@ -10,6 +10,14 @@
#include "base/scoped_ptr.h"
#include "base/nix/xdg_util.h"

namespace {

const char kDotConfigDir[] = ".config";
const char kDownloadsDir[] = "Downloads";
const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME";

} // namespace

namespace chrome {

// See http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
Expand All @@ -19,8 +27,9 @@ namespace chrome {
// (This also helps us sidestep issues with other apps grabbing ~/.chromium .)
bool GetDefaultUserDataDirectory(FilePath* result) {
scoped_ptr<base::Environment> env(base::Environment::Create());
FilePath config_dir(
base::nix::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config"));
FilePath config_dir(base::nix::GetXDGDirectory(env.get(),
kXdgConfigHomeEnvVar,
kDotConfigDir));
#if defined(GOOGLE_CHROME_BUILD)
*result = config_dir.Append("google-chrome");
#else
Expand All @@ -46,8 +55,9 @@ void GetUserCacheDirectory(const FilePath& profile_dir, FilePath* result) {
FilePath cache_dir;
if (!PathService::Get(base::DIR_CACHE, &cache_dir))
return;
FilePath config_dir(
base::nix::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config"));
FilePath config_dir(base::nix::GetXDGDirectory(env.get(),
kXdgConfigHomeEnvVar,
kDotConfigDir));

if (!config_dir.AppendRelativePath(profile_dir, &cache_dir))
return;
Expand All @@ -57,8 +67,9 @@ void GetUserCacheDirectory(const FilePath& profile_dir, FilePath* result) {

bool GetChromeFrameUserDataDirectory(FilePath* result) {
scoped_ptr<base::Environment> env(base::Environment::Create());
FilePath config_dir(
base::nix::GetXDGDirectory(env.get(), "XDG_CONFIG_HOME", ".config"));
FilePath config_dir(base::nix::GetXDGDirectory(env.get(),
kXdgConfigHomeEnvVar,
kDotConfigDir));
#if defined(GOOGLE_CHROME_BUILD)
*result = config_dir.Append("google-chrome-frame");
#else
Expand All @@ -77,18 +88,19 @@ bool GetUserDocumentsDirectory(FilePath* result) {
// ~ or their desktop directory, in which case we default to ~/Downloads.
bool GetUserDownloadsDirectory(FilePath* result) {
scoped_ptr<base::Environment> env(base::Environment::Create());
*result = base::nix::GetXDGUserDirectory(env.get(), "DOWNLOAD", "Downloads");
*result = base::nix::GetXDGUserDirectory(env.get(), "DOWNLOAD",
kDownloadsDir);

FilePath home = file_util::GetHomeDir();
if (*result == home) {
*result = home.Append("Downloads");
*result = home.Append(kDownloadsDir);
return true;
}

FilePath desktop;
GetUserDesktop(&desktop);
if (*result == desktop) {
*result = home.Append("Downloads");
*result = home.Append(kDownloadsDir);
}

return true;
Expand Down

0 comments on commit 16404c5

Please sign in to comment.