OLD | NEW |
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_url_request_job.h" | 5 #include "webkit/browser/fileapi/file_system_url_request_job.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 weak_factory_.GetWeakPtr())); | 69 weak_factory_.GetWeakPtr())); |
70 base::MessageLoop::current()->RunUntilIdle(); | 70 base::MessageLoop::current()->RunUntilIdle(); |
71 | 71 |
72 net::URLRequest::Deprecated::RegisterProtocolFactory( | 72 net::URLRequest::Deprecated::RegisterProtocolFactory( |
73 "filesystem", &FileSystemURLRequestJobFactory); | 73 "filesystem", &FileSystemURLRequestJobFactory); |
74 } | 74 } |
75 | 75 |
76 virtual void TearDown() OVERRIDE { | 76 virtual void TearDown() OVERRIDE { |
77 net::URLRequest::Deprecated::RegisterProtocolFactory("filesystem", NULL); | 77 net::URLRequest::Deprecated::RegisterProtocolFactory("filesystem", NULL); |
78 ClearUnusedJob(); | 78 ClearUnusedJob(); |
79 if (pending_job_) { | 79 if (pending_job_.get()) { |
80 pending_job_->Kill(); | 80 pending_job_->Kill(); |
81 pending_job_ = NULL; | 81 pending_job_ = NULL; |
82 } | 82 } |
83 // FileReader posts a task to close the file in destructor. | 83 // FileReader posts a task to close the file in destructor. |
84 base::MessageLoop::current()->RunUntilIdle(); | 84 base::MessageLoop::current()->RunUntilIdle(); |
85 } | 85 } |
86 | 86 |
87 void OnOpenFileSystem(base::PlatformFileError result) { | 87 void OnOpenFileSystem(base::PlatformFileError result) { |
88 ASSERT_EQ(base::PLATFORM_FILE_OK, result); | 88 ASSERT_EQ(base::PLATFORM_FILE_OK, result); |
89 } | 89 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 123 } |
124 | 124 |
125 void CreateDirectory(const base::StringPiece& dir_name) { | 125 void CreateDirectory(const base::StringPiece& dir_name) { |
126 FileSystemFileUtil* file_util = file_system_context_-> | 126 FileSystemFileUtil* file_util = file_system_context_-> |
127 sandbox_provider()->GetFileUtil(kFileSystemTypeTemporary); | 127 sandbox_provider()->GetFileUtil(kFileSystemTypeTemporary); |
128 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 128 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
129 GURL("http://remote"), | 129 GURL("http://remote"), |
130 kFileSystemTypeTemporary, | 130 kFileSystemTypeTemporary, |
131 base::FilePath().AppendASCII(dir_name)); | 131 base::FilePath().AppendASCII(dir_name)); |
132 | 132 |
133 FileSystemOperationContext context(file_system_context_); | 133 FileSystemOperationContext context(file_system_context_.get()); |
134 context.set_allowed_bytes_growth(1024); | 134 context.set_allowed_bytes_growth(1024); |
135 | 135 |
136 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateDirectory( | 136 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateDirectory( |
137 &context, | 137 &context, |
138 url, | 138 url, |
139 false /* exclusive */, | 139 false /* exclusive */, |
140 false /* recursive */)); | 140 false /* recursive */)); |
141 } | 141 } |
142 | 142 |
143 void WriteFile(const base::StringPiece& file_name, | 143 void WriteFile(const base::StringPiece& file_name, |
144 const char* buf, int buf_size) { | 144 const char* buf, int buf_size) { |
145 FileSystemFileUtil* file_util = file_system_context_-> | 145 FileSystemFileUtil* file_util = file_system_context_-> |
146 sandbox_provider()->GetFileUtil(kFileSystemTypeTemporary); | 146 sandbox_provider()->GetFileUtil(kFileSystemTypeTemporary); |
147 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 147 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
148 GURL("http://remote"), | 148 GURL("http://remote"), |
149 kFileSystemTypeTemporary, | 149 kFileSystemTypeTemporary, |
150 base::FilePath().AppendASCII(file_name)); | 150 base::FilePath().AppendASCII(file_name)); |
151 | 151 |
152 FileSystemOperationContext context(file_system_context_); | 152 FileSystemOperationContext context(file_system_context_.get()); |
153 context.set_allowed_bytes_growth(1024); | 153 context.set_allowed_bytes_growth(1024); |
154 | 154 |
155 base::PlatformFile handle = base::kInvalidPlatformFileValue; | 155 base::PlatformFile handle = base::kInvalidPlatformFileValue; |
156 bool created = false; | 156 bool created = false; |
157 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateOrOpen( | 157 ASSERT_EQ(base::PLATFORM_FILE_OK, file_util->CreateOrOpen( |
158 &context, | 158 &context, |
159 url, | 159 url, |
160 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, | 160 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, |
161 &handle, | 161 &handle, |
162 &created)); | 162 &created)); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 351 |
352 TestRequest(CreateFileSystemURL(kFilename)); | 352 TestRequest(CreateFileSystemURL(kFilename)); |
353 | 353 |
354 std::string mime_type_from_job; | 354 std::string mime_type_from_job; |
355 request_->GetMimeType(&mime_type_from_job); | 355 request_->GetMimeType(&mime_type_from_job); |
356 EXPECT_EQ(mime_type_direct, mime_type_from_job); | 356 EXPECT_EQ(mime_type_direct, mime_type_from_job); |
357 } | 357 } |
358 | 358 |
359 } // namespace | 359 } // namespace |
360 } // namespace fileapi | 360 } // namespace fileapi |
OLD | NEW |