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

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

Issue 1492283004: ABANDONED CL: Introducing a compile-time-safe SavePackageId type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@type-safe-id-base
Patch Set: Created 5 years 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_package.h ('k') | content/browser/download/save_types.h » ('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 #include "content/browser/download/save_package.h" 5 #include "content/browser/download/save_package.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "net/base/io_buffer.h" 48 #include "net/base/io_buffer.h"
49 #include "net/base/mime_util.h" 49 #include "net/base/mime_util.h"
50 #include "net/url_request/url_request_context.h" 50 #include "net/url_request/url_request_context.h"
51 #include "url/url_constants.h" 51 #include "url/url_constants.h"
52 52
53 using base::Time; 53 using base::Time;
54 54
55 namespace content { 55 namespace content {
56 namespace { 56 namespace {
57 57
58 // A counter for uniquely identifying each save package. 58 // Generates unique ids for SavePackage::unique_id_ field.
59 int g_save_package_id = 0; 59 SavePackageId GetNextSavePackageId() {
60 static int g_save_package_id = 0;
61 return SavePackageId::FromUnsafeValue(g_save_package_id++);
62 }
60 63
61 // Default name which will be used when we can not get proper name from 64 // Default name which will be used when we can not get proper name from
62 // resource URL. 65 // resource URL.
63 const char kDefaultSaveName[] = "saved_resource"; 66 const char kDefaultSaveName[] = "saved_resource";
64 67
65 // Maximum number of file ordinal number. I think it's big enough for resolving 68 // Maximum number of file ordinal number. I think it's big enough for resolving
66 // name-conflict files which has same base file name. 69 // name-conflict files which has same base file name.
67 const int32 kMaxFileOrdinalNumber = 9999; 70 const int32 kMaxFileOrdinalNumber = 9999;
68 71
69 // Maximum length for file path. Since Windows have MAX_PATH limitation for 72 // Maximum length for file path. Since Windows have MAX_PATH limitation for
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 title_(web_contents->GetTitle()), 155 title_(web_contents->GetTitle()),
153 start_tick_(base::TimeTicks::Now()), 156 start_tick_(base::TimeTicks::Now()),
154 finished_(false), 157 finished_(false),
155 mhtml_finishing_(false), 158 mhtml_finishing_(false),
156 user_canceled_(false), 159 user_canceled_(false),
157 disk_error_occurred_(false), 160 disk_error_occurred_(false),
158 save_type_(save_type), 161 save_type_(save_type),
159 all_save_items_count_(0), 162 all_save_items_count_(0),
160 file_name_set_(&base::FilePath::CompareLessIgnoreCase), 163 file_name_set_(&base::FilePath::CompareLessIgnoreCase),
161 wait_state_(INITIALIZE), 164 wait_state_(INITIALIZE),
162 unique_id_(g_save_package_id++), 165 unique_id_(GetNextSavePackageId()),
163 wrote_to_completed_file_(false), 166 wrote_to_completed_file_(false),
164 wrote_to_failed_file_(false) { 167 wrote_to_failed_file_(false) {
165 DCHECK(page_url_.is_valid()); 168 DCHECK(page_url_.is_valid());
166 DCHECK((save_type_ == SAVE_PAGE_TYPE_AS_ONLY_HTML) || 169 DCHECK((save_type_ == SAVE_PAGE_TYPE_AS_ONLY_HTML) ||
167 (save_type_ == SAVE_PAGE_TYPE_AS_MHTML) || 170 (save_type_ == SAVE_PAGE_TYPE_AS_MHTML) ||
168 (save_type_ == SAVE_PAGE_TYPE_AS_COMPLETE_HTML)) 171 (save_type_ == SAVE_PAGE_TYPE_AS_COMPLETE_HTML))
169 << save_type_; 172 << save_type_;
170 DCHECK(!saved_main_file_path_.empty() && 173 DCHECK(!saved_main_file_path_.empty() &&
171 saved_main_file_path_.value().length() <= kMaxFilePathLength); 174 saved_main_file_path_.value().length() <= kMaxFilePathLength);
172 DCHECK(!saved_main_directory_path_.empty() && 175 DCHECK(!saved_main_directory_path_.empty() &&
(...skipping 11 matching lines...) Expand all
184 title_(web_contents->GetTitle()), 187 title_(web_contents->GetTitle()),
185 start_tick_(base::TimeTicks::Now()), 188 start_tick_(base::TimeTicks::Now()),
186 finished_(false), 189 finished_(false),
187 mhtml_finishing_(false), 190 mhtml_finishing_(false),
188 user_canceled_(false), 191 user_canceled_(false),
189 disk_error_occurred_(false), 192 disk_error_occurred_(false),
190 save_type_(SAVE_PAGE_TYPE_UNKNOWN), 193 save_type_(SAVE_PAGE_TYPE_UNKNOWN),
191 all_save_items_count_(0), 194 all_save_items_count_(0),
192 file_name_set_(&base::FilePath::CompareLessIgnoreCase), 195 file_name_set_(&base::FilePath::CompareLessIgnoreCase),
193 wait_state_(INITIALIZE), 196 wait_state_(INITIALIZE),
194 unique_id_(g_save_package_id++), 197 unique_id_(GetNextSavePackageId()),
195 wrote_to_completed_file_(false), 198 wrote_to_completed_file_(false),
196 wrote_to_failed_file_(false) { 199 wrote_to_failed_file_(false) {
197 DCHECK(page_url_.is_valid()); 200 DCHECK(page_url_.is_valid());
198 InternalInit(); 201 InternalInit();
199 } 202 }
200 203
201 // This is for testing use. Set |finished_| as true because we don't want 204 // This is for testing use. Set |finished_| as true because we don't want
202 // method Cancel to be be called in destructor in test mode. 205 // method Cancel to be be called in destructor in test mode.
203 // We also don't call InternalInit(). 206 // We also don't call InternalInit().
204 SavePackage::SavePackage(WebContents* web_contents, 207 SavePackage::SavePackage(WebContents* web_contents,
205 const base::FilePath& file_full_path, 208 const base::FilePath& file_full_path,
206 const base::FilePath& directory_full_path) 209 const base::FilePath& directory_full_path)
207 : WebContentsObserver(web_contents), 210 : WebContentsObserver(web_contents),
208 number_of_frames_pending_response_(0), 211 number_of_frames_pending_response_(0),
209 file_manager_(NULL), 212 file_manager_(NULL),
210 download_manager_(NULL), 213 download_manager_(NULL),
211 download_(NULL), 214 download_(NULL),
212 saved_main_file_path_(file_full_path), 215 saved_main_file_path_(file_full_path),
213 saved_main_directory_path_(directory_full_path), 216 saved_main_directory_path_(directory_full_path),
214 start_tick_(base::TimeTicks::Now()), 217 start_tick_(base::TimeTicks::Now()),
215 finished_(true), 218 finished_(true),
216 mhtml_finishing_(false), 219 mhtml_finishing_(false),
217 user_canceled_(false), 220 user_canceled_(false),
218 disk_error_occurred_(false), 221 disk_error_occurred_(false),
219 save_type_(SAVE_PAGE_TYPE_UNKNOWN), 222 save_type_(SAVE_PAGE_TYPE_UNKNOWN),
220 all_save_items_count_(0), 223 all_save_items_count_(0),
221 file_name_set_(&base::FilePath::CompareLessIgnoreCase), 224 file_name_set_(&base::FilePath::CompareLessIgnoreCase),
222 wait_state_(INITIALIZE), 225 wait_state_(INITIALIZE),
223 unique_id_(g_save_package_id++), 226 unique_id_(GetNextSavePackageId()),
224 wrote_to_completed_file_(false), 227 wrote_to_completed_file_(false),
225 wrote_to_failed_file_(false) {} 228 wrote_to_failed_file_(false) {}
226 229
227 SavePackage::~SavePackage() { 230 SavePackage::~SavePackage() {
228 // Stop receiving saving job's updates 231 // Stop receiving saving job's updates
229 if (!finished_ && !canceled()) { 232 if (!finished_ && !canceled()) {
230 // Unexpected quit. 233 // Unexpected quit.
231 Cancel(true); 234 Cancel(true);
232 } 235 }
233 236
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 1563
1561 void SavePackage::FinalizeDownloadEntry() { 1564 void SavePackage::FinalizeDownloadEntry() {
1562 DCHECK(download_); 1565 DCHECK(download_);
1563 DCHECK(download_manager_); 1566 DCHECK(download_manager_);
1564 1567
1565 download_manager_->OnSavePackageSuccessfullyFinished(download_); 1568 download_manager_->OnSavePackageSuccessfullyFinished(download_);
1566 StopObservation(); 1569 StopObservation();
1567 } 1570 }
1568 1571
1569 } // namespace content 1572 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/save_package.h ('k') | content/browser/download/save_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698