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

Side by Side Diff: chrome/browser/chromeos/file_request_interceptor.cc

Issue 2790073002: wip (Closed)
Patch Set: Created 3 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/file_request_interceptor.h"
6 #include "base/threading/sequenced_worker_pool.h"
7 #include "content/public/browser/browser_thread.h"
8 #include "net/base/filename_util.h"
9 #include "net/url_request/url_request_file_job.h"
10
11 namespace chromeos {
12
13 namespace {
14 class FileRequestJob : public net::URLRequestFileJob {
15 public:
16 FileRequestJob(net::URLRequest* request,
17 net::NetworkDelegate* network_delegate,
18 const base::FilePath& file_path,
19 const scoped_refptr<base::TaskRunner>& file_task_runner)
20 : net::URLRequestFileJob(request,
21 network_delegate,
22 file_path,
23 file_task_runner) {}
24
25 protected:
26 bool OnFetchMetaInfo(
27 const net::URLRequestFileJob::FileMetaInfo& meta_info) override {
28 if (network_delegate() && !network_delegate()->CanAccessFile(
29 *request(), meta_info.absolute_path)) {
30 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
31 net::ERR_ACCESS_DENIED));
32 return false;
33 }
34 return true;
35 }
36 };
37
38 } // namespace
39
40 FileRequestInterceptor::FileRequestInterceptor() {}
41
42 FileRequestInterceptor::~FileRequestInterceptor() {}
43
44 net::URLRequestJob* FileRequestInterceptor::MaybeInterceptRequest(
45 net::URLRequest* request,
46 net::NetworkDelegate* network_delegate) const {
47 base::FilePath file_path;
48 if (request->url().scheme() == "file" &&
49 net::FileURLToFilePath(request->url(), &file_path) &&
50 !file_path.EndsWithSeparator()) {
51 return new FileRequestJob(
52 request, network_delegate, file_path,
53 content::BrowserThread::GetBlockingPool()
54 ->GetTaskRunnerWithShutdownBehavior(
55 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
56 } else {
57 return nullptr;
58 }
59 }
60
61 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698