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

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

Issue 2758453003: Recording download mime types for normal profile (Closed)
Patch Set: comments Created 3 years, 9 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 | « no previous file | content/browser/download/download_item_impl_unittest.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 // File method ordering: Methods in this file are in the same order as 5 // File method ordering: Methods in this file are in the same order as
6 // in download_item_impl.h, with the following exception: The public 6 // in download_item_impl.h, with the following exception: The public
7 // interface Start is placed in chronological order with the other 7 // interface Start is placed in chronological order with the other
8 // (private) routines that together define a DownloadItem's state 8 // (private) routines that together define a DownloadItem's state
9 // transitions as the download progresses. See "Download progression 9 // transitions as the download progresses. See "Download progression
10 // cascade" later in this file. 10 // cascade" later in this file.
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 OnAllDataSaved(total_bytes, std::move(secure_hash)); 1158 OnAllDataSaved(total_bytes, std::move(secure_hash));
1159 MaybeCompleteDownload(); 1159 MaybeCompleteDownload();
1160 } 1160 }
1161 1161
1162 // **** Download progression cascade 1162 // **** Download progression cascade
1163 1163
1164 void DownloadItemImpl::Init(bool active, 1164 void DownloadItemImpl::Init(bool active,
1165 DownloadType download_type) { 1165 DownloadType download_type) {
1166 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1166 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1167 1167
1168 if (active)
1169 RecordDownloadCount(START_COUNT);
1170
1171 std::string file_name; 1168 std::string file_name;
1172 if (download_type == SRC_HISTORY_IMPORT) { 1169 if (download_type == SRC_HISTORY_IMPORT) {
1173 // target_path_ works for History and Save As versions. 1170 // target_path_ works for History and Save As versions.
1174 file_name = target_path_.AsUTF8Unsafe(); 1171 file_name = target_path_.AsUTF8Unsafe();
1175 } else { 1172 } else {
1176 // See if it's set programmatically. 1173 // See if it's set programmatically.
1177 file_name = forced_file_path_.AsUTF8Unsafe(); 1174 file_name = forced_file_path_.AsUTF8Unsafe();
1178 // Possibly has a 'download' attribute for the anchor. 1175 // Possibly has a 'download' attribute for the anchor.
1179 if (file_name.empty()) 1176 if (file_name.empty())
1180 file_name = suggested_filename_; 1177 file_name = suggested_filename_;
(...skipping 16 matching lines...) Expand all
1197 } 1194 }
1198 1195
1199 // We're starting the download. 1196 // We're starting the download.
1200 void DownloadItemImpl::Start( 1197 void DownloadItemImpl::Start(
1201 std::unique_ptr<DownloadFile> file, 1198 std::unique_ptr<DownloadFile> file,
1202 std::unique_ptr<DownloadRequestHandleInterface> req_handle, 1199 std::unique_ptr<DownloadRequestHandleInterface> req_handle,
1203 const DownloadCreateInfo& new_create_info) { 1200 const DownloadCreateInfo& new_create_info) {
1204 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1201 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1205 DCHECK(!download_file_.get()); 1202 DCHECK(!download_file_.get());
1206 DVLOG(20) << __func__ << "() this=" << DebugString(true); 1203 DVLOG(20) << __func__ << "() this=" << DebugString(true);
1204 RecordDownloadCount(START_COUNT);
1207 1205
1208 download_file_ = std::move(file); 1206 download_file_ = std::move(file);
1209 job_ = DownloadJobFactory::CreateJob(this, std::move(req_handle), 1207 job_ = DownloadJobFactory::CreateJob(this, std::move(req_handle),
1210 new_create_info); 1208 new_create_info);
1211 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE; 1209 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE;
1212 1210
1213 if (state_ == CANCELLED_INTERNAL) { 1211 if (state_ == CANCELLED_INTERNAL) {
1214 // The download was in the process of resuming when it was cancelled. Don't 1212 // The download was in the process of resuming when it was cancelled. Don't
1215 // proceed. 1213 // proceed.
1216 ReleaseDownloadFile(true); 1214 ReleaseDownloadFile(true);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 1256
1259 // Otherwise, this was a resumption attempt which ended with an 1257 // Otherwise, this was a resumption attempt which ended with an
1260 // interruption. Continue with current target path. 1258 // interruption. Continue with current target path.
1261 TransitionTo(TARGET_RESOLVED_INTERNAL); 1259 TransitionTo(TARGET_RESOLVED_INTERNAL);
1262 InterruptWithPartialState( 1260 InterruptWithPartialState(
1263 offset, std::move(hash_state), new_create_info.result); 1261 offset, std::move(hash_state), new_create_info.result);
1264 UpdateObservers(); 1262 UpdateObservers();
1265 return; 1263 return;
1266 } 1264 }
1267 1265
1266 if (state_ == INITIAL_INTERNAL) {
1267 RecordDownloadCount(NEW_DOWNLOAD_COUNT);
1268 RecordDownloadMimeType(mime_type_);
1269 if (!GetBrowserContext()->IsOffTheRecord()) {
1270 RecordDownloadCount(NEW_DOWNLOAD_COUNT_NORMAL_PROFILE);
1271 RecordDownloadMimeTypeForNormalProfile(mime_type_);
1272 }
1273 }
1274
1268 // Successful download start. 1275 // Successful download start.
1269 DCHECK(download_file_); 1276 DCHECK(download_file_);
1270 DCHECK(job_); 1277 DCHECK(job_);
1271 1278
1272 if (state_ == RESUMING_INTERNAL) 1279 if (state_ == RESUMING_INTERNAL)
1273 UpdateValidatorsOnResumption(new_create_info); 1280 UpdateValidatorsOnResumption(new_create_info);
1274 1281
1275 if (state_ == INITIAL_INTERNAL && job_->UsesParallelRequests()) 1282 if (state_ == INITIAL_INTERNAL && job_->UsesParallelRequests())
1276 RecordDownloadCount(USES_PARALLEL_REQUESTS); 1283 RecordDownloadCount(USES_PARALLEL_REQUESTS);
1277 1284
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 1563
1557 void DownloadItemImpl::Completed() { 1564 void DownloadItemImpl::Completed() {
1558 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1565 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1559 1566
1560 DVLOG(20) << __func__ << "() " << DebugString(false); 1567 DVLOG(20) << __func__ << "() " << DebugString(false);
1561 1568
1562 DCHECK(all_data_saved_); 1569 DCHECK(all_data_saved_);
1563 end_time_ = base::Time::Now(); 1570 end_time_ = base::Time::Now();
1564 TransitionTo(COMPLETE_INTERNAL); 1571 TransitionTo(COMPLETE_INTERNAL);
1565 RecordDownloadCompleted(start_tick_, received_bytes_); 1572 RecordDownloadCompleted(start_tick_, received_bytes_);
1573 if (!GetBrowserContext()->IsOffTheRecord()) {
1574 RecordDownloadCount(COMPLETED_COUNT_NORMAL_PROFILE);
1575 }
1566 1576
1567 if (auto_opened_) { 1577 if (auto_opened_) {
1568 // If it was already handled by the delegate, do nothing. 1578 // If it was already handled by the delegate, do nothing.
1569 } else if (GetOpenWhenComplete() || 1579 } else if (GetOpenWhenComplete() ||
1570 ShouldOpenFileBasedOnExtension() || 1580 ShouldOpenFileBasedOnExtension() ||
1571 IsTemporary()) { 1581 IsTemporary()) {
1572 // If the download is temporary, like in drag-and-drop, do not open it but 1582 // If the download is temporary, like in drag-and-drop, do not open it but
1573 // we still need to set it auto-opened so that it can be removed from the 1583 // we still need to set it auto-opened so that it can be removed from the
1574 // download shelf. 1584 // download shelf.
1575 if (!IsTemporary()) 1585 if (!IsTemporary())
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
2175 case RESUME_MODE_USER_CONTINUE: 2185 case RESUME_MODE_USER_CONTINUE:
2176 return "USER_CONTINUE"; 2186 return "USER_CONTINUE";
2177 case RESUME_MODE_USER_RESTART: 2187 case RESUME_MODE_USER_RESTART:
2178 return "USER_RESTART"; 2188 return "USER_RESTART";
2179 } 2189 }
2180 NOTREACHED() << "Unknown resume mode " << mode; 2190 NOTREACHED() << "Unknown resume mode " << mode;
2181 return "unknown"; 2191 return "unknown";
2182 } 2192 }
2183 2193
2184 } // namespace content 2194 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/download_item_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698