OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 // |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 76 } |
77 | 77 |
78 URLRequestFileJob* owner_; | 78 URLRequestFileJob* owner_; |
79 | 79 |
80 Lock lock_; | 80 Lock lock_; |
81 MessageLoop* owner_loop_; | 81 MessageLoop* owner_loop_; |
82 }; | 82 }; |
83 #endif | 83 #endif |
84 | 84 |
85 // static | 85 // static |
86 URLRequestJob* URLRequestFileJob::Factory( | 86 URLRequestJob* URLRequestFileJob::Factory(net::URLRequest* request, |
87 URLRequest* request, const std::string& scheme) { | 87 const std::string& scheme) { |
88 | 88 |
89 FilePath file_path; | 89 FilePath file_path; |
90 const bool is_file = net::FileURLToFilePath(request->url(), &file_path); | 90 const bool is_file = net::FileURLToFilePath(request->url(), &file_path); |
91 | 91 |
92 #if defined(OS_CHROMEOS) | 92 #if defined(OS_CHROMEOS) |
93 // Check file access. | 93 // Check file access. |
94 if (AccessDisabled(file_path)) | 94 if (AccessDisabled(file_path)) |
95 return new URLRequestErrorJob(request, net::ERR_ACCESS_DENIED); | 95 return new URLRequestErrorJob(request, net::ERR_ACCESS_DENIED); |
96 #endif | 96 #endif |
97 | 97 |
98 // We need to decide whether to create URLRequestFileJob for file access or | 98 // We need to decide whether to create URLRequestFileJob for file access or |
99 // URLRequestFileDirJob for directory access. To avoid accessing the | 99 // URLRequestFileDirJob for directory access. To avoid accessing the |
100 // filesystem, we only look at the path string here. | 100 // filesystem, we only look at the path string here. |
101 // The code in the URLRequestFileJob::Start() method discovers that a path, | 101 // The code in the URLRequestFileJob::Start() method discovers that a path, |
102 // which doesn't end with a slash, should really be treated as a directory, | 102 // which doesn't end with a slash, should really be treated as a directory, |
103 // and it then redirects to the URLRequestFileDirJob. | 103 // and it then redirects to the URLRequestFileDirJob. |
104 if (is_file && | 104 if (is_file && |
105 file_util::EndsWithSeparator(file_path) && | 105 file_util::EndsWithSeparator(file_path) && |
106 file_path.IsAbsolute()) | 106 file_path.IsAbsolute()) |
107 return new URLRequestFileDirJob(request, file_path); | 107 return new URLRequestFileDirJob(request, file_path); |
108 | 108 |
109 // Use a regular file request job for all non-directories (including invalid | 109 // Use a regular file request job for all non-directories (including invalid |
110 // file names). | 110 // file names). |
111 return new URLRequestFileJob(request, file_path); | 111 return new URLRequestFileJob(request, file_path); |
112 } | 112 } |
113 | 113 |
114 URLRequestFileJob::URLRequestFileJob(URLRequest* request, | 114 URLRequestFileJob::URLRequestFileJob(net::URLRequest* request, |
115 const FilePath& file_path) | 115 const FilePath& file_path) |
116 : URLRequestJob(request), | 116 : URLRequestJob(request), |
117 file_path_(file_path), | 117 file_path_(file_path), |
118 ALLOW_THIS_IN_INITIALIZER_LIST( | 118 ALLOW_THIS_IN_INITIALIZER_LIST( |
119 io_callback_(this, &URLRequestFileJob::DidRead)), | 119 io_callback_(this, &URLRequestFileJob::DidRead)), |
120 is_directory_(false), | 120 is_directory_(false), |
121 remaining_bytes_(0) { | 121 remaining_bytes_(0) { |
122 } | 122 } |
123 | 123 |
124 URLRequestFileJob::~URLRequestFileJob() { | 124 URLRequestFileJob::~URLRequestFileJob() { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 static const char* const kLocalAccessWhiteList[] = { | 360 static const char* const kLocalAccessWhiteList[] = { |
361 "/home/chronos/user/Downloads", | 361 "/home/chronos/user/Downloads", |
362 "/mnt/partner_partition", | 362 "/mnt/partner_partition", |
363 "/usr/share/chromeos-assets", | 363 "/usr/share/chromeos-assets", |
364 "/tmp", | 364 "/tmp", |
365 "/var/log", | 365 "/var/log", |
366 }; | 366 }; |
367 | 367 |
368 // static | 368 // static |
369 bool URLRequestFileJob::AccessDisabled(const FilePath& file_path) { | 369 bool URLRequestFileJob::AccessDisabled(const FilePath& file_path) { |
370 if (URLRequest::IsFileAccessAllowed()) { // for tests. | 370 if (net::URLRequest::IsFileAccessAllowed()) { // for tests. |
371 return false; | 371 return false; |
372 } | 372 } |
373 | 373 |
374 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) { | 374 for (size_t i = 0; i < arraysize(kLocalAccessWhiteList); ++i) { |
375 const FilePath white_listed_path(kLocalAccessWhiteList[i]); | 375 const FilePath white_listed_path(kLocalAccessWhiteList[i]); |
376 // FilePath::operator== should probably handle trailing seperators. | 376 // FilePath::operator== should probably handle trailing seperators. |
377 if (white_listed_path == file_path.StripTrailingSeparators() || | 377 if (white_listed_path == file_path.StripTrailingSeparators() || |
378 white_listed_path.IsParent(file_path)) { | 378 white_listed_path.IsParent(file_path)) { |
379 return false; | 379 return false; |
380 } | 380 } |
381 } | 381 } |
382 return true; | 382 return true; |
383 } | 383 } |
384 #endif | 384 #endif |
385 | 385 |
OLD | NEW |