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

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: Created 8 years, 1 month 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/net_export.h" 13 #include "net/base/net_export.h"
13 #include "net/http/http_byte_range.h" 14 #include "net/http/http_byte_range.h"
14 #include "net/url_request/url_request.h" 15 #include "net/url_request/url_request.h"
15 #include "net/url_request/url_request_job.h" 16 #include "net/url_request/url_request_job.h"
16 17
17 namespace base{ 18 namespace base{
18 struct PlatformFileInfo; 19 struct PlatformFileInfo;
19 } 20 }
20 namespace file_util { 21 namespace file_util {
21 struct FileInfo; 22 struct FileInfo;
(...skipping 25 matching lines...) Expand all
47 virtual void SetExtraRequestHeaders( 48 virtual void SetExtraRequestHeaders(
48 const HttpRequestHeaders& headers) OVERRIDE; 49 const HttpRequestHeaders& headers) OVERRIDE;
49 50
50 protected: 51 protected:
51 virtual ~URLRequestFileJob(); 52 virtual ~URLRequestFileJob();
52 53
53 // The OS-specific full path name of the file 54 // The OS-specific full path name of the file
54 FilePath file_path_; 55 FilePath file_path_;
55 56
56 private: 57 private:
58 // Meta information about the file. It's used as a member in the
59 // URLRequestFileJob and also passed between threads because disk access is
60 // necessary to obtain it.
61 struct FileMetaInfo {
62 FileMetaInfo();
63
64 // Size of the file.
65 int64 file_size;
66 // Mime type associated with the file.
67 std::string mime_type;
68 // Result returned from GetMimeTypeFromFile(), i.e. flag showing whether
69 // obtaining of the mime type was successful.
70 bool mime_type_result;
71 // Flag showing whether the file exists.
72 bool file_exists;
73 // Flag showing whether the file name actually refers to a directory.
74 bool is_directory;
75 };
76
77 // Fetches file info on a background thread.
78 static void FetchMetaInfo(const FilePath& file_path,
79 FileMetaInfo* meta_info);
80
57 // Callback after fetching file info on a background thread. 81 // Callback after fetching file info on a background thread.
58 void DidResolve(bool exists, const base::PlatformFileInfo& file_info); 82 void DidFetchMetaInfo(const FileMetaInfo* meta_info);
83
84 // Callback after opening file on a background thread.
85 void DidOpen(int result);
86
87 // Callback after seeking to the beginning of |byte_range_| in the file
88 // on a background thread.
89 void DidSeek(int64 result);
59 90
60 // Callback after data is asynchronously read from the file. 91 // Callback after data is asynchronously read from the file.
61 void DidRead(int result); 92 void DidRead(int result);
62 93
63 scoped_ptr<FileStream> stream_; 94 scoped_ptr<FileStream> stream_;
64 bool is_directory_; 95 FileMetaInfo meta_info_;
65 96
66 HttpByteRange byte_range_; 97 HttpByteRange byte_range_;
67 int64 remaining_bytes_; 98 int64 remaining_bytes_;
68 99
69 // The initial file metadata is fetched on a background thread. 100 base::WeakPtrFactory<URLRequestFileJob> weak_ptr_factory_;
70 // AsyncResolver runs that task.
71 class AsyncResolver;
72 friend class AsyncResolver;
73 scoped_refptr<AsyncResolver> async_resolver_;
74 101
75 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob); 102 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob);
76 }; 103 };
77 104
78 } // namespace net 105 } // namespace net
79 106
80 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ 107 #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