| 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 // 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 "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // We're in a content_browsertest; we know that the DownloadManager | 68 // We're in a content_browsertest; we know that the DownloadManager |
| 69 // is a DownloadManagerImpl. | 69 // is a DownloadManagerImpl. |
| 70 return static_cast<DownloadManagerImpl*>( | 70 return static_cast<DownloadManagerImpl*>( |
| 71 BrowserContext::GetDownloadManager( | 71 BrowserContext::GetDownloadManager( |
| 72 shell->web_contents()->GetBrowserContext())); | 72 shell->web_contents()->GetBrowserContext())); |
| 73 } | 73 } |
| 74 | 74 |
| 75 class DownloadFileWithDelay : public DownloadFileImpl { | 75 class DownloadFileWithDelay : public DownloadFileImpl { |
| 76 public: | 76 public: |
| 77 DownloadFileWithDelay( | 77 DownloadFileWithDelay( |
| 78 const DownloadCreateInfo* info, | 78 scoped_ptr<DownloadCreateInfo> info, |
| 79 scoped_ptr<content::ByteStreamReader> stream, | 79 scoped_ptr<content::ByteStreamReader> stream, |
| 80 DownloadRequestHandleInterface* request_handle, | 80 DownloadRequestHandleInterface* request_handle, |
| 81 scoped_refptr<content::DownloadManager> download_manager, | 81 scoped_refptr<content::DownloadManager> download_manager, |
| 82 bool calculate_hash, | 82 bool calculate_hash, |
| 83 scoped_ptr<content::PowerSaveBlocker> power_save_blocker, | 83 scoped_ptr<content::PowerSaveBlocker> power_save_blocker, |
| 84 const net::BoundNetLog& bound_net_log, | 84 const net::BoundNetLog& bound_net_log, |
| 85 // |owner| is required to outlive the DownloadFileWithDelay. | 85 // |owner| is required to outlive the DownloadFileWithDelay. |
| 86 DownloadFileWithDelayFactory* owner); | 86 DownloadFileWithDelayFactory* owner); |
| 87 | 87 |
| 88 virtual ~DownloadFileWithDelay(); | 88 virtual ~DownloadFileWithDelay(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 116 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelay); | 116 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelay); |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 class DownloadFileWithDelayFactory : public DownloadFileFactory { | 119 class DownloadFileWithDelayFactory : public DownloadFileFactory { |
| 120 public: | 120 public: |
| 121 DownloadFileWithDelayFactory(); | 121 DownloadFileWithDelayFactory(); |
| 122 virtual ~DownloadFileWithDelayFactory(); | 122 virtual ~DownloadFileWithDelayFactory(); |
| 123 | 123 |
| 124 // DownloadFileFactory interface. | 124 // DownloadFileFactory interface. |
| 125 virtual content::DownloadFile* CreateFile( | 125 virtual content::DownloadFile* CreateFile( |
| 126 DownloadCreateInfo* info, | 126 scoped_ptr<DownloadCreateInfo> info, |
| 127 scoped_ptr<content::ByteStreamReader> stream, | 127 scoped_ptr<content::ByteStreamReader> stream, |
| 128 DownloadManager* download_manager, | 128 DownloadManager* download_manager, |
| 129 bool calculate_hash, | 129 bool calculate_hash, |
| 130 const net::BoundNetLog& bound_net_log) OVERRIDE; | 130 const net::BoundNetLog& bound_net_log) OVERRIDE; |
| 131 | 131 |
| 132 // Must all be called on the UI thread. | 132 // Must all be called on the UI thread. |
| 133 void AddRenameCallback(base::Closure callback); | 133 void AddRenameCallback(base::Closure callback); |
| 134 void AddDetachCallback(base::Closure callback); | 134 void AddDetachCallback(base::Closure callback); |
| 135 void GetAllRenameCallbacks(std::vector<base::Closure>* results); | 135 void GetAllRenameCallbacks(std::vector<base::Closure>* results); |
| 136 void GetAllDetachCallbacks(std::vector<base::Closure>* results); | 136 void GetAllDetachCallbacks(std::vector<base::Closure>* results); |
| 137 | 137 |
| 138 // Do not return until either GetAllRenameCallbacks() or | 138 // Do not return until either GetAllRenameCallbacks() or |
| 139 // GetAllDetachCallbacks() will return a non-empty list. | 139 // GetAllDetachCallbacks() will return a non-empty list. |
| 140 void WaitForSomeCallback(); | 140 void WaitForSomeCallback(); |
| 141 | 141 |
| 142 private: | 142 private: |
| 143 std::vector<base::Closure> rename_callbacks_; | 143 std::vector<base::Closure> rename_callbacks_; |
| 144 std::vector<base::Closure> detach_callbacks_; | 144 std::vector<base::Closure> detach_callbacks_; |
| 145 bool waiting_; | 145 bool waiting_; |
| 146 | 146 |
| 147 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory); | 147 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory); |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 DownloadFileWithDelay::DownloadFileWithDelay( | 150 DownloadFileWithDelay::DownloadFileWithDelay( |
| 151 const DownloadCreateInfo* info, | 151 scoped_ptr<DownloadCreateInfo> info, |
| 152 scoped_ptr<content::ByteStreamReader> stream, | 152 scoped_ptr<content::ByteStreamReader> stream, |
| 153 DownloadRequestHandleInterface* request_handle, | 153 DownloadRequestHandleInterface* request_handle, |
| 154 scoped_refptr<content::DownloadManager> download_manager, | 154 scoped_refptr<content::DownloadManager> download_manager, |
| 155 bool calculate_hash, | 155 bool calculate_hash, |
| 156 scoped_ptr<content::PowerSaveBlocker> power_save_blocker, | 156 scoped_ptr<content::PowerSaveBlocker> power_save_blocker, |
| 157 const net::BoundNetLog& bound_net_log, | 157 const net::BoundNetLog& bound_net_log, |
| 158 DownloadFileWithDelayFactory* owner) | 158 DownloadFileWithDelayFactory* owner) |
| 159 : DownloadFileImpl(info, stream.Pass(), request_handle, download_manager, | 159 : DownloadFileImpl(info.Pass(), stream.Pass(), request_handle, |
| 160 calculate_hash, power_save_blocker.Pass(), | 160 download_manager, calculate_hash, |
| 161 bound_net_log), | 161 power_save_blocker.Pass(), bound_net_log), |
| 162 owner_(owner) {} | 162 owner_(owner) {} |
| 163 | 163 |
| 164 DownloadFileWithDelay::~DownloadFileWithDelay() {} | 164 DownloadFileWithDelay::~DownloadFileWithDelay() {} |
| 165 | 165 |
| 166 void DownloadFileWithDelay::Rename(const FilePath& full_path, | 166 void DownloadFileWithDelay::Rename(const FilePath& full_path, |
| 167 bool overwrite_existing_file, | 167 bool overwrite_existing_file, |
| 168 const RenameCompletionCallback& callback) { | 168 const RenameCompletionCallback& callback) { |
| 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 170 DownloadFileImpl::Rename( | 170 DownloadFileImpl::Rename( |
| 171 full_path, overwrite_existing_file, | 171 full_path, overwrite_existing_file, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 196 const base::Closure& original_callback) { | 196 const base::Closure& original_callback) { |
| 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 198 factory->AddDetachCallback(original_callback); | 198 factory->AddDetachCallback(original_callback); |
| 199 } | 199 } |
| 200 | 200 |
| 201 DownloadFileWithDelayFactory::DownloadFileWithDelayFactory() | 201 DownloadFileWithDelayFactory::DownloadFileWithDelayFactory() |
| 202 : waiting_(false) {} | 202 : waiting_(false) {} |
| 203 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} | 203 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} |
| 204 | 204 |
| 205 DownloadFile* DownloadFileWithDelayFactory::CreateFile( | 205 DownloadFile* DownloadFileWithDelayFactory::CreateFile( |
| 206 DownloadCreateInfo* info, | 206 scoped_ptr<DownloadCreateInfo> info, |
| 207 scoped_ptr<content::ByteStreamReader> stream, | 207 scoped_ptr<content::ByteStreamReader> stream, |
| 208 DownloadManager* download_manager, | 208 DownloadManager* download_manager, |
| 209 bool calculate_hash, | 209 bool calculate_hash, |
| 210 const net::BoundNetLog& bound_net_log) { | 210 const net::BoundNetLog& bound_net_log) { |
| 211 // Ownership will be taken by DownloadFileWithDelay. |
| 212 DownloadRequestHandle* request_handle( |
| 213 new DownloadRequestHandle(info->request_handle)); |
| 211 | 214 |
| 212 return new DownloadFileWithDelay( | 215 return new DownloadFileWithDelay( |
| 213 info, stream.Pass(), new DownloadRequestHandle(info->request_handle), | 216 info.Pass(), stream.Pass(), request_handle, download_manager, |
| 214 download_manager, calculate_hash, | 217 calculate_hash, |
| 215 scoped_ptr<content::PowerSaveBlocker>( | 218 scoped_ptr<content::PowerSaveBlocker>( |
| 216 new content::PowerSaveBlocker( | 219 new content::PowerSaveBlocker( |
| 217 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 220 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 218 "Download in progress")).Pass(), | 221 "Download in progress")).Pass(), |
| 219 bound_net_log, this); | 222 bound_net_log, this); |
| 220 } | 223 } |
| 221 | 224 |
| 222 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { | 225 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { |
| 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 224 rename_callbacks_.push_back(callback); | 227 rename_callbacks_.push_back(callback); |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 // Shutdown the download manager. Mostly this is confirming a lack of | 662 // Shutdown the download manager. Mostly this is confirming a lack of |
| 660 // crashes. | 663 // crashes. |
| 661 DownloadManagerForShell(shell())->Shutdown(); | 664 DownloadManagerForShell(shell())->Shutdown(); |
| 662 | 665 |
| 663 // Run the detach callback; shouldn't cause any problems. | 666 // Run the detach callback; shouldn't cause any problems. |
| 664 callbacks[0].Run(); | 667 callbacks[0].Run(); |
| 665 callbacks.clear(); | 668 callbacks.clear(); |
| 666 } | 669 } |
| 667 | 670 |
| 668 } // namespace content | 671 } // namespace content |
| OLD | NEW |