Skip to content

Commit

Permalink
Make redirects work on canary by looking in the correct profile
Browse files Browse the repository at this point in the history
BUG=334379

Review URL: https://codereview.chromium.org/156103004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249806 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
caitkp@chromium.org committed Feb 7, 2014
1 parent 69c355d commit a8eab3b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
9 changes: 5 additions & 4 deletions chrome_elf/chrome_elf_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

#include "chrome_elf/chrome_elf_constants.h"

const wchar_t kUserDataDirName[] = L"User Data";
const wchar_t kPreferencesFilename[] = L"Preferences";
const wchar_t kLocalStateFilename[] = L"Local State";

#if defined(GOOGLE_CHROME_BUILD)
const wchar_t kAppDataDirName[] = L"Google\\Chrome";
#else
const wchar_t kAppDataDirName[] = L"Chromium";
#endif
const wchar_t kCanaryAppDataDirName[] = L"Google\\Chrome SxS";
const wchar_t kLocalStateFilename[] = L"Local State";
const wchar_t kPreferencesFilename[] = L"Preferences";
const wchar_t kUserDataDirName[] = L"User Data";

3 changes: 2 additions & 1 deletion chrome_elf/chrome_elf_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

// directory names
extern const wchar_t kAppDataDirName[];
extern const wchar_t kPreferencesFilename[];
extern const wchar_t kCanaryAppDataDirName[];
extern const wchar_t kLocalStateFilename[];
extern const wchar_t kPreferencesFilename[];
extern const wchar_t kUserDataDirName[];

#endif // CHROME_ELF_CHROME_ELF_CONSTANTS_H_
14 changes: 13 additions & 1 deletion chrome_elf/create_file/chrome_create_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ HANDLE CreateFileNTDLL(
return file_handle;
}

bool IsCanary(LPWSTR exe_path) {
wchar_t* found = wcsstr(exe_path, L"Google\\Chrome SxS");
return !!found;
}

bool ShouldBypass(LPCWSTR file_path) {
// If the shell functions are not present, forward the call to kernel32.
if (!PopulateShellFunctions())
Expand All @@ -259,10 +264,17 @@ bool ShouldBypass(LPCWSTR file_path) {
HRESULT appdata_result = g_get_folder_func(
NULL, CSIDL_LOCAL_APPDATA, NULL, 0, local_appdata_path);

wchar_t buffer[MAX_PATH] = {};
if (!GetModuleFileNameW(NULL, buffer, MAX_PATH))
return false;

bool is_canary = IsCanary(buffer);

// If getting the %LOCALAPPDATA% path or appending to it failed, then forward
// the call to kernel32.
if (!SUCCEEDED(appdata_result) ||
!g_path_append_func(local_appdata_path, kAppDataDirName) ||
!g_path_append_func(local_appdata_path, is_canary ?
kCanaryAppDataDirName : kAppDataDirName) ||
!g_path_append_func(local_appdata_path, kUserDataDirName)) {
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions chrome_elf/create_file/chrome_create_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ HANDLE CreateFileNTDLL(
// system version (only uses ours if we're writing to the user data directory).
bool ShouldBypass(LPCWSTR file_name);

// Returns true if |exe_path| points to a Chrome installed in a SxS
// installation.
bool IsCanary(LPWSTR exe_path);

#endif // CHROME_ELF_CREATE_FILE_CHROME_CREATE_FILE_H_
6 changes: 6 additions & 0 deletions chrome_elf/create_file/chrome_create_file_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ TEST_F(ChromeCreateFileTest, CheckParams_FILE_FLAG_OPEN_NO_RECALL) {
ResetNtCreateFileCalls();
}

TEST_F(ChromeCreateFileTest, CanaryTest) {
EXPECT_TRUE(IsCanary(L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS"));
EXPECT_FALSE(IsCanary(L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome"));
EXPECT_FALSE(IsCanary(L"C:\\Users\\user\\AppData\\Local\\Chromium"));
}

TEST_F(ChromeCreateFileTest, BypassTest) {
std::wstring UNC_filepath_file(L"\\\\.\\some_file.txt");

Expand Down

0 comments on commit a8eab3b

Please sign in to comment.