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 #include "content/browser/download/mhtml_generation_manager.h" | 5 #include "content/browser/download/mhtml_generation_manager.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <queue> | 8 #include <queue> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
13 #include "base/guid.h" | 13 #include "base/guid.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" |
15 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
16 #include "base/scoped_observer.h" | 17 #include "base/scoped_observer.h" |
17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
20 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
21 #include "content/browser/bad_message.h" | 22 #include "content/browser/bad_message.h" |
22 #include "content/browser/frame_host/frame_tree_node.h" | 23 #include "content/browser/frame_host/frame_tree_node.h" |
23 #include "content/browser/frame_host/render_frame_host_impl.h" | 24 #include "content/browser/frame_host/render_frame_host_impl.h" |
24 #include "content/common/frame_messages.h" | 25 #include "content/common/frame_messages.h" |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 return file_size; | 385 return file_size; |
385 } | 386 } |
386 | 387 |
387 MHTMLGenerationManager* MHTMLGenerationManager::GetInstance() { | 388 MHTMLGenerationManager* MHTMLGenerationManager::GetInstance() { |
388 return base::Singleton<MHTMLGenerationManager>::get(); | 389 return base::Singleton<MHTMLGenerationManager>::get(); |
389 } | 390 } |
390 | 391 |
391 MHTMLGenerationManager::MHTMLGenerationManager() : next_job_id_(0) {} | 392 MHTMLGenerationManager::MHTMLGenerationManager() : next_job_id_(0) {} |
392 | 393 |
393 MHTMLGenerationManager::~MHTMLGenerationManager() { | 394 MHTMLGenerationManager::~MHTMLGenerationManager() { |
394 base::STLDeleteValues(&id_to_job_); | |
395 } | 395 } |
396 | 396 |
397 void MHTMLGenerationManager::SaveMHTML(WebContents* web_contents, | 397 void MHTMLGenerationManager::SaveMHTML(WebContents* web_contents, |
398 const MHTMLGenerationParams& params, | 398 const MHTMLGenerationParams& params, |
399 const GenerateMHTMLCallback& callback) { | 399 const GenerateMHTMLCallback& callback) { |
400 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 400 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
401 | 401 |
402 Job* job = NewJob(web_contents, params, callback); | 402 Job* job = NewJob(web_contents, params, callback); |
403 TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( | 403 TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( |
404 "page-serialization", "SavingMhtmlJob", job, "url", | 404 "page-serialization", "SavingMhtmlJob", job, "url", |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 | 506 |
507 Job* job = FindJob(job_id); | 507 Job* job = FindJob(job_id); |
508 TRACE_EVENT_NESTABLE_ASYNC_END2( | 508 TRACE_EVENT_NESTABLE_ASYNC_END2( |
509 "page-serialization", "SavingMhtmlJob", job, "job result", | 509 "page-serialization", "SavingMhtmlJob", job, "job result", |
510 job_status == JobStatus::SUCCESS ? "success" : "failure", "file size", | 510 job_status == JobStatus::SUCCESS ? "success" : "failure", "file size", |
511 file_size); | 511 file_size); |
512 UMA_HISTOGRAM_TIMES("PageSerialization.MhtmlGeneration.FullPageSavingTime", | 512 UMA_HISTOGRAM_TIMES("PageSerialization.MhtmlGeneration.FullPageSavingTime", |
513 base::TimeTicks::Now() - job->creation_time()); | 513 base::TimeTicks::Now() - job->creation_time()); |
514 job->callback().Run(job_status == JobStatus::SUCCESS ? file_size : -1); | 514 job->callback().Run(job_status == JobStatus::SUCCESS ? file_size : -1); |
515 id_to_job_.erase(job_id); | 515 id_to_job_.erase(job_id); |
516 delete job; | |
517 } | 516 } |
518 | 517 |
519 MHTMLGenerationManager::Job* MHTMLGenerationManager::NewJob( | 518 MHTMLGenerationManager::Job* MHTMLGenerationManager::NewJob( |
520 WebContents* web_contents, | 519 WebContents* web_contents, |
521 const MHTMLGenerationParams& params, | 520 const MHTMLGenerationParams& params, |
522 const GenerateMHTMLCallback& callback) { | 521 const GenerateMHTMLCallback& callback) { |
523 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 522 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
524 | 523 |
525 Job* job = new Job(++next_job_id_, web_contents, params, callback); | 524 Job* job = new Job(++next_job_id_, web_contents, params, callback); |
526 id_to_job_[job->id()] = job; | 525 id_to_job_[job->id()] = base::WrapUnique(job); |
527 return job; | 526 return job; |
528 } | 527 } |
529 | 528 |
530 MHTMLGenerationManager::Job* MHTMLGenerationManager::FindJob(int job_id) { | 529 MHTMLGenerationManager::Job* MHTMLGenerationManager::FindJob(int job_id) { |
531 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 530 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
532 | 531 |
533 IDToJobMap::iterator iter = id_to_job_.find(job_id); | 532 auto iter = id_to_job_.find(job_id); |
534 if (iter == id_to_job_.end()) { | 533 if (iter == id_to_job_.end()) { |
535 NOTREACHED(); | 534 NOTREACHED(); |
536 return nullptr; | 535 return nullptr; |
537 } | 536 } |
538 return iter->second; | 537 return iter->second.get(); |
539 } | 538 } |
540 | 539 |
541 void MHTMLGenerationManager::RenderProcessExited(Job* job) { | 540 void MHTMLGenerationManager::RenderProcessExited(Job* job) { |
542 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 541 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
543 DCHECK(job); | 542 DCHECK(job); |
544 JobFinished(job, JobStatus::FAILURE); | 543 JobFinished(job, JobStatus::FAILURE); |
545 } | 544 } |
546 | 545 |
547 } // namespace content | 546 } // namespace content |
OLD | NEW |