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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 90 } |
91 | 91 |
92 // Collect the information from FILE and IO threads needed for the Cancel | 92 // Collect the information from FILE and IO threads needed for the Cancel |
93 // Test, specifically the number of outstanding requests on the | 93 // Test, specifically the number of outstanding requests on the |
94 // ResourceDispatcherHost and the number of pending downloads on the | 94 // ResourceDispatcherHost and the number of pending downloads on the |
95 // DownloadFileManager. | 95 // DownloadFileManager. |
96 class CancelTestDataCollector | 96 class CancelTestDataCollector |
97 : public base::RefCountedThreadSafe<CancelTestDataCollector> { | 97 : public base::RefCountedThreadSafe<CancelTestDataCollector> { |
98 public: | 98 public: |
99 CancelTestDataCollector() | 99 CancelTestDataCollector() |
100 : resource_dispatcher_host_( | 100 : slow_download_job_pending_requests_(0), |
101 g_browser_process->resource_dispatcher_host()), | |
102 slow_download_job_pending_requests_(0), | |
103 dfm_pending_downloads_(0) { } | 101 dfm_pending_downloads_(0) { } |
104 | 102 |
105 void WaitForDataCollected() { | 103 void WaitForDataCollected() { |
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
107 BrowserThread::PostTask( | 105 BrowserThread::PostTask( |
108 BrowserThread::IO, FROM_HERE, | 106 BrowserThread::IO, FROM_HERE, |
109 base::Bind(&CancelTestDataCollector::IOInfoCollector, this)); | 107 base::Bind(&CancelTestDataCollector::IOInfoCollector, this)); |
110 ui_test_utils::RunMessageLoop(); | 108 ui_test_utils::RunMessageLoop(); |
111 } | 109 } |
112 | 110 |
113 int slow_download_job_pending_requests() const { | 111 int slow_download_job_pending_requests() const { |
114 return slow_download_job_pending_requests_; | 112 return slow_download_job_pending_requests_; |
115 } | 113 } |
116 | 114 |
117 int dfm_pending_downloads() const { return dfm_pending_downloads_; } | 115 int dfm_pending_downloads() const { return dfm_pending_downloads_; } |
118 | 116 |
119 protected: | 117 protected: |
120 friend class base::RefCountedThreadSafe<CancelTestDataCollector>; | 118 friend class base::RefCountedThreadSafe<CancelTestDataCollector>; |
121 | 119 |
122 virtual ~CancelTestDataCollector() {} | 120 virtual ~CancelTestDataCollector() {} |
123 | 121 |
124 private: | 122 private: |
125 | 123 |
126 void IOInfoCollector() { | 124 void IOInfoCollector() { |
127 download_file_manager_ = resource_dispatcher_host_->download_file_manager(); | 125 download_file_manager_ = |
| 126 ResourceDispatcherHost::Get()->download_file_manager(); |
128 slow_download_job_pending_requests_ = | 127 slow_download_job_pending_requests_ = |
129 URLRequestSlowDownloadJob::NumberOutstandingRequests(); | 128 URLRequestSlowDownloadJob::NumberOutstandingRequests(); |
130 BrowserThread::PostTask( | 129 BrowserThread::PostTask( |
131 BrowserThread::FILE, FROM_HERE, | 130 BrowserThread::FILE, FROM_HERE, |
132 base::Bind(&CancelTestDataCollector::FileInfoCollector, this)); | 131 base::Bind(&CancelTestDataCollector::FileInfoCollector, this)); |
133 } | 132 } |
134 | 133 |
135 void FileInfoCollector() { | 134 void FileInfoCollector() { |
136 dfm_pending_downloads_ = download_file_manager_->NumberOfActiveDownloads(); | 135 dfm_pending_downloads_ = download_file_manager_->NumberOfActiveDownloads(); |
137 BrowserThread::PostTask( | 136 BrowserThread::PostTask( |
138 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); | 137 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); |
139 } | 138 } |
140 | 139 |
141 ResourceDispatcherHost* resource_dispatcher_host_; | |
142 DownloadFileManager* download_file_manager_; | 140 DownloadFileManager* download_file_manager_; |
143 int slow_download_job_pending_requests_; | 141 int slow_download_job_pending_requests_; |
144 int dfm_pending_downloads_; | 142 int dfm_pending_downloads_; |
145 | 143 |
146 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); | 144 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); |
147 }; | 145 }; |
148 | 146 |
149 class PickSuggestedFileDelegate : public ChromeDownloadManagerDelegate { | 147 class PickSuggestedFileDelegate : public ChromeDownloadManagerDelegate { |
150 public: | 148 public: |
151 explicit PickSuggestedFileDelegate(Profile* profile) | 149 explicit PickSuggestedFileDelegate(Profile* profile) |
(...skipping 1580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1732 | 1730 |
1733 // Check state. | 1731 // Check state. |
1734 EXPECT_EQ(1, browser()->tab_count()); | 1732 EXPECT_EQ(1, browser()->tab_count()); |
1735 ASSERT_TRUE(CheckDownloadFullPaths(browser(), | 1733 ASSERT_TRUE(CheckDownloadFullPaths(browser(), |
1736 target_file_full_path, | 1734 target_file_full_path, |
1737 OriginFile(file))); | 1735 OriginFile(file))); |
1738 | 1736 |
1739 // Temporary downloads won't be visible. | 1737 // Temporary downloads won't be visible. |
1740 CheckDownloadUI(browser(), false, false, file); | 1738 CheckDownloadUI(browser(), false, false, file); |
1741 } | 1739 } |
OLD | NEW |