Chromium Code Reviews

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

Issue 2075973002: Revert of Move content/browser/power_save_blocker to //device/power_save_blocker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@power-save-next-2
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 // This file contains download browser tests that are known to be runnable 5 // This file contains download browser tests that are known to be runnable
6 // in a pure content context. Over time tests should be migrated here. 6 // in a pure content context. Over time tests should be migrated here.
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <utility> 10 #include <utility>
(...skipping 12 matching lines...)
23 #include "base/threading/platform_thread.h" 23 #include "base/threading/platform_thread.h"
24 #include "base/time/time.h" 24 #include "base/time/time.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "content/browser/byte_stream.h" 26 #include "content/browser/byte_stream.h"
27 #include "content/browser/download/download_file_factory.h" 27 #include "content/browser/download/download_file_factory.h"
28 #include "content/browser/download/download_file_impl.h" 28 #include "content/browser/download/download_file_impl.h"
29 #include "content/browser/download/download_item_impl.h" 29 #include "content/browser/download/download_item_impl.h"
30 #include "content/browser/download/download_manager_impl.h" 30 #include "content/browser/download/download_manager_impl.h"
31 #include "content/browser/download/download_resource_handler.h" 31 #include "content/browser/download/download_resource_handler.h"
32 #include "content/browser/loader/resource_dispatcher_host_impl.h" 32 #include "content/browser/loader/resource_dispatcher_host_impl.h"
33 #include "content/browser/power_save_blocker_factory.h"
34 #include "content/browser/web_contents/web_contents_impl.h" 33 #include "content/browser/web_contents/web_contents_impl.h"
35 #include "content/public/browser/download_danger_type.h" 34 #include "content/public/browser/download_danger_type.h"
35 #include "content/public/browser/power_save_blocker_factory.h"
36 #include "content/public/browser/resource_dispatcher_host_delegate.h" 36 #include "content/public/browser/resource_dispatcher_host_delegate.h"
37 #include "content/public/browser/resource_throttle.h" 37 #include "content/public/browser/resource_throttle.h"
38 #include "content/public/common/content_features.h" 38 #include "content/public/common/content_features.h"
39 #include "content/public/common/webplugininfo.h" 39 #include "content/public/common/webplugininfo.h"
40 #include "content/public/test/browser_test_utils.h" 40 #include "content/public/test/browser_test_utils.h"
41 #include "content/public/test/content_browser_test.h" 41 #include "content/public/test/content_browser_test.h"
42 #include "content/public/test/content_browser_test_utils.h" 42 #include "content/public/test/content_browser_test_utils.h"
43 #include "content/public/test/download_test_observer.h" 43 #include "content/public/test/download_test_observer.h"
44 #include "content/public/test/test_download_request_handler.h" 44 #include "content/public/test/test_download_request_handler.h"
45 #include "content/public/test/test_file_error_injector.h" 45 #include "content/public/test/test_file_error_injector.h"
(...skipping 69 matching lines...)
115 static DownloadManagerImpl* DownloadManagerForShell(Shell* shell) { 115 static DownloadManagerImpl* DownloadManagerForShell(Shell* shell) {
116 // We're in a content_browsertest; we know that the DownloadManager 116 // We're in a content_browsertest; we know that the DownloadManager
117 // is a DownloadManagerImpl. 117 // is a DownloadManagerImpl.
118 return static_cast<DownloadManagerImpl*>( 118 return static_cast<DownloadManagerImpl*>(
119 BrowserContext::GetDownloadManager( 119 BrowserContext::GetDownloadManager(
120 shell->web_contents()->GetBrowserContext())); 120 shell->web_contents()->GetBrowserContext()));
121 } 121 }
122 122
123 class DownloadFileWithDelay : public DownloadFileImpl { 123 class DownloadFileWithDelay : public DownloadFileImpl {
124 public: 124 public:
125 DownloadFileWithDelay( 125 DownloadFileWithDelay(std::unique_ptr<DownloadSaveInfo> save_info,
126 std::unique_ptr<DownloadSaveInfo> save_info, 126 const base::FilePath& default_download_directory,
127 const base::FilePath& default_download_directory, 127 std::unique_ptr<ByteStreamReader> stream,
128 std::unique_ptr<ByteStreamReader> stream, 128 const net::BoundNetLog& bound_net_log,
129 const net::BoundNetLog& bound_net_log, 129 std::unique_ptr<PowerSaveBlocker> power_save_blocker,
130 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, 130 base::WeakPtr<DownloadDestinationObserver> observer,
131 base::WeakPtr<DownloadDestinationObserver> observer, 131 base::WeakPtr<DownloadFileWithDelayFactory> owner);
132 base::WeakPtr<DownloadFileWithDelayFactory> owner);
133 132
134 ~DownloadFileWithDelay() override; 133 ~DownloadFileWithDelay() override;
135 134
136 // Wraps DownloadFileImpl::Rename* and intercepts the return callback, 135 // Wraps DownloadFileImpl::Rename* and intercepts the return callback,
137 // storing it in the factory that produced this object for later 136 // storing it in the factory that produced this object for later
138 // retrieval. 137 // retrieval.
139 void RenameAndUniquify(const base::FilePath& full_path, 138 void RenameAndUniquify(const base::FilePath& full_path,
140 const RenameCompletionCallback& callback) override; 139 const RenameCompletionCallback& callback) override;
141 void RenameAndAnnotate(const base::FilePath& full_path, 140 void RenameAndAnnotate(const base::FilePath& full_path,
142 const std::string& client_guid, 141 const std::string& client_guid,
(...skipping 44 matching lines...)
187 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_; 186 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_;
188 187
189 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory); 188 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory);
190 }; 189 };
191 190
192 DownloadFileWithDelay::DownloadFileWithDelay( 191 DownloadFileWithDelay::DownloadFileWithDelay(
193 std::unique_ptr<DownloadSaveInfo> save_info, 192 std::unique_ptr<DownloadSaveInfo> save_info,
194 const base::FilePath& default_download_directory, 193 const base::FilePath& default_download_directory,
195 std::unique_ptr<ByteStreamReader> stream, 194 std::unique_ptr<ByteStreamReader> stream,
196 const net::BoundNetLog& bound_net_log, 195 const net::BoundNetLog& bound_net_log,
197 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, 196 std::unique_ptr<PowerSaveBlocker> power_save_blocker,
198 base::WeakPtr<DownloadDestinationObserver> observer, 197 base::WeakPtr<DownloadDestinationObserver> observer,
199 base::WeakPtr<DownloadFileWithDelayFactory> owner) 198 base::WeakPtr<DownloadFileWithDelayFactory> owner)
200 : DownloadFileImpl(std::move(save_info), 199 : DownloadFileImpl(std::move(save_info),
201 default_download_directory, 200 default_download_directory,
202 std::move(stream), 201 std::move(stream),
203 bound_net_log, 202 bound_net_log,
204 observer), 203 observer),
205 owner_(owner) {} 204 owner_(owner) {}
206 205
207 DownloadFileWithDelay::~DownloadFileWithDelay() {} 206 DownloadFileWithDelay::~DownloadFileWithDelay() {}
(...skipping 40 matching lines...)
248 weak_ptr_factory_(this) {} 247 weak_ptr_factory_(this) {}
249 248
250 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} 249 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {}
251 250
252 DownloadFile* DownloadFileWithDelayFactory::CreateFile( 251 DownloadFile* DownloadFileWithDelayFactory::CreateFile(
253 std::unique_ptr<DownloadSaveInfo> save_info, 252 std::unique_ptr<DownloadSaveInfo> save_info,
254 const base::FilePath& default_download_directory, 253 const base::FilePath& default_download_directory,
255 std::unique_ptr<ByteStreamReader> stream, 254 std::unique_ptr<ByteStreamReader> stream,
256 const net::BoundNetLog& bound_net_log, 255 const net::BoundNetLog& bound_net_log,
257 base::WeakPtr<DownloadDestinationObserver> observer) { 256 base::WeakPtr<DownloadDestinationObserver> observer) {
258 std::unique_ptr<device::PowerSaveBlocker> psb(CreatePowerSaveBlocker( 257 std::unique_ptr<PowerSaveBlocker> psb(CreatePowerSaveBlocker(
259 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 258 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
260 device::PowerSaveBlocker::kReasonOther, "Download in progress")); 259 PowerSaveBlocker::kReasonOther, "Download in progress"));
261 return new DownloadFileWithDelay(std::move(save_info), 260 return new DownloadFileWithDelay(std::move(save_info),
262 default_download_directory, 261 default_download_directory,
263 std::move(stream), 262 std::move(stream),
264 bound_net_log, 263 bound_net_log,
265 std::move(psb), 264 std::move(psb),
266 observer, 265 observer,
267 weak_ptr_factory_.GetWeakPtr()); 266 weak_ptr_factory_.GetWeakPtr());
268 } 267 }
269 268
270 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { 269 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) {
(...skipping 14 matching lines...)
285 284
286 if (rename_callbacks_.empty()) { 285 if (rename_callbacks_.empty()) {
287 waiting_ = true; 286 waiting_ = true;
288 RunMessageLoop(); 287 RunMessageLoop();
289 waiting_ = false; 288 waiting_ = false;
290 } 289 }
291 } 290 }
292 291
293 class CountingDownloadFile : public DownloadFileImpl { 292 class CountingDownloadFile : public DownloadFileImpl {
294 public: 293 public:
295 CountingDownloadFile( 294 CountingDownloadFile(std::unique_ptr<DownloadSaveInfo> save_info,
296 std::unique_ptr<DownloadSaveInfo> save_info, 295 const base::FilePath& default_downloads_directory,
297 const base::FilePath& default_downloads_directory, 296 std::unique_ptr<ByteStreamReader> stream,
298 std::unique_ptr<ByteStreamReader> stream, 297 const net::BoundNetLog& bound_net_log,
299 const net::BoundNetLog& bound_net_log, 298 std::unique_ptr<PowerSaveBlocker> power_save_blocker,
300 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, 299 base::WeakPtr<DownloadDestinationObserver> observer)
301 base::WeakPtr<DownloadDestinationObserver> observer)
302 : DownloadFileImpl(std::move(save_info), 300 : DownloadFileImpl(std::move(save_info),
303 default_downloads_directory, 301 default_downloads_directory,
304 std::move(stream), 302 std::move(stream),
305 bound_net_log, 303 bound_net_log,
306 observer) {} 304 observer) {}
307 305
308 ~CountingDownloadFile() override { 306 ~CountingDownloadFile() override {
309 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 307 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
310 active_files_--; 308 active_files_--;
311 } 309 }
(...skipping 33 matching lines...)
345 CountingDownloadFileFactory() {} 343 CountingDownloadFileFactory() {}
346 ~CountingDownloadFileFactory() override {} 344 ~CountingDownloadFileFactory() override {}
347 345
348 // DownloadFileFactory interface. 346 // DownloadFileFactory interface.
349 DownloadFile* CreateFile( 347 DownloadFile* CreateFile(
350 std::unique_ptr<DownloadSaveInfo> save_info, 348 std::unique_ptr<DownloadSaveInfo> save_info,
351 const base::FilePath& default_downloads_directory, 349 const base::FilePath& default_downloads_directory,
352 std::unique_ptr<ByteStreamReader> stream, 350 std::unique_ptr<ByteStreamReader> stream,
353 const net::BoundNetLog& bound_net_log, 351 const net::BoundNetLog& bound_net_log,
354 base::WeakPtr<DownloadDestinationObserver> observer) override { 352 base::WeakPtr<DownloadDestinationObserver> observer) override {
355 std::unique_ptr<device::PowerSaveBlocker> psb(CreatePowerSaveBlocker( 353 std::unique_ptr<PowerSaveBlocker> psb(CreatePowerSaveBlocker(
356 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 354 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
357 device::PowerSaveBlocker::kReasonOther, "Download in progress")); 355 PowerSaveBlocker::kReasonOther, "Download in progress"));
358 return new CountingDownloadFile(std::move(save_info), 356 return new CountingDownloadFile(std::move(save_info),
359 default_downloads_directory, 357 default_downloads_directory,
360 std::move(stream), 358 std::move(stream),
361 bound_net_log, 359 bound_net_log,
362 std::move(psb), 360 std::move(psb),
363 observer); 361 observer);
364 } 362 }
365 }; 363 };
366 364
367 class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate { 365 class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate {
(...skipping 2100 matching lines...)
2468 2466
2469 std::vector<DownloadItem*> downloads; 2467 std::vector<DownloadItem*> downloads;
2470 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); 2468 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
2471 ASSERT_EQ(1u, downloads.size()); 2469 ASSERT_EQ(1u, downloads.size());
2472 2470
2473 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), 2471 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"),
2474 downloads[0]->GetTargetFilePath().BaseName().value()); 2472 downloads[0]->GetTargetFilePath().BaseName().value());
2475 } 2473 }
2476 2474
2477 } // namespace content 2475 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/render_frame_devtools_agent_host.cc ('k') | content/browser/download/download_request_core.h » ('j') | no next file with comments »

Powered by Google App Engine