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

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

Issue 8672001: Revert 111252 - Switch MHTMLGenerationManager to use a Callback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/platform_file.h" 8 #include "base/platform_file.h"
9 #include "content/browser/renderer_host/render_process_host_impl.h" 9 #include "content/browser/renderer_host/render_process_host_impl.h"
10 #include "content/browser/renderer_host/render_view_host.h" 10 #include "content/browser/renderer_host/render_view_host.h"
(...skipping 11 matching lines...) Expand all
22 routing_id(-1) { 22 routing_id(-1) {
23 } 23 }
24 24
25 MHTMLGenerationManager::MHTMLGenerationManager() { 25 MHTMLGenerationManager::MHTMLGenerationManager() {
26 } 26 }
27 27
28 MHTMLGenerationManager::~MHTMLGenerationManager() { 28 MHTMLGenerationManager::~MHTMLGenerationManager() {
29 } 29 }
30 30
31 void MHTMLGenerationManager::GenerateMHTML(TabContents* tab_contents, 31 void MHTMLGenerationManager::GenerateMHTML(TabContents* tab_contents,
32 const FilePath& file, 32 const FilePath& file) {
33 const GenerateMHTMLCallback& callback) {
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
35 static int id_counter = 0; 34 static int id_counter = 0;
36 35
37 int job_id = id_counter++; 36 int job_id = id_counter++;
38 Job job; 37 Job job;
39 job.file_path = file; 38 job.file_path = file;
40 job.process_id = tab_contents->GetRenderProcessHost()->GetID(); 39 job.process_id = tab_contents->GetRenderProcessHost()->GetID();
41 job.routing_id = tab_contents->render_view_host()->routing_id(); 40 job.routing_id = tab_contents->render_view_host()->routing_id();
42 job.callback = callback;
43 id_to_job_[job_id] = job; 41 id_to_job_[job_id] = job;
44 42
45 base::ProcessHandle renderer_process = 43 base::ProcessHandle renderer_process =
46 tab_contents->GetRenderProcessHost()->GetHandle(); 44 tab_contents->GetRenderProcessHost()->GetHandle();
47 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 45 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
48 base::Bind(&MHTMLGenerationManager::CreateFile, this, 46 base::Bind(&MHTMLGenerationManager::CreateFile, this,
49 job_id, file, renderer_process)); 47 job_id, file, renderer_process));
50 } 48 }
51 49
52 void MHTMLGenerationManager::MHTMLGenerated(int job_id, int64 mhtml_data_size) { 50 void MHTMLGenerationManager::MHTMLGenerated(int job_id, int64 mhtml_data_size) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 102 }
105 103
106 void MHTMLGenerationManager::JobFinished(int job_id, int64 file_size) { 104 void MHTMLGenerationManager::JobFinished(int job_id, int64 file_size) {
107 IDToJobMap::iterator iter = id_to_job_.find(job_id); 105 IDToJobMap::iterator iter = id_to_job_.find(job_id);
108 if (iter == id_to_job_.end()) { 106 if (iter == id_to_job_.end()) {
109 NOTREACHED(); 107 NOTREACHED();
110 return; 108 return;
111 } 109 }
112 110
113 Job& job = iter->second; 111 Job& job = iter->second;
114 job.callback.Run(job.file_path, file_size); 112
113 RenderViewHost* rvh = RenderViewHost::FromID(job.process_id, job.routing_id);
114 if (rvh) {
115 NotificationDetails details;
116 details.file_path = job.file_path;
117 details.file_size = file_size;
118
119 content::NotificationService::current()->Notify(
120 content::NOTIFICATION_MHTML_GENERATED,
121 content::Source<RenderViewHost>(rvh),
122 content::Details<NotificationDetails>(&details));
123 }
115 124
116 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 125 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
117 base::Bind(&MHTMLGenerationManager::CloseFile, this, job.browser_file)); 126 base::Bind(&MHTMLGenerationManager::CloseFile, this, job.browser_file));
118 127
119 id_to_job_.erase(job_id); 128 id_to_job_.erase(job_id);
120 } 129 }
121 130
122 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) { 131 void MHTMLGenerationManager::CloseFile(base::PlatformFile file) {
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
124 base::ClosePlatformFile(file); 133 base::ClosePlatformFile(file);
125 } 134 }
OLDNEW
« no previous file with comments | « content/browser/download/mhtml_generation_manager.h ('k') | content/public/browser/notification_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698