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

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, 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 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 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/memory/weak_ptr.h"
13 #include "net/base/file_stream.h" 14 #include "net/base/file_stream.h"
14 #include "net/base/net_export.h" 15 #include "net/base/net_export.h"
15 #include "net/http/http_byte_range.h" 16 #include "net/http/http_byte_range.h"
16 #include "net/url_request/url_request.h" 17 #include "net/url_request/url_request.h"
17 #include "net/url_request/url_request_job.h" 18 #include "net/url_request/url_request_job.h"
18 19
19 namespace file_util { 20 namespace file_util {
20 struct FileInfo; 21 struct FileInfo;
21 } 22 }
22 23
(...skipping 23 matching lines...) Expand all
46 virtual void SetExtraRequestHeaders( 47 virtual void SetExtraRequestHeaders(
47 const HttpRequestHeaders& headers) OVERRIDE; 48 const HttpRequestHeaders& headers) OVERRIDE;
48 49
49 protected: 50 protected:
50 virtual ~URLRequestFileJob(); 51 virtual ~URLRequestFileJob();
51 52
52 // The OS-specific full path name of the file 53 // The OS-specific full path name of the file
53 FilePath file_path_; 54 FilePath file_path_;
54 55
55 private: 56 private:
57 struct FileMetaInfo {
58 int64 file_size_;
59 std::string mime_type_;
60 bool mime_type_result_;
61 bool file_exists_;
62 bool is_directory_;
wtc 2012/07/13 22:38:55 The style guide recommends that struct member name
63 };
64
56 // Tests to see if access to |path| is allowed. If g_allow_file_access_ is 65 // Tests to see if access to |path| is allowed. If g_allow_file_access_ is
57 // true, then this will return true. If the NetworkDelegate associated with 66 // true, then this will return true. If the NetworkDelegate associated with
58 // the |request| says it's OK, then this will also return true. 67 // the |request| says it's OK, then this will also return true.
59 static bool IsFileAccessAllowed(const URLRequest& request, 68 static bool IsFileAccessAllowed(const URLRequest& request,
60 const FilePath& path); 69 const FilePath& path);
61 70
71 // Function fetching file info on a WorkerPool thread.
wtc 2012/07/13 22:38:55 Nit: Function fetching => Fetches
72 static void FetchMetaInfo(const FilePath& file_path,
73 FileMetaInfo* meta_info);
74
62 // Callback after fetching file info on a background thread. 75 // Callback after fetching file info on a background thread.
63 void DidResolve(bool exists, const base::PlatformFileInfo& file_info); 76 void DidFetchMetaInfo(const FileMetaInfo* meta_info);
77
78 // Callback after opening file on a background thread.
79 void DidOpen(int result);
80
81 // Callback after seeking to necessary position in the file which is done
wtc 2012/07/13 22:38:55 Nit: change this comment to: // Callback after s
82 // on a background thread.
83 void DidSeek(int64 result);
64 84
65 // Callback after data is asynchronously read from the file. 85 // Callback after data is asynchronously read from the file.
66 void DidRead(int result); 86 void DidRead(int result);
67 87
68 FileStream stream_; 88 FileStream stream_;
69 bool is_directory_; 89 FileMetaInfo meta_info_;
70 90
71 HttpByteRange byte_range_; 91 HttpByteRange byte_range_;
72 int64 remaining_bytes_; 92 int64 remaining_bytes_;
73 93
74 // The initial file metadata is fetched on a background thread. 94 base::WeakPtrFactory<URLRequestFileJob> weak_ptr_factory_;
75 // AsyncResolver runs that task.
76 class AsyncResolver;
77 friend class AsyncResolver;
78 scoped_refptr<AsyncResolver> async_resolver_;
79 95
80 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob); 96 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob);
81 }; 97 };
82 98
83 } // namespace net 99 } // namespace net
84 100
85 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ 101 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698