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

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

Issue 1549113002: Switch to standard integer types in content/browser/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 12 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
« no previous file with comments | « content/browser/download/save_item.cc ('k') | content/browser/download/save_package.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_
6 #define CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_
7 7
8 #include <stddef.h>
9 #include <stdint.h>
10
8 #include <deque> 11 #include <deque>
9 #include <map> 12 #include <map>
10 #include <set> 13 #include <set>
11 #include <string> 14 #include <string>
12 #include <vector> 15 #include <vector>
13 16
14 #include "base/basictypes.h"
15 #include "base/containers/hash_tables.h" 17 #include "base/containers/hash_tables.h"
16 #include "base/files/file_path.h" 18 #include "base/files/file_path.h"
17 #include "base/gtest_prod_util.h" 19 #include "base/gtest_prod_util.h"
20 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 21 #include "base/memory/ref_counted.h"
19 #include "base/memory/weak_ptr.h" 22 #include "base/memory/weak_ptr.h"
20 #include "base/time/time.h" 23 #include "base/time/time.h"
21 #include "content/browser/download/save_types.h" 24 #include "content/browser/download/save_types.h"
22 #include "content/common/content_export.h" 25 #include "content/common/content_export.h"
23 #include "content/public/browser/download_item.h" 26 #include "content/public/browser/download_item.h"
24 #include "content/public/browser/download_manager_delegate.h" 27 #include "content/public/browser/download_manager_delegate.h"
25 #include "content/public/browser/save_page_type.h" 28 #include "content/public/browser/save_page_type.h"
26 #include "content/public/browser/web_contents_observer.h" 29 #include "content/public/browser/web_contents_observer.h"
27 #include "content/public/common/referrer.h" 30 #include "content/public/common/referrer.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // written to disk. 103 // written to disk.
101 bool Init(const SavePackageDownloadCreatedCallback& cb); 104 bool Init(const SavePackageDownloadCreatedCallback& cb);
102 105
103 // Cancel all in progress request, might be called by user or internal error. 106 // Cancel all in progress request, might be called by user or internal error.
104 void Cancel(bool user_action); 107 void Cancel(bool user_action);
105 108
106 void Finish(); 109 void Finish();
107 110
108 // Notifications sent from the file thread to the UI thread. 111 // Notifications sent from the file thread to the UI thread.
109 void StartSave(const SaveFileCreateInfo* info); 112 void StartSave(const SaveFileCreateInfo* info);
110 bool UpdateSaveProgress(int32 save_item_id, int64 size, bool write_success); 113 bool UpdateSaveProgress(int32_t save_item_id,
111 void SaveFinished(int32 save_item_id, int64 size, bool is_success); 114 int64_t size,
115 bool write_success);
116 void SaveFinished(int32_t save_item_id, int64_t size, bool is_success);
112 void SaveCanceled(SaveItem* save_item); 117 void SaveCanceled(SaveItem* save_item);
113 118
114 // Rough percent complete, -1 means we don't know (since we didn't receive a 119 // Rough percent complete, -1 means we don't know (since we didn't receive a
115 // total size). 120 // total size).
116 int PercentComplete(); 121 int PercentComplete();
117 122
118 bool canceled() const { return user_canceled_ || disk_error_occurred_; } 123 bool canceled() const { return user_canceled_ || disk_error_occurred_; }
119 bool finished() const { return finished_; } 124 bool finished() const { return finished_; }
120 SavePageType save_type() const { return save_type_; } 125 SavePageType save_type() const { return save_type_; }
121 int id() const { return unique_id_; } 126 int id() const { return unique_id_; }
122 127
123 void GetSaveInfo(); 128 void GetSaveInfo();
124 129
125 private: 130 private:
126 friend class base::RefCountedThreadSafe<SavePackage>; 131 friend class base::RefCountedThreadSafe<SavePackage>;
127 132
128 void InitWithDownloadItem( 133 void InitWithDownloadItem(
129 const SavePackageDownloadCreatedCallback& download_created_callback, 134 const SavePackageDownloadCreatedCallback& download_created_callback,
130 DownloadItemImpl* item); 135 DownloadItemImpl* item);
131 136
132 // Callback for WebContents::GenerateMHTML(). 137 // Callback for WebContents::GenerateMHTML().
133 void OnMHTMLGenerated(int64 size); 138 void OnMHTMLGenerated(int64_t size);
134 139
135 // For testing only. 140 // For testing only.
136 SavePackage(WebContents* web_contents, 141 SavePackage(WebContents* web_contents,
137 const base::FilePath& file_full_path, 142 const base::FilePath& file_full_path,
138 const base::FilePath& directory_full_path); 143 const base::FilePath& directory_full_path);
139 144
140 ~SavePackage() override; 145 ~SavePackage() override;
141 146
142 // Notes from Init() above applies here as well. 147 // Notes from Init() above applies here as well.
143 void InternalInit(); 148 void InternalInit();
(...skipping 13 matching lines...) Expand all
157 // Update the download history of this item upon completion. 162 // Update the download history of this item upon completion.
158 void FinalizeDownloadEntry(); 163 void FinalizeDownloadEntry();
159 164
160 // Detach from DownloadManager. 165 // Detach from DownloadManager.
161 void StopObservation(); 166 void StopObservation();
162 167
163 // Return max length of a path for a specific base directory. 168 // Return max length of a path for a specific base directory.
164 // This is needed on POSIX, which restrict the length of file names in 169 // This is needed on POSIX, which restrict the length of file names in
165 // addition to the restriction on the length of path names. 170 // addition to the restriction on the length of path names.
166 // |base_dir| is assumed to be a directory name with no trailing slash. 171 // |base_dir| is assumed to be a directory name with no trailing slash.
167 static uint32 GetMaxPathLengthForDirectory(const base::FilePath& base_dir); 172 static uint32_t GetMaxPathLengthForDirectory(const base::FilePath& base_dir);
168 173
169 static bool GetSafePureFileName( 174 static bool GetSafePureFileName(
170 const base::FilePath& dir_path, 175 const base::FilePath& dir_path,
171 const base::FilePath::StringType& file_name_ext, 176 const base::FilePath::StringType& file_name_ext,
172 uint32 max_file_path_len, 177 uint32_t max_file_path_len,
173 base::FilePath::StringType* pure_file_name); 178 base::FilePath::StringType* pure_file_name);
174 179
175 // Create a file name based on the response from the server. 180 // Create a file name based on the response from the server.
176 bool GenerateFileName(const std::string& disposition, 181 bool GenerateFileName(const std::string& disposition,
177 const GURL& url, 182 const GURL& url,
178 bool need_html_ext, 183 bool need_html_ext,
179 base::FilePath::StringType* generated_name); 184 base::FilePath::StringType* generated_name);
180 185
181 // Main routine that initiates asking all frames for their savable resources, 186 // Main routine that initiates asking all frames for their savable resources,
182 // using GetSavableResourceLinksForFrame to send IPC to individual frames. 187 // using GetSavableResourceLinksForFrame to send IPC to individual frames.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 void GetSerializedHtmlWithLocalLinksForFrame(FrameTreeNode* target_tree_node); 249 void GetSerializedHtmlWithLocalLinksForFrame(FrameTreeNode* target_tree_node);
245 250
246 // Routes html data (sent by renderer process in response to 251 // Routes html data (sent by renderer process in response to
247 // GetSerializedHtmlWithLocalLinksForFrame above) to the associated local file 252 // GetSerializedHtmlWithLocalLinksForFrame above) to the associated local file
248 // (and also keeps track of when all frames have been completed). 253 // (and also keeps track of when all frames have been completed).
249 void OnSerializedHtmlWithLocalLinksResponse(RenderFrameHostImpl* sender, 254 void OnSerializedHtmlWithLocalLinksResponse(RenderFrameHostImpl* sender,
250 const std::string& data, 255 const std::string& data,
251 bool end_of_data); 256 bool end_of_data);
252 257
253 // Look up SaveItem by save item id from in progress map. 258 // Look up SaveItem by save item id from in progress map.
254 SaveItem* LookupSaveItemInProcess(int32 save_item_id); 259 SaveItem* LookupSaveItemInProcess(int32_t save_item_id);
255 260
256 // Remove SaveItem from in progress map and put it to saved map. 261 // Remove SaveItem from in progress map and put it to saved map.
257 void PutInProgressItemToSavedMap(SaveItem* save_item); 262 void PutInProgressItemToSavedMap(SaveItem* save_item);
258 263
259 // Retrieves the URL to be saved from the WebContents. 264 // Retrieves the URL to be saved from the WebContents.
260 GURL GetUrlToBeSaved(); 265 GURL GetUrlToBeSaved();
261 266
262 void CreateDirectoryOnFileThread(const base::FilePath& website_save_dir, 267 void CreateDirectoryOnFileThread(const base::FilePath& website_save_dir,
263 const base::FilePath& download_save_dir, 268 const base::FilePath& download_save_dir,
264 bool skip_dir_check, 269 bool skip_dir_check,
(...skipping 23 matching lines...) Expand all
288 int completed_count() const { 293 int completed_count() const {
289 return static_cast<int>(saved_success_items_.size() + 294 return static_cast<int>(saved_success_items_.size() +
290 saved_failed_items_.size()); 295 saved_failed_items_.size());
291 } 296 }
292 297
293 // The current speed in files per second. This is used to update the 298 // The current speed in files per second. This is used to update the
294 // DownloadItem associated to this SavePackage. The files per second is 299 // DownloadItem associated to this SavePackage. The files per second is
295 // presented by the DownloadItem to the UI as bytes per second, which is 300 // presented by the DownloadItem to the UI as bytes per second, which is
296 // not correct but matches the way the total and received number of files is 301 // not correct but matches the way the total and received number of files is
297 // presented as the total and received bytes. 302 // presented as the total and received bytes.
298 int64 CurrentSpeed() const; 303 int64_t CurrentSpeed() const;
299 304
300 // Helper function for preparing suggested name for the SaveAs Dialog. The 305 // Helper function for preparing suggested name for the SaveAs Dialog. The
301 // suggested name is determined by the web document's title. 306 // suggested name is determined by the web document's title.
302 base::FilePath GetSuggestedNameForSaveAs( 307 base::FilePath GetSuggestedNameForSaveAs(
303 bool can_save_as_complete, 308 bool can_save_as_complete,
304 const std::string& contents_mime_type, 309 const std::string& contents_mime_type,
305 const std::string& accept_langs); 310 const std::string& accept_langs);
306 311
307 // Ensures that the file name has a proper extension for HTML by adding ".htm" 312 // Ensures that the file name has a proper extension for HTML by adding ".htm"
308 // if necessary. 313 // if necessary.
(...skipping 29 matching lines...) Expand all
338 // (i.e. to prevent information disclosure to oop frames). 343 // (i.e. to prevent information disclosure to oop frames).
339 // Note that |frame_tree_node_id_to_contained_save_items_| does NOT own 344 // Note that |frame_tree_node_id_to_contained_save_items_| does NOT own
340 // SaveItems - they remain owned by waiting_item_queue_, in_progress_items_, 345 // SaveItems - they remain owned by waiting_item_queue_, in_progress_items_,
341 // etc. 346 // etc.
342 base::hash_map<int, std::vector<SaveItem*>> 347 base::hash_map<int, std::vector<SaveItem*>>
343 frame_tree_node_id_to_contained_save_items_; 348 frame_tree_node_id_to_contained_save_items_;
344 349
345 // Number of frames that we still need to get a response from. 350 // Number of frames that we still need to get a response from.
346 int number_of_frames_pending_response_; 351 int number_of_frames_pending_response_;
347 352
348 typedef base::hash_map<int32, SaveItem*> SavedItemMap; 353 typedef base::hash_map<int32_t, SaveItem*> SavedItemMap;
349 // saved_success_items_ is map of all saving job which are successfully saved. 354 // saved_success_items_ is map of all saving job which are successfully saved.
350 SavedItemMap saved_success_items_; 355 SavedItemMap saved_success_items_;
351 356
352 // Non-owning pointer for handling file writing on the file thread. 357 // Non-owning pointer for handling file writing on the file thread.
353 SaveFileManager* file_manager_; 358 SaveFileManager* file_manager_;
354 359
355 // DownloadManager owns the DownloadItem and handles history and UI. 360 // DownloadManager owns the DownloadItem and handles history and UI.
356 DownloadManagerImpl* download_manager_; 361 DownloadManagerImpl* download_manager_;
357 DownloadItemImpl* download_; 362 DownloadItemImpl* download_;
358 363
(...skipping 26 matching lines...) Expand all
385 // Number of all need to be saved resources. 390 // Number of all need to be saved resources.
386 size_t all_save_items_count_; 391 size_t all_save_items_count_;
387 392
388 using FileNameSet = 393 using FileNameSet =
389 std::set<base::FilePath::StringType, 394 std::set<base::FilePath::StringType,
390 bool (*)(base::FilePath::StringPieceType, 395 bool (*)(base::FilePath::StringPieceType,
391 base::FilePath::StringPieceType)>; 396 base::FilePath::StringPieceType)>;
392 // This set is used to eliminate duplicated file names in saving directory. 397 // This set is used to eliminate duplicated file names in saving directory.
393 FileNameSet file_name_set_; 398 FileNameSet file_name_set_;
394 399
395 typedef base::hash_map<base::FilePath::StringType, uint32> FileNameCountMap; 400 typedef base::hash_map<base::FilePath::StringType, uint32_t> FileNameCountMap;
396 // This map is used to track serial number for specified filename. 401 // This map is used to track serial number for specified filename.
397 FileNameCountMap file_name_count_map_; 402 FileNameCountMap file_name_count_map_;
398 403
399 // Indicates current waiting state when SavePackage try to get something 404 // Indicates current waiting state when SavePackage try to get something
400 // from outside. 405 // from outside.
401 WaitState wait_state_; 406 WaitState wait_state_;
402 407
403 // Unique ID for this SavePackage. 408 // Unique ID for this SavePackage.
404 const int unique_id_; 409 const int unique_id_;
405 410
406 // Variables to record errors that happened so we can record them via 411 // Variables to record errors that happened so we can record them via
407 // UMA statistics. 412 // UMA statistics.
408 bool wrote_to_completed_file_; 413 bool wrote_to_completed_file_;
409 bool wrote_to_failed_file_; 414 bool wrote_to_failed_file_;
410 415
411 friend class SavePackageTest; 416 friend class SavePackageTest;
412 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); 417 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames);
413 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); 418 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename);
414 419
415 DISALLOW_COPY_AND_ASSIGN(SavePackage); 420 DISALLOW_COPY_AND_ASSIGN(SavePackage);
416 }; 421 };
417 422
418 } // namespace content 423 } // namespace content
419 424
420 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ 425 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_
OLDNEW
« no previous file with comments | « content/browser/download/save_item.cc ('k') | content/browser/download/save_package.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698