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

Side by Side Diff: content/browser/download/download_file_manager.h

Issue 7793003: Revert 98656 - Make a new integer field in sql::MetaTable (a per-profile db) containing a counter... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // The DownloadFileManager owns a set of DownloadFile objects, each of which 5 // The DownloadFileManager owns a set of DownloadFile objects, each of which
6 // represent one in progress download and performs the disk IO for that 6 // represent one in progress download and performs the disk IO for that
7 // download. The DownloadFileManager itself is a singleton object owned by the 7 // download. The DownloadFileManager itself is a singleton object owned by the
8 // ResourceDispatcherHost. 8 // ResourceDispatcherHost.
9 // 9 //
10 // The DownloadFileManager uses the file_thread for performing file write 10 // The DownloadFileManager uses the file_thread for performing file write
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 #include <map> 43 #include <map>
44 44
45 #include "base/atomic_sequence_num.h" 45 #include "base/atomic_sequence_num.h"
46 #include "base/basictypes.h" 46 #include "base/basictypes.h"
47 #include "base/gtest_prod_util.h" 47 #include "base/gtest_prod_util.h"
48 #include "base/hash_tables.h" 48 #include "base/hash_tables.h"
49 #include "base/memory/ref_counted.h" 49 #include "base/memory/ref_counted.h"
50 #include "base/timer.h" 50 #include "base/timer.h"
51 #include "content/browser/download/download_request_handle.h" 51 #include "content/browser/download/download_request_handle.h"
52 #include "content/browser/download/download_id.h"
53 #include "ui/gfx/native_widget_types.h" 52 #include "ui/gfx/native_widget_types.h"
54 53
55 struct DownloadBuffer; 54 struct DownloadBuffer;
56 struct DownloadCreateInfo; 55 struct DownloadCreateInfo;
57 struct DownloadSaveInfo; 56 struct DownloadSaveInfo;
58 class DownloadFile; 57 class DownloadFile;
59 class DownloadManager; 58 class DownloadManager;
60 class FilePath; 59 class FilePath;
61 class GURL; 60 class GURL;
62 class ResourceDispatcherHost; 61 class ResourceDispatcherHost;
63 62
64 namespace net { 63 namespace net {
65 class URLRequestContextGetter; 64 class URLRequestContextGetter;
66 } 65 }
67 66
68 // Manages all in progress downloads. 67 // Manages all in progress downloads.
69 class DownloadFileManager 68 class DownloadFileManager
70 : public base::RefCountedThreadSafe<DownloadFileManager> { 69 : public base::RefCountedThreadSafe<DownloadFileManager> {
71 public: 70 public:
72 explicit DownloadFileManager(ResourceDispatcherHost* rdh); 71 explicit DownloadFileManager(ResourceDispatcherHost* rdh);
73 72
74 // Called on shutdown on the UI thread. 73 // Called on shutdown on the UI thread.
75 void Shutdown(); 74 void Shutdown();
76 75
76 // Called on the IO or UI threads.
77 int GetNextId();
78
77 // Called on UI thread to make DownloadFileManager start the download. 79 // Called on UI thread to make DownloadFileManager start the download.
78 void StartDownload(DownloadCreateInfo* info); 80 void StartDownload(DownloadCreateInfo* info);
79 81
80 // Handlers for notifications sent from the IO thread and run on the 82 // Handlers for notifications sent from the IO thread and run on the
81 // FILE thread. 83 // FILE thread.
82 void UpdateDownload(DownloadId id, DownloadBuffer* buffer); 84 void UpdateDownload(int id, DownloadBuffer* buffer);
83 // |os_error| is 0 for normal completions, and non-0 for errors. 85 // |os_error| is 0 for normal completions, and non-0 for errors.
84 // |security_info| contains SSL information (cert_id, cert_status, 86 // |security_info| contains SSL information (cert_id, cert_status,
85 // security_bits, ssl_connection_status), which can be used to 87 // security_bits, ssl_connection_status), which can be used to
86 // fine-tune the error message. It is empty if the transaction 88 // fine-tune the error message. It is empty if the transaction
87 // was not performed securely. 89 // was not performed securely.
88 void OnResponseCompleted(DownloadId id, 90 void OnResponseCompleted(int id,
89 DownloadBuffer* buffer, 91 DownloadBuffer* buffer,
90 int os_error, 92 int os_error,
91 const std::string& security_info); 93 const std::string& security_info);
92 94
93 // Handlers for notifications sent from the UI thread and run on the 95 // Handlers for notifications sent from the UI thread and run on the
94 // FILE thread. These are both terminal actions with respect to the 96 // FILE thread. These are both terminal actions with respect to the
95 // download file, as far as the DownloadFileManager is concerned -- if 97 // download file, as far as the DownloadFileManager is concerned -- if
96 // anything happens to the download file after they are called, it will 98 // anything happens to the download file after they are called, it will
97 // be ignored. 99 // be ignored.
98 void CancelDownload(DownloadId id); 100 void CancelDownload(int id);
99 void CompleteDownload(DownloadId id); 101 void CompleteDownload(int id);
100 102
101 // Called on FILE thread by DownloadManager at the beginning of its shutdown. 103 // Called on FILE thread by DownloadManager at the beginning of its shutdown.
102 void OnDownloadManagerShutdown(DownloadManager* manager); 104 void OnDownloadManagerShutdown(DownloadManager* manager);
103 105
104 // The DownloadManager in the UI thread has provided an intermediate 106 // The DownloadManager in the UI thread has provided an intermediate
105 // .crdownload name for the download specified by |id|. 107 // .crdownload name for the download specified by |id|.
106 void RenameInProgressDownloadFile(DownloadId id, const FilePath& full_path); 108 void RenameInProgressDownloadFile(int id, const FilePath& full_path);
107 109
108 // The DownloadManager in the UI thread has provided a final name for the 110 // The DownloadManager in the UI thread has provided a final name for the
109 // download specified by |id|. 111 // download specified by |id|.
110 // |overwrite_existing_file| prevents uniquification, and is used for SAFE 112 // |overwrite_existing_file| prevents uniquification, and is used for SAFE
111 // downloads, as the user may have decided to overwrite the file. 113 // downloads, as the user may have decided to overwrite the file.
112 // Sent from the UI thread and run on the FILE thread. 114 // Sent from the UI thread and run on the FILE thread.
113 void RenameCompletingDownloadFile(DownloadId id, 115 void RenameCompletingDownloadFile(int id,
114 const FilePath& full_path, 116 const FilePath& full_path,
115 bool overwrite_existing_file); 117 bool overwrite_existing_file);
116 118
117 // The number of downloads currently active on the DownloadFileManager. 119 // The number of downloads currently active on the DownloadFileManager.
118 // Primarily for testing. 120 // Primarily for testing.
119 int NumberOfActiveDownloads() const { 121 int NumberOfActiveDownloads() const {
120 return downloads_.size(); 122 return downloads_.size();
121 } 123 }
122 124
123 private: 125 private:
(...skipping 11 matching lines...) Expand all
135 // Clean up helper that runs on the download thread. 137 // Clean up helper that runs on the download thread.
136 void OnShutdown(); 138 void OnShutdown();
137 139
138 // Creates DownloadFile on FILE thread and continues starting the download 140 // Creates DownloadFile on FILE thread and continues starting the download
139 // process. 141 // process.
140 void CreateDownloadFile(DownloadCreateInfo* info, 142 void CreateDownloadFile(DownloadCreateInfo* info,
141 DownloadManager* download_manager, 143 DownloadManager* download_manager,
142 bool hash_needed); 144 bool hash_needed);
143 145
144 // Called only on the download thread. 146 // Called only on the download thread.
145 DownloadFile* GetDownloadFile(DownloadId id); 147 DownloadFile* GetDownloadFile(int id);
146 148
147 // Called only from RenameInProgressDownloadFile and 149 // Called only from RenameInProgressDownloadFile and
148 // RenameCompletingDownloadFile on the FILE thread. 150 // RenameCompletingDownloadFile on the FILE thread.
149 void CancelDownloadOnRename(DownloadId id); 151 void CancelDownloadOnRename(int id);
150 152
151 // Erases the download file with the given the download |id| and removes 153 // Erases the download file with the given the download |id| and removes
152 // it from the maps. 154 // it from the maps.
153 void EraseDownload(DownloadId id); 155 void EraseDownload(int id);
154 156
155 typedef base::hash_map<DownloadId, DownloadFile*> DownloadFileMap; 157 // Unique ID for each DownloadItem.
158 base::AtomicSequenceNumber next_id_;
159
160 typedef base::hash_map<int, DownloadFile*> DownloadFileMap;
156 161
157 // A map of all in progress downloads. It owns the download files. 162 // A map of all in progress downloads. It owns the download files.
158 DownloadFileMap downloads_; 163 DownloadFileMap downloads_;
159 164
160 // Schedule periodic updates of the download progress. This timer 165 // Schedule periodic updates of the download progress. This timer
161 // is controlled from the FILE thread, and posts updates to the UI thread. 166 // is controlled from the FILE thread, and posts updates to the UI thread.
162 base::RepeatingTimer<DownloadFileManager> update_timer_; 167 base::RepeatingTimer<DownloadFileManager> update_timer_;
163 168
164 ResourceDispatcherHost* resource_dispatcher_host_; 169 ResourceDispatcherHost* resource_dispatcher_host_;
165 170
166 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); 171 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager);
167 }; 172 };
168 173
169 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_ 174 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_io_data.cc ('k') | content/browser/download/download_file_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698