OLD | NEW |
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> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <deque> | 11 #include <deque> |
12 #include <map> | 12 #include <map> |
| 13 #include <memory> |
13 #include <set> | 14 #include <set> |
14 #include <string> | 15 #include <string> |
15 #include <unordered_map> | 16 #include <unordered_map> |
16 #include <vector> | 17 #include <vector> |
17 | 18 |
18 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
19 #include "base/gtest_prod_util.h" | 20 #include "base/gtest_prod_util.h" |
20 #include "base/macros.h" | 21 #include "base/macros.h" |
21 #include "base/memory/ref_counted.h" | 22 #include "base/memory/ref_counted.h" |
22 #include "base/memory/weak_ptr.h" | 23 #include "base/memory/weak_ptr.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 128 |
128 // Friends for testing. Needed for accessing the test-only constructor below. | 129 // Friends for testing. Needed for accessing the test-only constructor below. |
129 friend class SavePackageTest; | 130 friend class SavePackageTest; |
130 friend class WebContentsImpl; | 131 friend class WebContentsImpl; |
131 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); | 132 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestSuggestedSaveNames); |
132 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); | 133 FRIEND_TEST_ALL_PREFIXES(SavePackageTest, TestLongSafePureFilename); |
133 FRIEND_TEST_ALL_PREFIXES(SavePackageBrowserTest, ImplicitCancel); | 134 FRIEND_TEST_ALL_PREFIXES(SavePackageBrowserTest, ImplicitCancel); |
134 FRIEND_TEST_ALL_PREFIXES(SavePackageBrowserTest, ExplicitCancel); | 135 FRIEND_TEST_ALL_PREFIXES(SavePackageBrowserTest, ExplicitCancel); |
135 | 136 |
136 // Map from SaveItem::id() (aka save_item_id) into a SaveItem. | 137 // Map from SaveItem::id() (aka save_item_id) into a SaveItem. |
137 using SaveItemIdMap = | 138 using SaveItemIdMap = std:: |
138 std::unordered_map<SaveItemId, SaveItem*, SaveItemId::Hasher>; | 139 unordered_map<SaveItemId, std::unique_ptr<SaveItem>, SaveItemId::Hasher>; |
139 | |
140 using SaveItemQueue = std::deque<SaveItem*>; | |
141 | 140 |
142 using FileNameSet = std::set<base::FilePath::StringType, | 141 using FileNameSet = std::set<base::FilePath::StringType, |
143 bool (*)(base::FilePath::StringPieceType, | 142 bool (*)(base::FilePath::StringPieceType, |
144 base::FilePath::StringPieceType)>; | 143 base::FilePath::StringPieceType)>; |
145 | 144 |
146 using FileNameCountMap = | 145 using FileNameCountMap = |
147 std::unordered_map<base::FilePath::StringType, uint32_t>; | 146 std::unordered_map<base::FilePath::StringType, uint32_t>; |
148 | 147 |
149 // Used only for testing. Bypasses the file and directory name generation / | 148 // Used only for testing. Bypasses the file and directory name generation / |
150 // sanitization by providing well known paths better suited for tests. | 149 // sanitization by providing well known paths better suited for tests. |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 // if necessary. | 351 // if necessary. |
353 static base::FilePath EnsureMimeExtension(const base::FilePath& name, | 352 static base::FilePath EnsureMimeExtension(const base::FilePath& name, |
354 const std::string& contents_mime_type); | 353 const std::string& contents_mime_type); |
355 | 354 |
356 // Returns extension for supported MIME types (for example, for "text/plain" | 355 // Returns extension for supported MIME types (for example, for "text/plain" |
357 // it returns "txt"). | 356 // it returns "txt"). |
358 static const base::FilePath::CharType* ExtensionForMimeType( | 357 static const base::FilePath::CharType* ExtensionForMimeType( |
359 const std::string& contents_mime_type); | 358 const std::string& contents_mime_type); |
360 | 359 |
361 // A queue for items we are about to start saving. | 360 // A queue for items we are about to start saving. |
362 SaveItemQueue waiting_item_queue_; | 361 std::deque<std::unique_ptr<SaveItem>> waiting_item_queue_; |
363 | 362 |
364 // Map of all saving job in in-progress state. | 363 // Map of all saving job in in-progress state. |
365 SaveItemIdMap in_progress_items_; | 364 SaveItemIdMap in_progress_items_; |
366 | 365 |
367 // Map of all saving job which are failed. | 366 // Map of all saving job which are failed. |
368 SaveItemIdMap saved_failed_items_; | 367 SaveItemIdMap saved_failed_items_; |
369 | 368 |
370 // Used to de-dupe urls that are being gathered into |waiting_item_queue_| | 369 // Used to de-dupe urls that are being gathered into |waiting_item_queue_| |
371 // and also to find SaveItems to associate with a containing frame. | 370 // and also to find SaveItems to associate with a containing frame. |
372 // Note that |url_to_save_item_| does NOT own SaveItems - they | 371 // Note that |url_to_save_item_| does NOT own SaveItems - they |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 442 |
444 // Unique ID for this SavePackage. | 443 // Unique ID for this SavePackage. |
445 const SavePackageId unique_id_; | 444 const SavePackageId unique_id_; |
446 | 445 |
447 DISALLOW_COPY_AND_ASSIGN(SavePackage); | 446 DISALLOW_COPY_AND_ASSIGN(SavePackage); |
448 }; | 447 }; |
449 | 448 |
450 } // namespace content | 449 } // namespace content |
451 | 450 |
452 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ | 451 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_PACKAGE_H_ |
OLD | NEW |