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

Side by Side Diff: net/url_request/url_request_file_job.cc

Issue 10068021: Fix file access on Chrome for ChromeOS on Linux (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // For loading files, we make use of overlapped i/o to ensure that reading from 5 // For loading files, we make use of overlapped i/o to ensure that reading from
6 // the filesystem (e.g., a network filesystem) does not block the calling 6 // the filesystem (e.g., a network filesystem) does not block the calling
7 // thread. An alternative approach would be to use a background thread or pool 7 // thread. An alternative approach would be to use a background thread or pool
8 // of threads, but it seems better to leverage the operating system's ability 8 // of threads, but it seems better to leverage the operating system's ability
9 // to do background file reads for us. 9 // to do background file reads for us.
10 // 10 //
11 // Since overlapped reads require a 'static' buffer for the duration of the 11 // Since overlapped reads require a 'static' buffer for the duration of the
12 // asynchronous read, the URLRequestFileJob keeps a buffer as a member var. In 12 // asynchronous read, the URLRequestFileJob keeps a buffer as a member var. In
13 // URLRequestFileJob::Read, data is simply copied from the object's buffer into 13 // URLRequestFileJob::Read, data is simply copied from the object's buffer into
14 // the given buffer. If there is no data to copy, the URLRequestFileJob 14 // the given buffer. If there is no data to copy, the URLRequestFileJob
15 // attempts to read more from the file to fill its buffer. If reading from the 15 // attempts to read more from the file to fill its buffer. If reading from the
16 // file does not complete synchronously, then the URLRequestFileJob waits for a 16 // file does not complete synchronously, then the URLRequestFileJob waits for a
17 // signal from the OS that the overlapped read has completed. It does so by 17 // signal from the OS that the overlapped read has completed. It does so by
18 // leveraging the MessageLoop::WatchObject API. 18 // leveraging the MessageLoop::WatchObject API.
19 19
20 #include "net/url_request/url_request_file_job.h" 20 #include "net/url_request/url_request_file_job.h"
21 21
22 #include "base/bind.h" 22 #include "base/bind.h"
23 #include "base/chromeos/chromeos_version.h"
23 #include "base/compiler_specific.h" 24 #include "base/compiler_specific.h"
24 #include "base/message_loop.h" 25 #include "base/message_loop.h"
25 #include "base/platform_file.h" 26 #include "base/platform_file.h"
26 #include "base/string_util.h" 27 #include "base/string_util.h"
27 #include "base/synchronization/lock.h" 28 #include "base/synchronization/lock.h"
28 #include "base/threading/worker_pool.h" 29 #include "base/threading/worker_pool.h"
29 #include "base/threading/thread_restrictions.h" 30 #include "base/threading/thread_restrictions.h"
30 #include "build/build_config.h" 31 #include "build/build_config.h"
31 #include "googleurl/src/gurl.h" 32 #include "googleurl/src/gurl.h"
32 #include "net/base/io_buffer.h" 33 #include "net/base/io_buffer.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 "/tmp", 131 "/tmp",
131 "/var/log", 132 "/var/log",
132 }; 133 };
133 134
134 // static 135 // static
135 bool URLRequestFileJob::AccessDisabled(const FilePath& file_path) { 136 bool URLRequestFileJob::AccessDisabled(const FilePath& file_path) {
136 if (URLRequest::IsFileAccessAllowed()) { // for tests. 137 if (URLRequest::IsFileAccessAllowed()) { // for tests.
137 return false; 138 return false;
138 } 139 }
139 140
141 // If we're running Chrome for ChromeOS on Linux, we want to allow files
zel 2012/04/12 20:19:40 if this is for debugging only on Linux machines wi
Greg Spencer (Chromium) 2012/04/12 20:26:58 It's already inside of OS_CHROMEOS, and while I se
willchan no longer on Chromium 2012/04/12 23:44:59 Ugh, I don't know why this whitelist was allowed i
142 // within the user's Downloads directory.
143 if (!base::chromeos::IsRunningOnChromeOS()) {
144 const char* home = getenv("HOME");
145 if (home && strlen(home) > 0) {
146 FilePath home_path(home);
147 home_path.AppendASCII("Downloads");
148 if (home_path.IsParent(file_path))
149 return false;
150 }
151 }
152
140 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) { 153 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) {
141 const FilePath white_listed_path(kLocalAccessWhiteList[i]); 154 const FilePath white_listed_path(kLocalAccessWhiteList[i]);
142 // FilePath::operator== should probably handle trailing seperators. 155 // FilePath::operator== should probably handle trailing seperators.
143 if (white_listed_path == file_path.StripTrailingSeparators() || 156 if (white_listed_path == file_path.StripTrailingSeparators() ||
144 white_listed_path.IsParent(file_path)) { 157 white_listed_path.IsParent(file_path)) {
145 return false; 158 return false;
146 } 159 }
147 } 160 }
148 return true; 161 return true;
149 } 162 }
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); 373 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result));
361 } 374 }
362 375
363 remaining_bytes_ -= result; 376 remaining_bytes_ -= result;
364 DCHECK_GE(remaining_bytes_, 0); 377 DCHECK_GE(remaining_bytes_, 0);
365 378
366 NotifyReadComplete(result); 379 NotifyReadComplete(result);
367 } 380 }
368 381
369 } // namespace net 382 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698