| OLD | NEW |
| 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/download_request_handle.h" | 5 #include "content/browser/download/download_request_handle.h" |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "content/browser/browser_context.h" | 8 #include "content/browser/browser_context.h" |
| 9 #include "content/browser/browser_thread.h" | 9 #include "content/browser/browser_thread.h" |
| 10 #include "content/browser/renderer_host/render_view_host.h" | 10 #include "content/browser/renderer_host/render_view_host.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 TabContents* DownloadRequestHandle::GetTabContents() const { | 54 TabContents* DownloadRequestHandle::GetTabContents() const { |
| 55 RenderViewHost* render_view_host = | 55 RenderViewHost* render_view_host = |
| 56 RenderViewHost::FromID(child_id_, render_view_id_); | 56 RenderViewHost::FromID(child_id_, render_view_id_); |
| 57 if (!render_view_host) | 57 if (!render_view_host) |
| 58 return NULL; | 58 return NULL; |
| 59 | 59 |
| 60 return render_view_host->delegate()->GetAsTabContents(); | 60 return render_view_host->delegate()->GetAsTabContents(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 DownloadManager* DownloadRequestHandle::GetDownloadManager() const { | 63 DownloadManager* DownloadRequestHandle::GetDownloadManager() const { |
| 64 TabContents* contents = GetTabContents(); | 64 RenderViewHost* rvh = RenderViewHost::FromID(child_id_, render_view_id_); |
| 65 if (!contents) | 65 if (rvh == NULL) |
| 66 return NULL; | 66 return NULL; |
| 67 | 67 RenderProcessHost* rph = rvh->process(); |
| 68 content::BrowserContext* browser_context = contents->browser_context(); | 68 if (rph == NULL) |
| 69 if (!browser_context) | |
| 70 return NULL; | 69 return NULL; |
| 71 | 70 content::BrowserContext* context = rph->browser_context(); |
| 72 return browser_context->GetDownloadManager(); | 71 if (context == NULL) |
| 72 return NULL; |
| 73 return context->GetDownloadManager(); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void DownloadRequestHandle::PauseRequest() const { | 76 void DownloadRequestHandle::PauseRequest() const { |
| 76 // The post is safe because ResourceDispatcherHost is guaranteed | 77 // The post is safe because ResourceDispatcherHost is guaranteed |
| 77 // to outlive the IO thread. | 78 // to outlive the IO thread. |
| 78 if (rdh_) { | 79 if (rdh_) { |
| 79 BrowserThread::PostTask( | 80 BrowserThread::PostTask( |
| 80 BrowserThread::IO, FROM_HERE, | 81 BrowserThread::IO, FROM_HERE, |
| 81 NewRunnableFunction(&ResourceDispatcherHostPauseRequest, | 82 NewRunnableFunction(&ResourceDispatcherHostPauseRequest, |
| 82 rdh_, child_id_, request_id_, true)); | 83 rdh_, child_id_, request_id_, true)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 108 std::string DownloadRequestHandle::DebugString() const { | 109 std::string DownloadRequestHandle::DebugString() const { |
| 109 return base::StringPrintf("{" | 110 return base::StringPrintf("{" |
| 110 " child_id = %d" | 111 " child_id = %d" |
| 111 " render_view_id = %d" | 112 " render_view_id = %d" |
| 112 " request_id = %d" | 113 " request_id = %d" |
| 113 "}", | 114 "}", |
| 114 child_id_, | 115 child_id_, |
| 115 render_view_id_, | 116 render_view_id_, |
| 116 request_id_); | 117 request_id_); |
| 117 } | 118 } |
| OLD | NEW |