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

Side by Side Diff: webkit/browser/fileapi/file_system_dir_url_request_job.cc

Issue 195923002: Add mechanism to auto mount file systems in response to a URL request. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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
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 #include "webkit/browser/fileapi/file_system_dir_url_request_job.h" 5 #include "webkit/browser/fileapi/file_system_dir_url_request_job.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 17 matching lines...) Expand all
28 using net::NetworkDelegate; 28 using net::NetworkDelegate;
29 using net::URLRequest; 29 using net::URLRequest;
30 using net::URLRequestJob; 30 using net::URLRequestJob;
31 using net::URLRequestStatus; 31 using net::URLRequestStatus;
32 32
33 namespace fileapi { 33 namespace fileapi {
34 34
35 FileSystemDirURLRequestJob::FileSystemDirURLRequestJob( 35 FileSystemDirURLRequestJob::FileSystemDirURLRequestJob(
36 URLRequest* request, 36 URLRequest* request,
37 NetworkDelegate* network_delegate, 37 NetworkDelegate* network_delegate,
38 const std::string& storage_domain,
38 FileSystemContext* file_system_context) 39 FileSystemContext* file_system_context)
39 : URLRequestJob(request, network_delegate), 40 : URLRequestJob(request, network_delegate),
41 storage_domain_(storage_domain),
40 file_system_context_(file_system_context), 42 file_system_context_(file_system_context),
41 weak_factory_(this) { 43 weak_factory_(this) {
42 } 44 }
43 45
44 FileSystemDirURLRequestJob::~FileSystemDirURLRequestJob() { 46 FileSystemDirURLRequestJob::~FileSystemDirURLRequestJob() {
45 } 47 }
46 48
47 bool FileSystemDirURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size, 49 bool FileSystemDirURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size,
48 int *bytes_read) { 50 int *bytes_read) {
49 int count = std::min(dest_size, static_cast<int>(data_.size())); 51 int count = std::min(dest_size, static_cast<int>(data_.size()));
(...skipping 24 matching lines...) Expand all
74 76
75 bool FileSystemDirURLRequestJob::GetCharset(std::string* charset) { 77 bool FileSystemDirURLRequestJob::GetCharset(std::string* charset) {
76 *charset = "utf-8"; 78 *charset = "utf-8";
77 return true; 79 return true;
78 } 80 }
79 81
80 void FileSystemDirURLRequestJob::StartAsync() { 82 void FileSystemDirURLRequestJob::StartAsync() {
81 if (!request_) 83 if (!request_)
82 return; 84 return;
83 url_ = file_system_context_->CrackURL(request_->url()); 85 url_ = file_system_context_->CrackURL(request_->url());
86 if (!url_.is_valid()) {
87 file_system_context_->AttemptAutoMountForURLRequest(
88 request_,
89 storage_domain_,
90 base::Bind(&FileSystemDirURLRequestJob::DidAttemptAutoMount,
91 weak_factory_.GetWeakPtr()));
92 }
84 if (!file_system_context_->CanServeURLRequest(url_)) { 93 if (!file_system_context_->CanServeURLRequest(url_)) {
85 // In incognito mode the API is not usable and there should be no data. 94 // In incognito mode the API is not usable and there should be no data.
86 if (url_.is_valid() && VirtualPath::IsRootPath(url_.virtual_path())) { 95 if (url_.is_valid() && VirtualPath::IsRootPath(url_.virtual_path())) {
87 // Return an empty directory if the filesystem root is queried. 96 // Return an empty directory if the filesystem root is queried.
88 DidReadDirectory(base::File::FILE_OK, 97 DidReadDirectory(base::File::FILE_OK,
89 std::vector<DirectoryEntry>(), 98 std::vector<DirectoryEntry>(),
90 false); 99 false);
91 return; 100 return;
92 } 101 }
93 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 102 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
94 net::ERR_FILE_NOT_FOUND)); 103 net::ERR_FILE_NOT_FOUND));
95 return; 104 return;
96 } 105 }
97 file_system_context_->operation_runner()->ReadDirectory( 106 file_system_context_->operation_runner()->ReadDirectory(
98 url_, 107 url_,
99 base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this)); 108 base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this));
100 } 109 }
101 110
111 void FileSystemDirURLRequestJob::DidAttemptAutoMount(base::File::Error result) {
112 if (result >= 0 &&
113 file_system_context_->CrackURL(request_->url()).is_valid()) {
114 StartAsync();
115 } else {
116 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
117 net::ERR_FILE_NOT_FOUND));
118 }
119 }
120
102 void FileSystemDirURLRequestJob::DidReadDirectory( 121 void FileSystemDirURLRequestJob::DidReadDirectory(
103 base::File::Error result, 122 base::File::Error result,
104 const std::vector<DirectoryEntry>& entries, 123 const std::vector<DirectoryEntry>& entries,
105 bool has_more) { 124 bool has_more) {
106 if (result != base::File::FILE_OK) { 125 if (result != base::File::FILE_OK) {
107 int rv = net::ERR_FILE_NOT_FOUND; 126 int rv = net::ERR_FILE_NOT_FOUND;
108 if (result == base::File::FILE_ERROR_INVALID_URL) 127 if (result == base::File::FILE_ERROR_INVALID_URL)
109 rv = net::ERR_INVALID_URL; 128 rv = net::ERR_INVALID_URL;
110 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); 129 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
111 return; 130 return;
(...skipping 20 matching lines...) Expand all
132 it->last_modified_time)); 151 it->last_modified_time));
133 } 152 }
134 153
135 if (!has_more) { 154 if (!has_more) {
136 set_expected_content_size(data_.size()); 155 set_expected_content_size(data_.size());
137 NotifyHeadersComplete(); 156 NotifyHeadersComplete();
138 } 157 }
139 } 158 }
140 159
141 } // namespace fileapi 160 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698