Skip to content

Commit

Permalink
Revert 157667 - Add new PathService paths for Windows' All Users Desk…
Browse files Browse the repository at this point in the history
…top and Quick Launch folders.

The previous patch failed PathServiceTest.Get.

This allows usage of PathService to cache the paths and more importantly to mock them in shortcut tests!

Also move chrome::DIR_USER_DESKTOP to base::DIR_USER_DESKTOP; this is really where it belongs. In fact it is only in chrome_paths.h because it used to be called DIR_DEFAULT_DOWNLOAD and cpu@ renamed it to DIR_USER_DESKTOP in http://crrev.com/1753 (early days!) after that it started to be used all over the place as the Desktop path. Finally bringing it to base_paths.h, beside DIR_START_MENU and friends, is the right thing to do imo.

BUG=148539
TEST=Quick Launch shortcut installed in the right place on XP (both Default and current user)
Desktop shortcuts installed in the right place (both All Users and per-user installs).

installer_util_unittests.exe --gtest_filter=ShellUtilShortcutTest*
unit_tests.exe --gtest_filter=ProfileShortcutManagerTest*
base_unittests --gtest_filter=PathServiceTest*

Review URL: https://chromiumcodereview.appspot.com/10910209

TBR=gab@chromium.org
Review URL: https://codereview.chromium.org/10958009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157680 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
wjia@chromium.org committed Sep 20, 2012
1 parent 5e63aed commit 1f4ae16
Show file tree
Hide file tree
Showing 28 changed files with 152 additions and 215 deletions.
1 change: 0 additions & 1 deletion base/base.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
'base_paths_mac.h',
'base_paths_mac.mm',
'base_paths_posix.cc',
'base_paths_posix.h',
'base_paths_win.cc',
'base_paths_win.h',
'base_switches.h',
Expand Down
2 changes: 1 addition & 1 deletion base/base_paths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace base {

bool PathProvider(int key, FilePath* result) {
// NOTE: DIR_CURRENT is a special case in PathService::Get
// NOTE: DIR_CURRENT is a special cased in PathService::Get

FilePath cur;
switch (key) {
Expand Down
16 changes: 11 additions & 5 deletions base/base_paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
#include "base/base_paths_android.h"
#endif

#if defined(OS_POSIX)
#include "base/base_paths_posix.h"
#endif

namespace base {

enum BasePathKey {
Expand All @@ -38,7 +34,17 @@ enum BasePathKey {
DIR_SOURCE_ROOT, // Returns the root of the source tree. This key is useful
// for tests that need to locate various resources. It
// should not be used outside of test code.
DIR_USER_DESKTOP, // The current user's Desktop.
#if defined(OS_POSIX)
DIR_CACHE, // Directory where to put cache data. Note this is
// *not* where the browser cache lives, but the
// browser cache can be a subdirectory.
// This is $XDG_CACHE_HOME on Linux and
// ~/Library/Caches on Mac.
DIR_HOME, // $HOME on POSIX-like systems.
#endif
#if defined(OS_ANDROID)
DIR_ANDROID_EXTERNAL_STORAGE, // Android external storage directory.
#endif

PATH_END
};
Expand Down
32 changes: 17 additions & 15 deletions base/base_paths_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Defines base::PathProviderAndroid which replaces base::PathProviderPosix for
// Android in base/path_service.cc.
#include "base/base_paths.h"

#include <unistd.h>

#include "base/android/jni_android.h"
#include "base/android/path_utils.h"
#include "base/base_paths.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
Expand All @@ -30,38 +28,42 @@ bool PathProviderAndroid(int key, FilePath* result) {
*result = FilePath(bin_dir);
return true;
}
case base::FILE_MODULE:
case base::FILE_MODULE: {
// dladdr didn't work in Android as only the file name was returned.
NOTIMPLEMENTED();
return false;
case base::DIR_MODULE:
}
case base::DIR_MODULE: {
*result = FilePath(base::android::GetNativeLibraryDirectory());
return true;
case base::DIR_SOURCE_ROOT:
}
case base::DIR_SOURCE_ROOT: {
// This const is only used for tests.
*result = FilePath(base::android::GetExternalStorageDirectory());
return true;
case base::DIR_USER_DESKTOP:
// Android doesn't support GetUserDesktop.
NOTIMPLEMENTED();
return false;
case base::DIR_CACHE:
}
case base::DIR_CACHE: {
*result = FilePath(base::android::GetCacheDirectory());
return true;
case base::DIR_ANDROID_APP_DATA:
}
case base::DIR_ANDROID_APP_DATA: {
*result = FilePath(base::android::GetDataDirectory());
return true;
case base::DIR_HOME:
}
case base::DIR_HOME: {
*result = file_util::GetHomeDir();
return true;
case base::DIR_ANDROID_EXTERNAL_STORAGE:
}
case base::DIR_ANDROID_EXTERNAL_STORAGE: {
*result = FilePath(base::android::GetExternalStorageDirectory());
return true;
default:
}
default: {
// Note: the path system expects this function to override the default
// behavior. So no need to log an error if we don't support a given
// path. The system will just use the default.
return false;
}
}
}

Expand Down
1 change: 0 additions & 1 deletion base/base_paths_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ enum {
PATH_ANDROID_START = 300,

DIR_ANDROID_APP_DATA, // Directory where to put Android app's data.
DIR_ANDROID_EXTERNAL_STORAGE, // Android external storage directory.

PATH_ANDROID_END
};
Expand Down
17 changes: 7 additions & 10 deletions base/base_paths_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Defines base::PathProviderMac which replaces base::PathProviderPosix for Mac
// in base/path_service.cc.
#include "base/base_paths_mac.h"

#include <dlfcn.h>
#import <Foundation/Foundation.h>
#include <mach-o/dyld.h>

#include "base/base_paths.h"
#include "base/compiler_specific.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "build/build_config.h"

namespace {

Expand Down Expand Up @@ -60,6 +57,8 @@ bool PathProviderMac(int key, FilePath* result) {
case base::FILE_MODULE:
return GetModulePathForAddress(result,
reinterpret_cast<const void*>(&base::PathProviderMac));
case base::DIR_CACHE:
return base::mac::GetUserDirectory(NSCachesDirectory, result);
case base::DIR_APP_DATA: {
bool success = base::mac::GetUserDirectory(NSApplicationSupportDirectory,
result);
Expand All @@ -70,7 +69,7 @@ bool PathProviderMac(int key, FilePath* result) {
#endif // defined(OS_IOS)
return success;
}
case base::DIR_SOURCE_ROOT:
case base::DIR_SOURCE_ROOT: {
// Go through PathService to catch overrides.
if (!PathService::Get(base::FILE_EXE, result))
return false;
Expand All @@ -91,13 +90,11 @@ bool PathProviderMac(int key, FilePath* result) {
}
#endif
return true;
case base::DIR_USER_DESKTOP:
return base::mac::GetUserDirectory(NSDesktopDirectory, result);
case base::DIR_CACHE:
return base::mac::GetUserDirectory(NSCachesDirectory, result);
case base::DIR_HOME:
}
case base::DIR_HOME: {
*result = base::mac::NSStringToFilePath(NSHomeDirectory());
return true;
}
default:
return false;
}
Expand Down
13 changes: 4 additions & 9 deletions base/base_paths_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Defines base::PathProviderPosix, default path provider on POSIX OSes that
// don't have their own base_paths_OS.cc implementation (i.e. all but Mac and
// Android).
#include "base/base_paths.h"

#include <ostream>
#include <string>

#include "base/base_paths.h"
#include "build/build_config.h"
#include "base/environment.h"
#include "base/file_path.h"
#include "base/file_util.h"
Expand All @@ -18,7 +16,6 @@
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/nix/xdg_util.h"
#include "build/build_config.h"

#if defined(OS_FREEBSD)
#include <sys/param.h>
Expand Down Expand Up @@ -99,19 +96,17 @@ bool PathProviderPosix(int key, FilePath* result) {
<< "Try running from your chromium/src directory.";
return false;
}
case base::DIR_USER_DESKTOP:
*result = base::nix::GetXDGUserDirectory("DESKTOP", "Desktop");
return true;
case base::DIR_CACHE: {
scoped_ptr<base::Environment> env(base::Environment::Create());
FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME",
".cache"));
*result = cache_dir;
return true;
}
case base::DIR_HOME:
case base::DIR_HOME: {
*result = file_util::GetHomeDir();
return true;
}
}
return false;
}
Expand Down
29 changes: 0 additions & 29 deletions base/base_paths_posix.h

This file was deleted.

60 changes: 3 additions & 57 deletions base/base_paths_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/base_paths_win.h"

#include <windows.h>
#include <shlobj.h>

#include "base/base_paths.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
Expand All @@ -16,38 +16,6 @@
// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
extern "C" IMAGE_DOS_HEADER __ImageBase;

namespace {

bool GetQuickLaunchPath(bool default_user, FilePath* result) {
if (default_user) {
wchar_t system_buffer[MAX_PATH];
system_buffer[0] = 0;
// As per MSDN, passing -1 for |hToken| indicates the Default user:
// http://msdn.microsoft.com/library/windows/desktop/bb762181.aspx
if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA,
reinterpret_cast<HANDLE>(-1), SHGFP_TYPE_CURRENT,
system_buffer))) {
return false;
}
*result = FilePath(system_buffer);
} else if (!PathService::Get(base::DIR_APP_DATA, result)) {
// For the current user, grab the APPDATA directory directly from the
// PathService cache.
return false;
}
// According to various sources, appending
// "Microsoft\Internet Explorer\Quick Launch" to %appdata% is the only
// reliable way to get the quick launch folder across all versions of Windows.
// http://stackoverflow.com/questions/76080/how-do-you-reliably-get-the-quick-
// http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept05/hey0901.mspx
*result = result->AppendASCII("Microsoft");
*result = result->AppendASCII("Internet Explorer");
*result = result->AppendASCII("Quick Launch");
return true;
}

} // namespace

namespace base {

bool PathProviderWin(int key, FilePath* result) {
Expand Down Expand Up @@ -135,9 +103,9 @@ bool PathProviderWin(int key, FilePath* result) {
cur = FilePath(system_buffer);
break;
case base::DIR_LOCAL_APP_DATA_LOW:
if (win::GetVersion() < win::VERSION_VISTA)
if (win::GetVersion() < win::VERSION_VISTA) {
return false;

}
// TODO(nsylvain): We should use SHGetKnownFolderPath instead. Bug 1281128
if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT,
system_buffer)))
Expand Down Expand Up @@ -170,28 +138,6 @@ bool PathProviderWin(int key, FilePath* result) {
cur = FilePath(string16(path_buf));
break;
}
case base::DIR_USER_DESKTOP:
if (FAILED(SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL,
SHGFP_TYPE_CURRENT, system_buffer))) {
return false;
}
cur = FilePath(system_buffer);
break;
case base::DIR_COMMON_DESKTOP:
if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_DESKTOPDIRECTORY, NULL,
SHGFP_TYPE_CURRENT, system_buffer))) {
return false;
}
cur = FilePath(system_buffer);
break;
case base::DIR_USER_QUICK_LAUNCH:
if (!GetQuickLaunchPath(false, &cur))
return false;
break;
case base::DIR_DEFAULT_USER_QUICK_LAUNCH:
if (!GetQuickLaunchPath(true, &cur))
return false;
break;
default:
return false;
}
Expand Down
6 changes: 0 additions & 6 deletions base/base_paths_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ enum {
DIR_APP_SHORTCUTS, // Where tiles on the start screen are stored, only
// for Windows 8. Maps to "Local\AppData\Microsoft\
// Windows\Application Shortcuts\".
DIR_COMMON_DESKTOP, // Directory for the common desktop (visible
// on all user's Desktop).
DIR_USER_QUICK_LAUNCH, // Directory for the quick launch shortcuts.
DIR_DEFAULT_USER_QUICK_LAUNCH, // Directory for the quick launch shortcuts
// of the Default user.

PATH_WIN_END
};

Expand Down
10 changes: 4 additions & 6 deletions base/path_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ namespace base {
#elif defined(OS_ANDROID)
bool PathProviderAndroid(int key, FilePath* result);
#elif defined(OS_POSIX)
// PathProviderPosix is the default path provider on POSIX OSes other than
// Mac and Android.
bool PathProviderPosix(int key, FilePath* result);
#endif
}
Expand Down Expand Up @@ -87,8 +85,8 @@ Provider base_provider_android = {
base::PathProviderAndroid,
&base_provider,
#ifndef NDEBUG
base::PATH_ANDROID_START,
base::PATH_ANDROID_END,
0,
0,
#endif
true
};
Expand All @@ -99,8 +97,8 @@ Provider base_provider_posix = {
base::PathProviderPosix,
&base_provider,
#ifndef NDEBUG
base::PATH_POSIX_START,
base::PATH_POSIX_END,
0,
0,
#endif
true
};
Expand Down
Loading

0 comments on commit 1f4ae16

Please sign in to comment.