Commit 0b695eb4 authored by Yann Dago's avatar Yann Dago Committed by Commit Bot

LBS: switch back from ie to opening chrome instance

When navigating back from IE to Chrome using LBS, the latest Chrome
installation was opened, unless the admin specified a Chrome path to
use. By writing the chrome path of the browser that initiated the IE
navigation cache.dat, the chrome instance was used last will be the
one we back to.

Bug: 1005849
Change-Id: Iad4c4d601eedcc8cd7d9bee6f0f90143352f96fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2004949
Commit-Queue: Yann Dago <ydago@chromium.org>
Reviewed-by: default avatarNicolas Ouellet-Payeur <nicolaso@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733994}
parent 848c651c
......@@ -6,7 +6,9 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "chrome/browser/browser_switcher/browser_switcher_sitelist.h"
......@@ -16,6 +18,10 @@
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_thread.h"
#if defined(OS_WIN)
#include <windows.h>
#endif
namespace browser_switcher {
namespace {
......@@ -215,7 +221,7 @@ bool BrowserSwitcherPrefs::UseIeSitelist() const {
return prefs_->GetBoolean(prefs::kUseIeSitelist);
}
const std::string& BrowserSwitcherPrefs::GetChromePath() const {
const base::FilePath& BrowserSwitcherPrefs::GetChromePath() const {
return chrome_path_;
}
......@@ -319,7 +325,14 @@ void BrowserSwitcherPrefs::GreylistChanged() {
void BrowserSwitcherPrefs::ChromePathChanged() {
chrome_path_.clear();
if (prefs_->IsManagedPreference(prefs::kChromePath))
chrome_path_ = prefs_->GetString(prefs::kChromePath);
chrome_path_ = prefs_->GetFilePath(prefs::kChromePath);
#if defined(OS_WIN)
if (chrome_path_.empty()) {
base::FilePath::CharType chrome_path[MAX_PATH];
::GetModuleFileName(NULL, chrome_path, ARRAYSIZE(chrome_path));
chrome_path_ = base::FilePath(chrome_path);
}
#endif
}
void BrowserSwitcherPrefs::ChromeParametersChanged() {
......
......@@ -10,6 +10,7 @@
#include "base/callback.h"
#include "base/callback_list.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "build/build_config.h"
......@@ -112,7 +113,7 @@ class BrowserSwitcherPrefs : public KeyedService,
// Returns the path to the Chrome executable to launch when switching from IE,
// before substitutions.
const std::string& GetChromePath() const;
const base::FilePath& GetChromePath() const;
// Returns the arguments to pass to Chrome when switching from IE, before
// substitutions.
......@@ -165,7 +166,7 @@ class BrowserSwitcherPrefs : public KeyedService,
std::string alt_browser_path_;
std::vector<std::string> alt_browser_params_;
#if defined(OS_WIN)
std::string chrome_path_;
base::FilePath chrome_path_;
std::vector<std::string> chrome_params_;
#endif
......
......@@ -114,7 +114,7 @@ TEST_F(BrowserSwitcherPrefsTest, ListensForPrefChanges) {
EXPECT_EQ("c", prefs()->GetAlternativeBrowserParameters()[2]);
#if defined(OS_WIN)
EXPECT_EQ("cmd.exe", prefs()->GetChromePath());
EXPECT_EQ("cmd.exe", prefs()->GetChromePath().MaybeAsASCII());
EXPECT_EQ(3u, prefs()->GetChromeParameters().size());
EXPECT_EQ("d", prefs()->GetChromeParameters()[0]);
......
......@@ -768,22 +768,29 @@ IN_PROC_BROWSER_TEST_F(BrowserSwitcherServiceTest, WritesSitelistsToCacheFile) {
base::File::FLAG_OPEN | base::File::FLAG_READ);
ASSERT_TRUE(file.IsValid());
const char expected_output[] =
base::FilePath expected_chrome_path;
base::FilePath::CharType chrome_path[MAX_PATH];
#if defined(OS_WIN)
::GetModuleFileName(NULL, chrome_path, ARRAYSIZE(chrome_path));
expected_chrome_path = base::FilePath(chrome_path);
#endif
std::string expected_output = base::StringPrintf(
"1\n"
"\n"
"\n"
"\n"
"%s\n"
"\n"
"2\n"
"docs.google.com\n"
"yahoo.com\n"
"1\n"
"greylist.invalid.com\n";
"greylist.invalid.com\n",
expected_chrome_path.MaybeAsASCII().c_str());
std::unique_ptr<char[]> buffer(new char[file.GetLength() + 1]);
buffer.get()[file.GetLength()] = '\0';
file.Read(0, buffer.get(), file.GetLength());
EXPECT_EQ(std::string(expected_output), std::string(buffer.get()));
EXPECT_EQ(expected_output, std::string(buffer.get()));
// Check that sitelistcache.dat doesn't exist.
EXPECT_FALSE(base::PathExists(sitelist_cache_file_path));
......@@ -843,21 +850,27 @@ IN_PROC_BROWSER_TEST_F(BrowserSwitcherServiceTest, CacheFileCorrectOnStartup) {
base::File file(cache_file_path,
base::File::FLAG_OPEN | base::File::FLAG_READ);
ASSERT_TRUE(file.IsValid());
const char expected_output[] =
base::FilePath expected_chrome_path;
base::FilePath::CharType chrome_path[MAX_PATH];
#if defined(OS_WIN)
::GetModuleFileName(NULL, chrome_path, ARRAYSIZE(chrome_path));
expected_chrome_path = base::FilePath(chrome_path);
#endif
std::string expected_output = base::StringPrintf(
"1\n"
"\n"
"\n"
"\n"
"%s\n"
"\n"
"1\n"
"docs.google.com\n"
"0\n";
"0\n",
expected_chrome_path.MaybeAsASCII().c_str());
std::unique_ptr<char[]> buffer(new char[file.GetLength() + 1]);
buffer.get()[file.GetLength()] = '\0';
file.Read(0, buffer.get(), file.GetLength());
EXPECT_EQ(std::string(expected_output), std::string(buffer.get()));
EXPECT_EQ(expected_output, std::string(buffer.get()));
std::move(quit).Run();
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment