This source file includes following definitions.
- GetUserDirectory
- GetDefaultUserDataDirectory
- GetUserCacheDirectory
- GetUserDocumentsDirectory
- GetUserDownloadsDirectorySafe
- GetUserDownloadsDirectory
- GetUserMusicDirectory
- GetUserPicturesDirectory
- GetUserVideosDirectory
- ProcessNeedsProfileDir
#include "chrome/common/chrome_paths_internal.h"
#include <windows.h>
#include <knownfolders.h>
#include <shellapi.h>
#include <shlobj.h>
#include <shobjidl.h>
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/win/metro.h"
#include "base/win/scoped_co_mem.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/installer/util/browser_distribution.h"
#include "components/nacl/common/nacl_switches.h"
namespace chrome {
namespace {
bool GetUserDirectory(int csidl_folder, base::FilePath* result) {
wchar_t path_buf[MAX_PATH];
path_buf[0] = 0;
if (FAILED(SHGetFolderPath(NULL, csidl_folder, NULL,
SHGFP_TYPE_CURRENT, path_buf))) {
return false;
}
*result = base::FilePath(path_buf);
return true;
}
}
bool GetDefaultUserDataDirectory(base::FilePath* result) {
if (!PathService::Get(base::DIR_LOCAL_APP_DATA, result))
return false;
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
*result = result->Append(dist->GetInstallSubDir());
*result = result->Append(chrome::kUserDataDirname);
return true;
}
void GetUserCacheDirectory(const base::FilePath& profile_dir,
base::FilePath* result) {
*result = profile_dir;
}
bool GetUserDocumentsDirectory(base::FilePath* result) {
return GetUserDirectory(CSIDL_MYDOCUMENTS, result);
}
bool GetUserDownloadsDirectorySafe(base::FilePath* result) {
if (!GetUserDocumentsDirectory(result))
return false;
*result = result->Append(L"Downloads");
return true;
}
bool GetUserDownloadsDirectory(base::FilePath* result) {
typedef HRESULT (WINAPI *GetKnownFolderPath)(
REFKNOWNFOLDERID, DWORD, HANDLE, PWSTR*);
GetKnownFolderPath f = reinterpret_cast<GetKnownFolderPath>(
GetProcAddress(GetModuleHandle(L"shell32.dll"), "SHGetKnownFolderPath"));
base::win::ScopedCoMem<wchar_t> path_buf;
if (f && SUCCEEDED(f(FOLDERID_Downloads, 0, NULL, &path_buf))) {
*result = base::FilePath(std::wstring(path_buf));
return true;
}
return GetUserDownloadsDirectorySafe(result);
}
bool GetUserMusicDirectory(base::FilePath* result) {
return GetUserDirectory(CSIDL_MYMUSIC, result);
}
bool GetUserPicturesDirectory(base::FilePath* result) {
return GetUserDirectory(CSIDL_MYPICTURES, result);
}
bool GetUserVideosDirectory(base::FilePath* result) {
return GetUserDirectory(CSIDL_MYVIDEO, result);
}
bool ProcessNeedsProfileDir(const std::string& process_type) {
if (process_type.empty() || process_type == switches::kServiceProcess)
return true;
#if !defined(DISABLE_NACL)
if (process_type == switches::kNaClBrokerProcess ||
process_type == switches::kNaClLoaderProcess) {
return true;
}
#endif
return false;
}
}