diff options
author | rdsmith@chromium.org <rdsmith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-19 17:29:31 +0000 |
---|---|---|
committer | rdsmith@chromium.org <rdsmith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-19 17:29:31 +0000 |
commit | 5c89736a6794265f8f409a5e0b822ff7ed7dd5cf (patch) | |
tree | 4cfe33070f94c3e20da0e6a700299592070845e5 | |
parent | 536ebe2307fa5b14dda84227bef8236ee646b12e (diff) | |
download | chromium_src-5c89736a6794265f8f409a5e0b822ff7ed7dd5cf.zip chromium_src-5c89736a6794265f8f409a5e0b822ff7ed7dd5cf.tar.gz chromium_src-5c89736a6794265f8f409a5e0b822ff7ed7dd5cf.tar.bz2 |
Make PowerSaveBlocker object an argument to DownloadFileImpl constructor
so that we don't need to worry about it in unittests.
BUG=110886
TEST=Run DownloadFileTest.* over an NX connection.
R=benjhayden@chromium.org
Review URL: http://codereview.chromium.org/10116027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132998 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/browser/download/base_file.cc | 1 | ||||
-rw-r--r-- | content/browser/download/base_file.h | 4 | ||||
-rw-r--r-- | content/browser/download/download_file_impl.cc | 5 | ||||
-rw-r--r-- | content/browser/download/download_file_impl.h | 7 | ||||
-rw-r--r-- | content/browser/download/download_file_manager.cc | 12 | ||||
-rw-r--r-- | content/browser/download/download_file_unittest.cc | 11 | ||||
-rw-r--r-- | content/browser/download/download_manager_impl_unittest.cc | 15 | ||||
-rw-r--r-- | content/browser/power_save_blocker.h | 5 | ||||
-rw-r--r-- | content/test/test_file_error_injector.cc | 2 |
9 files changed, 39 insertions, 23 deletions
diff --git a/content/browser/download/base_file.cc b/content/browser/download/base_file.cc index 5c27ade..9516fb3 100644 --- a/content/browser/download/base_file.cc +++ b/content/browser/download/base_file.cc @@ -215,7 +215,6 @@ BaseFile::BaseFile(const FilePath& full_path, file_stream_(file_stream), bytes_so_far_(received_bytes), start_tick_(base::TimeTicks::Now()), - power_save_blocker_(PowerSaveBlocker::kPowerSaveBlockPreventSystemSleep), calculate_hash_(calculate_hash), detached_(false), bound_net_log_(bound_net_log) { diff --git a/content/browser/download/base_file.h b/content/browser/download/base_file.h index 00a83e6..cd6f2fd 100644 --- a/content/browser/download/base_file.h +++ b/content/browser/download/base_file.h @@ -13,7 +13,6 @@ #include "base/memory/linked_ptr.h" #include "base/memory/scoped_ptr.h" #include "base/time.h" -#include "content/browser/power_save_blocker.h" #include "content/common/content_export.h" #include "googleurl/src/gurl.h" #include "net/base/file_stream.h" @@ -125,9 +124,6 @@ class CONTENT_EXPORT BaseFile { // Start time for calculating speed. base::TimeTicks start_tick_; - // RAII handle to keep the system from sleeping while we're downloading. - PowerSaveBlocker power_save_blocker_; - // Indicates if hash should be calculated for the file. bool calculate_hash_; diff --git a/content/browser/download/download_file_impl.cc b/content/browser/download/download_file_impl.cc index 5fb7ffc..3d1b1a9 100644 --- a/content/browser/download/download_file_impl.cc +++ b/content/browser/download/download_file_impl.cc @@ -8,6 +8,7 @@ #include "base/file_util.h" #include "content/browser/download/download_create_info.h" +#include "content/browser/power_save_blocker.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/download_manager.h" @@ -20,6 +21,7 @@ DownloadFileImpl::DownloadFileImpl( DownloadRequestHandleInterface* request_handle, DownloadManager* download_manager, bool calculate_hash, + scoped_ptr<PowerSaveBlocker> power_save_blocker, const net::BoundNetLog& bound_net_log) : file_(info->save_info.file_path, info->url(), @@ -31,7 +33,8 @@ DownloadFileImpl::DownloadFileImpl( bound_net_log), id_(info->download_id), request_handle_(request_handle), - download_manager_(download_manager) { + download_manager_(download_manager), + power_save_blocker_(power_save_blocker.Pass()) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); } diff --git a/content/browser/download/download_file_impl.h b/content/browser/download/download_file_impl.h index b66174e..9fed5d7 100644 --- a/content/browser/download/download_file_impl.h +++ b/content/browser/download/download_file_impl.h @@ -9,9 +9,12 @@ #include "content/browser/download/download_file.h" #include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" #include "content/browser/download/base_file.h" #include "content/browser/download/download_request_handle.h" +class PowerSaveBlocker; + struct DownloadCreateInfo; namespace content { @@ -26,6 +29,7 @@ class CONTENT_EXPORT DownloadFileImpl : virtual public content::DownloadFile { DownloadRequestHandleInterface* request_handle, content::DownloadManager* download_manager, bool calculate_hash, + scoped_ptr<PowerSaveBlocker> power_save_blocker, const net::BoundNetLog& bound_net_log); virtual ~DownloadFileImpl(); @@ -65,6 +69,9 @@ class CONTENT_EXPORT DownloadFileImpl : virtual public content::DownloadFile { // DownloadManager this download belongs to. scoped_refptr<content::DownloadManager> download_manager_; + // RAII handle to keep the system from sleeping while we're downloading. + scoped_ptr<PowerSaveBlocker> power_save_blocker_; + DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); }; diff --git a/content/browser/download/download_file_manager.cc b/content/browser/download/download_file_manager.cc index e50dd9b..1a67cb0 100644 --- a/content/browser/download/download_file_manager.cc +++ b/content/browser/download/download_file_manager.cc @@ -19,6 +19,7 @@ #include "content/browser/download/download_interrupt_reasons_impl.h" #include "content/browser/download/download_request_handle.h" #include "content/browser/download/download_stats.h" +#include "content/browser/power_save_blocker.h" #include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/download_manager.h" @@ -56,10 +57,13 @@ DownloadFile* DownloadFileFactoryImpl::CreateFile( DownloadManager* download_manager, bool calculate_hash, const net::BoundNetLog& bound_net_log) { - return new DownloadFileImpl(info, - new DownloadRequestHandle(request_handle), - download_manager, calculate_hash, - bound_net_log); + return new DownloadFileImpl( + info, new DownloadRequestHandle(request_handle), + download_manager, calculate_hash, + scoped_ptr<PowerSaveBlocker>( + new PowerSaveBlocker( + PowerSaveBlocker::kPowerSaveBlockPreventSystemSleep)).Pass(), + bound_net_log); } } // namespace diff --git a/content/browser/download/download_file_unittest.cc b/content/browser/download/download_file_unittest.cc index 2708d76f..5b2936e 100644 --- a/content/browser/download/download_file_unittest.cc +++ b/content/browser/download/download_file_unittest.cc @@ -9,19 +9,13 @@ #include "content/browser/download/download_create_info.h" #include "content/browser/download/download_file_impl.h" #include "content/browser/download/download_request_handle.h" +#include "content/browser/power_save_blocker.h" #include "content/public/browser/download_manager.h" #include "content/test/mock_download_manager.h" #include "net/base/file_stream.h" #include "net/base/net_errors.h" #include "testing/gtest/include/gtest/gtest.h" -#if defined(OS_LINUX) -// http://crbug.com/110886 for Linux -#define MAYBE_RenameFileFinal DISABLED_RenameFileFinal -#else -#define MAYBE_RenameFileFinal RenameFileFinal -#endif - using content::BrowserThread; using content::BrowserThreadImpl; using content::DownloadFile; @@ -77,6 +71,7 @@ class DownloadFileTest : public testing::Test { file->reset( new DownloadFileImpl(&info, new DownloadRequestHandle(), download_manager_, calculate_hash, + scoped_ptr<PowerSaveBlocker>(NULL).Pass(), net::BoundNetLog())); } @@ -139,7 +134,7 @@ const int DownloadFileTest::kDummyRequestId = 67; // Rename the file before any data is downloaded, after some has, after it all // has, and after it's closed. -TEST_F(DownloadFileTest, MAYBE_RenameFileFinal) { +TEST_F(DownloadFileTest, RenameFileFinal) { CreateDownloadFile(&download_file_, 0, true); ASSERT_EQ(net::OK, download_file_->Initialize()); FilePath initial_path(download_file_->FullPath()); diff --git a/content/browser/download/download_manager_impl_unittest.cc b/content/browser/download/download_manager_impl_unittest.cc index abafb14..221692e 100644 --- a/content/browser/download/download_manager_impl_unittest.cc +++ b/content/browser/download/download_manager_impl_unittest.cc @@ -9,6 +9,7 @@ #include "base/file_util.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" +#include "base/memory/scoped_ptr.h" #include "base/scoped_temp_dir.h" #include "base/stl_util.h" #include "base/string16.h" @@ -22,6 +23,7 @@ #include "content/browser/download/download_manager_impl.h" #include "content/browser/download/download_request_handle.h" #include "content/browser/download/mock_download_file.h" +#include "content/browser/power_save_blocker.h" #include "content/public/browser/download_interrupt_reasons.h" #include "content/public/browser/download_item.h" #include "content/public/browser/download_manager_delegate.h" @@ -349,6 +351,7 @@ DownloadFileWithErrors::DownloadFileWithErrors(DownloadCreateInfo* info, new DownloadRequestHandle(), manager, calculate_hash, + scoped_ptr<PowerSaveBlocker>(NULL).Pass(), net::BoundNetLog()), forced_error_(net::OK) { } @@ -539,7 +542,9 @@ TEST_F(DownloadManagerTest, MAYBE_StartDownload) { DownloadFile* download_file( new DownloadFileImpl(info.get(), new DownloadRequestHandle(), - download_manager_, false, net::BoundNetLog())); + download_manager_, false, + scoped_ptr<PowerSaveBlocker>(NULL).Pass(), + net::BoundNetLog())); AddDownloadToFileManager(info->download_id.local(), download_file); download_file->Initialize(); download_manager_->StartDownload(info->download_id.local()); @@ -1184,7 +1189,9 @@ TEST_F(DownloadManagerTest, MAYBE_DownloadOverwriteTest) { // properly. DownloadFile* download_file( new DownloadFileImpl(info.get(), new DownloadRequestHandle(), - download_manager_, false, net::BoundNetLog())); + download_manager_, false, + scoped_ptr<PowerSaveBlocker>(NULL).Pass(), + net::BoundNetLog())); download_file->Rename(cr_path); // This creates the .temp version of the file. download_file->Initialize(); @@ -1258,7 +1265,9 @@ TEST_F(DownloadManagerTest, MAYBE_DownloadRemoveTest) { // properly. DownloadFile* download_file( new DownloadFileImpl(info.get(), new DownloadRequestHandle(), - download_manager_, false, net::BoundNetLog())); + download_manager_, false, + scoped_ptr<PowerSaveBlocker>(NULL).Pass(), + net::BoundNetLog())); download_file->Rename(cr_path); // This creates the .temp version of the file. download_file->Initialize(); diff --git a/content/browser/power_save_blocker.h b/content/browser/power_save_blocker.h index 48ebbc0..7e6e79b 100644 --- a/content/browser/power_save_blocker.h +++ b/content/browser/power_save_blocker.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,9 +9,10 @@ #include <vector> #include "base/basictypes.h" +#include "content/common/content_export.h" // A RAII-style class to block the system from entering low-power (sleep) mode. -class PowerSaveBlocker { +class CONTENT_EXPORT PowerSaveBlocker { public: enum PowerSaveBlockerType { kPowerSaveBlockPreventNone = -1, diff --git a/content/test/test_file_error_injector.cc b/content/test/test_file_error_injector.cc index e4e59ec..2364f6a 100644 --- a/content/test/test_file_error_injector.cc +++ b/content/test/test_file_error_injector.cc @@ -11,6 +11,7 @@ #include "content/browser/download/download_create_info.h" #include "content/browser/download/download_file_impl.h" #include "content/browser/download/download_file_manager.h" +#include "content/browser/power_save_blocker.h" #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/download_id.h" @@ -83,6 +84,7 @@ DownloadFileWithErrors::DownloadFileWithErrors( request_handle, download_manager, calculate_hash, + scoped_ptr<PowerSaveBlocker>(NULL).Pass(), bound_net_log), source_url_(info->url()), error_info_(error_info), |