1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/fileapi/file_system_url_request_job_base.h"
#include "base/message_loop.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_request.h"
using net::URLRequest;
using net::URLRequestJob;
using net::URLRequestStatus;
namespace fileapi {
class LocalPathCallbackDispatcher : public FileSystemCallbackDispatcher {
public:
explicit LocalPathCallbackDispatcher(
FileSystemURLRequestJobBase* request)
: request_(request),
io_loop_(base::MessageLoopProxy::CreateForCurrentThread()) {
DCHECK(request_);
}
// fileapi::FileSystemCallbackDispatcher overrides.
virtual void DidSucceed() OVERRIDE {
NOTREACHED();
}
virtual void DidGetLocalPath(const FilePath& local_path) {
io_loop_->PostTask(FROM_HERE,
NewRunnableMethod(request_,
&FileSystemURLRequestJobBase::OnGetLocalPath,
local_path));
}
virtual void DidReadMetadata(const base::PlatformFileInfo& info,
const FilePath& unused) OVERRIDE {
NOTREACHED();
}
virtual void DidReadDirectory(
const std::vector<base::FileUtilProxy::Entry>& entries,
bool has_more) OVERRIDE {
NOTREACHED();
}
virtual void DidWrite(int64 bytes, bool complete) OVERRIDE {
NOTREACHED();
}
virtual void DidOpenFileSystem(const std::string& name,
const GURL& root_path) OVERRIDE {
NOTREACHED();
}
virtual void DidFail(base::PlatformFileError error_code) OVERRIDE {
io_loop_->PostTask(FROM_HERE,
NewRunnableMethod(request_,
&FileSystemURLRequestJobBase::RespondFailedOnIOThread,
error_code));
}
private:
FileSystemURLRequestJobBase* request_;
scoped_refptr<base::MessageLoopProxy> io_loop_;
DISALLOW_COPY_AND_ASSIGN(LocalPathCallbackDispatcher);
};
FileSystemURLRequestJobBase::FileSystemURLRequestJobBase(
URLRequest* request, FileSystemContext* file_system_context,
scoped_refptr<base::MessageLoopProxy> file_thread_proxy)
: URLRequestJob(request),
file_system_context_(file_system_context),
file_thread_proxy_(file_thread_proxy) {
}
FileSystemURLRequestJobBase::~FileSystemURLRequestJobBase() {
}
FileSystemOperation* FileSystemURLRequestJobBase::GetNewOperation() {
LocalPathCallbackDispatcher* dispatcher =
new LocalPathCallbackDispatcher(this);
FileSystemOperation* operation = new FileSystemOperation(
dispatcher,
file_thread_proxy_,
file_system_context_,
NULL);
return operation;
}
void FileSystemURLRequestJobBase::StartAsync() {
GetNewOperation()->GetLocalPath(request_->url());
}
void FileSystemURLRequestJobBase::RespondFailedOnIOThread(int error_code) {
int rv = net::ERR_FILE_NOT_FOUND;
if (error_code == base::PLATFORM_FILE_ERROR_INVALID_URL)
rv = net::ERR_INVALID_URL;
NotifyFailed(rv);
}
void FileSystemURLRequestJobBase::NotifyFailed(int rv) {
NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
}
void FileSystemURLRequestJobBase::OnGetLocalPath(
const FilePath& local_path) {
DidGetLocalPath(local_path);
}
} // namespace fileapi
|