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: content/browser/download/download_file_manager.h

Issue 7237034: sql::MetaTable.next_download_id, DownloadManager::GetNextId() (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: fix merge 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"
52 #include "ui/gfx/native_widget_types.h" 53 #include "ui/gfx/native_widget_types.h"
53 54
54 struct DownloadBuffer; 55 struct DownloadBuffer;
55 struct DownloadCreateInfo; 56 struct DownloadCreateInfo;
56 struct DownloadSaveInfo; 57 struct DownloadSaveInfo;
57 class DownloadFile; 58 class DownloadFile;
58 class DownloadManager; 59 class DownloadManager;
59 class FilePath; 60 class FilePath;
60 class GURL; 61 class GURL;
61 class ResourceDispatcherHost; 62 class ResourceDispatcherHost;
62 63
63 namespace net { 64 namespace net {
64 class URLRequestContextGetter; 65 class URLRequestContextGetter;
65 } 66 }
66 67
67 // Manages all in progress downloads. 68 // Manages all in progress downloads.
68 class DownloadFileManager 69 class DownloadFileManager
69 : public base::RefCountedThreadSafe<DownloadFileManager> { 70 : public base::RefCountedThreadSafe<DownloadFileManager> {
70 public: 71 public:
71 explicit DownloadFileManager(ResourceDispatcherHost* rdh); 72 explicit DownloadFileManager(ResourceDispatcherHost* rdh);
72 73
73 // Called on shutdown on the UI thread. 74 // Called on shutdown on the UI thread.
74 void Shutdown(); 75 void Shutdown();
75 76
76 // Called on the IO or UI threads.
77 int GetNextId();
78
79 // Called on UI thread to make DownloadFileManager start the download. 77 // Called on UI thread to make DownloadFileManager start the download.
80 void StartDownload(DownloadCreateInfo* info); 78 void StartDownload(DownloadCreateInfo* info);
81 79
82 // Handlers for notifications sent from the IO thread and run on the 80 // Handlers for notifications sent from the IO thread and run on the
83 // FILE thread. 81 // FILE thread.
84 void UpdateDownload(int id, DownloadBuffer* buffer); 82 void UpdateDownload(DownloadId id, DownloadBuffer* buffer);
85 // |os_error| is 0 for normal completions, and non-0 for errors. 83 // |os_error| is 0 for normal completions, and non-0 for errors.
86 // |security_info| contains SSL information (cert_id, cert_status, 84 // |security_info| contains SSL information (cert_id, cert_status,
87 // security_bits, ssl_connection_status), which can be used to 85 // security_bits, ssl_connection_status), which can be used to
88 // fine-tune the error message. It is empty if the transaction 86 // fine-tune the error message. It is empty if the transaction
89 // was not performed securely. 87 // was not performed securely.
90 void OnResponseCompleted(int id, 88 void OnResponseCompleted(DownloadId id,
91 DownloadBuffer* buffer, 89 DownloadBuffer* buffer,
92 int os_error, 90 int os_error,
93 const std::string& security_info); 91 const std::string& security_info);
94 92
95 // Handlers for notifications sent from the UI thread and run on the 93 // Handlers for notifications sent from the UI thread and run on the
96 // FILE thread. These are both terminal actions with respect to the 94 // FILE thread. These are both terminal actions with respect to the
97 // download file, as far as the DownloadFileManager is concerned -- if 95 // download file, as far as the DownloadFileManager is concerned -- if
98 // anything happens to the download file after they are called, it will 96 // anything happens to the download file after they are called, it will
99 // be ignored. 97 // be ignored.
100 void CancelDownload(int id); 98 void CancelDownload(DownloadId id);
101 void CompleteDownload(int id); 99 void CompleteDownload(DownloadId id);
102 100
103 // Called on FILE thread by DownloadManager at the beginning of its shutdown. 101 // Called on FILE thread by DownloadManager at the beginning of its shutdown.
104 void OnDownloadManagerShutdown(DownloadManager* manager); 102 void OnDownloadManagerShutdown(DownloadManager* manager);
105 103
106 // The DownloadManager in the UI thread has provided an intermediate 104 // The DownloadManager in the UI thread has provided an intermediate
107 // .crdownload name for the download specified by |id|. 105 // .crdownload name for the download specified by |id|.
108 void RenameInProgressDownloadFile(int id, const FilePath& full_path); 106 void RenameInProgressDownloadFile(DownloadId id, const FilePath& full_path);
109 107
110 // The DownloadManager in the UI thread has provided a final name for the 108 // The DownloadManager in the UI thread has provided a final name for the
111 // download specified by |id|. 109 // download specified by |id|.
112 // |overwrite_existing_file| prevents uniquification, and is used for SAFE 110 // |overwrite_existing_file| prevents uniquification, and is used for SAFE
113 // downloads, as the user may have decided to overwrite the file. 111 // downloads, as the user may have decided to overwrite the file.
114 // Sent from the UI thread and run on the FILE thread. 112 // Sent from the UI thread and run on the FILE thread.
115 void RenameCompletingDownloadFile(int id, 113 void RenameCompletingDownloadFile(DownloadId id,
116 const FilePath& full_path, 114 const FilePath& full_path,
117 bool overwrite_existing_file); 115 bool overwrite_existing_file);
118 116
119 // The number of downloads currently active on the DownloadFileManager. 117 // The number of downloads currently active on the DownloadFileManager.
120 // Primarily for testing. 118 // Primarily for testing.
121 int NumberOfActiveDownloads() const { 119 int NumberOfActiveDownloads() const {
122 return downloads_.size(); 120 return downloads_.size();
123 } 121 }
124 122
125 private: 123 private:
(...skipping 11 matching lines...) Expand all
137 // Clean up helper that runs on the download thread. 135 // Clean up helper that runs on the download thread.
138 void OnShutdown(); 136 void OnShutdown();
139 137
140 // Creates DownloadFile on FILE thread and continues starting the download 138 // Creates DownloadFile on FILE thread and continues starting the download
141 // process. 139 // process.
142 void CreateDownloadFile(DownloadCreateInfo* info, 140 void CreateDownloadFile(DownloadCreateInfo* info,
143 DownloadManager* download_manager, 141 DownloadManager* download_manager,
144 bool hash_needed); 142 bool hash_needed);
145 143
146 // Called only on the download thread. 144 // Called only on the download thread.
147 DownloadFile* GetDownloadFile(int id); 145 DownloadFile* GetDownloadFile(DownloadId id);
148 146
149 // Called only from RenameInProgressDownloadFile and 147 // Called only from RenameInProgressDownloadFile and
150 // RenameCompletingDownloadFile on the FILE thread. 148 // RenameCompletingDownloadFile on the FILE thread.
151 void CancelDownloadOnRename(int id); 149 void CancelDownloadOnRename(DownloadId id);
152 150
153 // Erases the download file with the given the download |id| and removes 151 // Erases the download file with the given the download |id| and removes
154 // it from the maps. 152 // it from the maps.
155 void EraseDownload(int id); 153 void EraseDownload(DownloadId id);
156 154
157 // Unique ID for each DownloadItem. 155 typedef base::hash_map<DownloadId, DownloadFile*> DownloadFileMap;
158 base::AtomicSequenceNumber next_id_;
159
160 typedef base::hash_map<int, DownloadFile*> DownloadFileMap;
161 156
162 // A map of all in progress downloads. It owns the download files. 157 // A map of all in progress downloads. It owns the download files.
163 DownloadFileMap downloads_; 158 DownloadFileMap downloads_;
164 159
165 // Schedule periodic updates of the download progress. This timer 160 // Schedule periodic updates of the download progress. This timer
166 // is controlled from the FILE thread, and posts updates to the UI thread. 161 // is controlled from the FILE thread, and posts updates to the UI thread.
167 base::RepeatingTimer<DownloadFileManager> update_timer_; 162 base::RepeatingTimer<DownloadFileManager> update_timer_;
168 163
169 ResourceDispatcherHost* resource_dispatcher_host_; 164 ResourceDispatcherHost* resource_dispatcher_host_;
170 165
171 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); 166 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager);
172 }; 167 };
173 168
174 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_ 169 #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