Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2642)

Unified Diff: chrome/browser/net/chrome_network_delegate.cc

Issue 2657903005: Factor out core logic from OnCanAccessFile() and add tests for it (Closed)
Patch Set: android build Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/net/chrome_network_delegate.cc
diff --git a/chrome/browser/net/chrome_network_delegate.cc b/chrome/browser/net/chrome_network_delegate.cc
index 0a2b6b5c0e6cedb37a8f3da56d420fc28ef0e6fc..47508d329d26d282c17c9398d6b338f809fad3f0 100644
--- a/chrome/browser/net/chrome_network_delegate.cc
+++ b/chrome/browser/net/chrome_network_delegate.cc
@@ -451,17 +451,27 @@ bool ChromeNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
const base::FilePath& path) const {
-#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
- return true;
-#else
#if defined(OS_CHROMEOS)
// If we're running Chrome for ChromeOS on Linux, we want to allow file
- // access.
+ // access. This is checked here to make IsAccessAllowed() unit-testable.
if (!base::SysInfo::IsRunningOnChromeOS() ||
base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
return true;
}
+#endif
+
+ return IsAccessAllowed(path, profile_path_);
+}
+// static
+bool ChromeNetworkDelegate::IsAccessAllowed(
+ const base::FilePath& path,
+ const base::FilePath& profile_path) {
+#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
+ return true;
+#else
+
+#if defined(OS_CHROMEOS)
// Use a whitelist to only allow access to files residing in the list of
// directories below.
static const char* const kLocalAccessWhiteList[] = {
@@ -480,11 +490,11 @@ bool ChromeNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
// logged in profile.) For the support of multi-profile sessions, we are
// switching to use explicit "$PROFILE_PATH/Xyz" path and here whitelist such
// access.
- if (!profile_path_.empty()) {
- const base::FilePath downloads = profile_path_.AppendASCII("Downloads");
+ if (!profile_path.empty()) {
+ const base::FilePath downloads = profile_path.AppendASCII("Downloads");
if (downloads == path.StripTrailingSeparators() || downloads.IsParent(path))
return true;
- const base::FilePath webrtc_logs = profile_path_.AppendASCII("WebRTC Logs");
+ const base::FilePath webrtc_logs = profile_path.AppendASCII("WebRTC Logs");
if (webrtc_logs == path.StripTrailingSeparators() ||
webrtc_logs.IsParent(path)) {
return true;

Powered by Google App Engine
This is Rietveld 408576698