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

Unified Diff: net/url_request/url_request_file_job.h

Issue 10695110: Avoid disk accesses on the wrong thread in URLRequestFileJob (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/url_request/url_request_file_job.cc » ('j') | net/url_request/url_request_file_job.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_file_job.h
===================================================================
--- net/url_request/url_request_file_job.h (revision 149338)
+++ net/url_request/url_request_file_job.h (working copy)
@@ -9,6 +9,7 @@
#include <vector>
#include "base/file_path.h"
+#include "base/memory/weak_ptr.h"
#include "net/base/file_stream.h"
#include "net/base/net_export.h"
#include "net/http/http_byte_range.h"
@@ -52,29 +53,55 @@
FilePath file_path_;
private:
+ // Meta information about the file. It's used as a member in the
+ // URLRequestFileJob and also passed between threads because disk access is
+ // necessary to obtain it.
+ struct FileMetaInfo {
+ // Size of the file.
+ int64 file_size;
+ // Mime type associated with the file.
+ std::string mime_type;
+ // Result returned from GetMimeTypeFromFile(), i.e. flag showing whether
+ // obtaining of the mime type was successful.
+ bool mime_type_result;
+ // Flag showing whether the file exists.
+ bool file_exists;
+ // Flag showing whether the file name is actually points to a directory.
wtc 2012/08/09 16:05:43 Nit: remove "is", or change "points" to "pointing"
+ bool is_directory;
+
+ FileMetaInfo();
wtc 2012/08/09 16:05:43 Declare the constructor before the data members.
+ };
+
// Tests to see if access to |path| is allowed. If g_allow_file_access_ is
// true, then this will return true. If the NetworkDelegate associated with
// the |request| says it's OK, then this will also return true.
static bool IsFileAccessAllowed(const URLRequest& request,
const FilePath& path);
+ // This function fetches file info on a background thread.
wtc 2012/08/09 16:05:43 Nit: here I did mean just "Fetches". In our comme
+ static void FetchMetaInfo(const FilePath& file_path,
+ FileMetaInfo* meta_info);
+
// Callback after fetching file info on a background thread.
- void DidResolve(bool exists, const base::PlatformFileInfo& file_info);
+ void DidFetchMetaInfo(const FileMetaInfo* meta_info);
+ // Callback after opening file on a background thread.
+ void DidOpen(int result);
+
+ // Callback after seeking to the necessary position in the file
wtc 2012/08/09 16:05:43 Nit: the use of "necessary" sounds a little strang
wtc 2012/08/14 18:00:40 paivanof wrote:
+ // on a background thread.
+ void DidSeek(int64 result);
+
// Callback after data is asynchronously read from the file.
void DidRead(int result);
- FileStream stream_;
- bool is_directory_;
+ scoped_ptr<FileStream> stream_;
+ FileMetaInfo meta_info_;
HttpByteRange byte_range_;
int64 remaining_bytes_;
- // The initial file metadata is fetched on a background thread.
- // AsyncResolver runs that task.
- class AsyncResolver;
- friend class AsyncResolver;
- scoped_refptr<AsyncResolver> async_resolver_;
+ base::WeakPtrFactory<URLRequestFileJob> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob);
};
« no previous file with comments | « no previous file | net/url_request/url_request_file_job.cc » ('j') | net/url_request/url_request_file_job.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698