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

Side by Side 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: Avoid disk accesses on the wrong thread in URLRequestFileJob Created 8 years, 4 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
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 #ifndef NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ 5 #ifndef NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_
6 #define NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ 6 #define NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/memory/weak_ptr.h"
12 #include "net/base/file_stream.h" 13 #include "net/base/file_stream.h"
13 #include "net/base/net_export.h" 14 #include "net/base/net_export.h"
14 #include "net/http/http_byte_range.h" 15 #include "net/http/http_byte_range.h"
15 #include "net/url_request/url_request.h" 16 #include "net/url_request/url_request.h"
16 #include "net/url_request/url_request_job.h" 17 #include "net/url_request/url_request_job.h"
17 18
18 namespace file_util { 19 namespace file_util {
19 struct FileInfo; 20 struct FileInfo;
20 } 21 }
21 22
(...skipping 23 matching lines...) Expand all
45 virtual void SetExtraRequestHeaders( 46 virtual void SetExtraRequestHeaders(
46 const HttpRequestHeaders& headers) OVERRIDE; 47 const HttpRequestHeaders& headers) OVERRIDE;
47 48
48 protected: 49 protected:
49 virtual ~URLRequestFileJob(); 50 virtual ~URLRequestFileJob();
50 51
51 // The OS-specific full path name of the file 52 // The OS-specific full path name of the file
52 FilePath file_path_; 53 FilePath file_path_;
53 54
54 private: 55 private:
56 // Meta information about the file. It's used as a member in the
57 // URLRequestFileJob and also passed between threads because disk access is
58 // necessary to obtain it.
59 struct FileMetaInfo {
60 FileMetaInfo();
61
62 // Size of the file.
63 int64 file_size;
64 // Mime type associated with the file.
65 std::string mime_type;
66 // Result returned from GetMimeTypeFromFile(), i.e. flag showing whether
67 // obtaining of the mime type was successful.
68 bool mime_type_result;
69 // Flag showing whether the file exists.
70 bool file_exists;
wtc 2012/08/14 18:00:40 Nit: I suggest listing the struct members in this
pivanof 2012/08/15 06:36:50 I've placed members like that to avoid unnecessary
wtc 2012/08/17 00:24:04 Ah, I see. Then please disregard my suggestion.
71 // Flag showing whether the file name actually refers to a directory.
72 bool is_directory;
73 };
74
55 // Tests to see if access to |path| is allowed. If g_allow_file_access_ is 75 // Tests to see if access to |path| is allowed. If g_allow_file_access_ is
56 // true, then this will return true. If the NetworkDelegate associated with 76 // true, then this will return true. If the NetworkDelegate associated with
57 // the |request| says it's OK, then this will also return true. 77 // the |request| says it's OK, then this will also return true.
58 static bool IsFileAccessAllowed(const URLRequest& request, 78 static bool IsFileAccessAllowed(const URLRequest& request,
59 const FilePath& path); 79 const FilePath& path);
60 80
81 // Fetches file info on a background thread.
82 static void FetchMetaInfo(const FilePath& file_path,
83 FileMetaInfo* meta_info);
84
61 // Callback after fetching file info on a background thread. 85 // Callback after fetching file info on a background thread.
62 void DidResolve(bool exists, const base::PlatformFileInfo& file_info); 86 void DidFetchMetaInfo(const FileMetaInfo* meta_info);
wtc 2012/08/14 18:00:40 Nit: should the input parameter be a const referen
pivanof 2012/08/15 06:36:50 IIUC, with const reference PostTaskAndReply will s
87
88 // Callback after opening file on a background thread.
89 void DidOpen(int result);
90
91 // Callback after seeking to the requested position in the file
92 // on a background thread.
wtc 2012/08/17 00:24:04 Please change this comment to: // Callback after
93 void DidSeek(int64 result);
63 94
64 // Callback after data is asynchronously read from the file. 95 // Callback after data is asynchronously read from the file.
65 void DidRead(int result); 96 void DidRead(int result);
66 97
67 FileStream stream_; 98 scoped_ptr<FileStream> stream_;
68 bool is_directory_; 99 FileMetaInfo meta_info_;
69 100
70 HttpByteRange byte_range_; 101 HttpByteRange byte_range_;
71 int64 remaining_bytes_; 102 int64 remaining_bytes_;
72 103
73 // The initial file metadata is fetched on a background thread. 104 base::WeakPtrFactory<URLRequestFileJob> weak_ptr_factory_;
74 // AsyncResolver runs that task.
75 class AsyncResolver;
76 friend class AsyncResolver;
77 scoped_refptr<AsyncResolver> async_resolver_;
78 105
79 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob); 106 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob);
80 }; 107 };
81 108
82 } // namespace net 109 } // namespace net
83 110
84 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ 111 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_
OLDNEW
« 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