Skip to content

Commit

Permalink
Power save blocker: switch to new implementation. In addition to maki…
Browse files Browse the repository at this point in the history
…ng things

much simpler, this will also fix bug 126591 on Windows 8 by activating the new
code in r140668.

BUG=126591

Review URL: https://chromiumcodereview.appspot.com/10542089

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141433 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mdm@chromium.org committed Jun 11, 2012
1 parent bb23e67 commit 6b55aec
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 723 deletions.
2 changes: 1 addition & 1 deletion content/browser/download/download_file_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ DownloadFileImpl::DownloadFileImpl(
DownloadRequestHandleInterface* request_handle,
DownloadManager* download_manager,
bool calculate_hash,
scoped_ptr<PowerSaveBlocker> power_save_blocker,
scoped_ptr<content::PowerSaveBlocker> power_save_blocker,
const net::BoundNetLog& bound_net_log)
: file_(info->save_info.file_path,
info->url(),
Expand Down
7 changes: 3 additions & 4 deletions content/browser/download/download_file_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
#include "content/browser/download/download_request_handle.h"
#include "net/base/net_log.h"

class PowerSaveBlocker;

struct DownloadCreateInfo;

namespace content {
class ByteStreamReader;
class DownloadManager;
class PowerSaveBlocker;
}

class CONTENT_EXPORT DownloadFileImpl : virtual public content::DownloadFile {
Expand All @@ -36,7 +35,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,
scoped_ptr<content::PowerSaveBlocker> power_save_blocker,
const net::BoundNetLog& bound_net_log);
virtual ~DownloadFileImpl();

Expand Down Expand Up @@ -104,7 +103,7 @@ class CONTENT_EXPORT DownloadFileImpl : virtual public content::DownloadFile {
base::WeakPtrFactory<DownloadFileImpl> weak_factory_;

// RAII handle to keep the system from sleeping while we're downloading.
scoped_ptr<PowerSaveBlocker> power_save_blocker_;
scoped_ptr<content::PowerSaveBlocker> power_save_blocker_;

DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl);
};
Expand Down
7 changes: 4 additions & 3 deletions content/browser/download/download_file_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ DownloadFile* DownloadFileFactoryImpl::CreateFile(
return new DownloadFileImpl(
info, stream.Pass(), new DownloadRequestHandle(request_handle),
download_manager, calculate_hash,
scoped_ptr<PowerSaveBlocker>(
new PowerSaveBlocker(
PowerSaveBlocker::kPowerSaveBlockPreventSystemSleep)).Pass(),
scoped_ptr<content::PowerSaveBlocker>(
new content::PowerSaveBlocker(
content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
"Download in progress")).Pass(),
bound_net_log);
}

Expand Down
2 changes: 1 addition & 1 deletion content/browser/download/download_file_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class DownloadFileTest : public testing::Test {
scoped_ptr<content::ByteStreamReader>(input_stream_).Pass(),
new DownloadRequestHandle(),
download_manager_, calculate_hash,
scoped_ptr<PowerSaveBlocker>(NULL).Pass(),
scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(),
net::BoundNetLog()));

EXPECT_CALL(*input_stream_, Read(_, _))
Expand Down
8 changes: 4 additions & 4 deletions content/browser/download/download_manager_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ DownloadFileWithErrors::DownloadFileWithErrors(
new DownloadRequestHandle(),
manager,
calculate_hash,
scoped_ptr<PowerSaveBlocker>(NULL).Pass(),
scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(),
net::BoundNetLog()),
forced_error_(net::OK) {
}
Expand Down Expand Up @@ -563,7 +563,7 @@ TEST_F(DownloadManagerTest, MAYBE_StartDownload) {
stream_reader.Pass(),
new DownloadRequestHandle(),
download_manager_, false,
scoped_ptr<PowerSaveBlocker>(NULL).Pass(),
scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(),
net::BoundNetLog()));
AddDownloadToFileManager(info->download_id, download_file);
download_file->Initialize();
Expand Down Expand Up @@ -1129,7 +1129,7 @@ TEST_F(DownloadManagerTest, MAYBE_DownloadOverwriteTest) {
new DownloadFileImpl(info.get(), stream_output.Pass(),
new DownloadRequestHandle(),
download_manager_, false,
scoped_ptr<PowerSaveBlocker>(NULL).Pass(),
scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(),
net::BoundNetLog()));
download_file->Rename(cr_path);
// This creates the .temp version of the file.
Expand Down Expand Up @@ -1208,7 +1208,7 @@ TEST_F(DownloadManagerTest, MAYBE_DownloadRemoveTest) {
new DownloadFileImpl(info.get(), stream_output.Pass(),
new DownloadRequestHandle(),
download_manager_, false,
scoped_ptr<PowerSaveBlocker>(NULL).Pass(),
scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(),
net::BoundNetLog()));
download_file->Rename(cr_path);
// This creates the .temp version of the file.
Expand Down
56 changes: 6 additions & 50 deletions content/browser/power_save_blocker.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,11 @@
#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"

// A RAII-style class to block the system from entering low-power (sleep) mode.
class CONTENT_EXPORT PowerSaveBlocker {
public:
enum PowerSaveBlockerType {
kPowerSaveBlockPreventNone = -1,

// Prevent the system from going to sleep; allow display sleep.
kPowerSaveBlockPreventSystemSleep,

// Prevent the system or display from going to sleep.
kPowerSaveBlockPreventDisplaySleep,

// Count of the values; not valid as a parameter.
kPowerSaveBlockPreventStateCount
};

// Pass in the level of sleep prevention desired. kPowerSaveBlockPreventNone
// is not a valid option.
explicit PowerSaveBlocker(PowerSaveBlockerType type);
~PowerSaveBlocker();

private:
// Platform-specific function called when enable state is changed.
// Guaranteed to be called only from the UI thread.
static void ApplyBlock(PowerSaveBlockerType type);

// Called only from UI thread.
static void AdjustBlockCount(const std::vector<int>& deltas);

// Invokes AdjustBlockCount on the UI thread.
static void PostAdjustBlockCount(const std::vector<int>& deltas);

// Returns the highest-severity block type in use.
static PowerSaveBlockerType HighestBlockType();

PowerSaveBlockerType type_;

static int blocker_count_[];

DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker);
};

namespace content {

// NOT READY YET. PowerSaveBlocker above is soon to be replaced by this class,
// but it's not done yet so client code should use the one above for now.
// A RAII-style class to block the system from entering low-power (sleep) mode.
// This class is thread-safe; it may be constructed and deleted on any thread.
class CONTENT_EXPORT PowerSaveBlocker2 {
class CONTENT_EXPORT PowerSaveBlocker {
public:
enum PowerSaveBlockerType {
// Prevent the application from being suspended. On some platforms, apps may
Expand All @@ -81,8 +37,8 @@ class CONTENT_EXPORT PowerSaveBlocker2 {
// Pass in the type of power save blocking desired. If multiple types of
// blocking are desired, instantiate one PowerSaveBlocker for each type.
// |reason| may be provided to the underlying system APIs on some platforms.
PowerSaveBlocker2(PowerSaveBlockerType type, const std::string& reason);
~PowerSaveBlocker2();
PowerSaveBlocker(PowerSaveBlockerType type, const std::string& reason);
~PowerSaveBlocker();

private:
class Delegate;
Expand All @@ -91,15 +47,15 @@ class CONTENT_EXPORT PowerSaveBlocker2 {
// lifetime than the RAII container, or additional storage. This member is
// here for that purpose. If not used, just define the class as an empty
// RefCounted (or RefCountedThreadSafe) like so to make it compile:
// class PowerSaveBlocker2::Delegate
// : public base::RefCounted<PowerSaveBlocker2::Delegate> {
// class PowerSaveBlocker::Delegate
// : public base::RefCounted<PowerSaveBlocker::Delegate> {
// private:
// friend class base::RefCounted<Delegate>;
// ~Delegate() {}
// };
scoped_refptr<Delegate> delegate_;

DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker2);
DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker);
};

} // namespace content
Expand Down
20 changes: 17 additions & 3 deletions content/browser/power_save_blocker_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@

#include "base/logging.h"

// Called only from UI thread.
// static
void PowerSaveBlocker::ApplyBlock(PowerSaveBlockerType type) {
namespace content {

class PowerSaveBlocker::Delegate
: public base::RefCounted<PowerSaveBlocker::Delegate> {
private:
friend class base::RefCounted<Delegate>;
~Delegate() {}
};

PowerSaveBlocker::PowerSaveBlocker(PowerSaveBlockerType type,
const std::string& reason) {
// TODO(wangxianzhu): Implement it.
// This may be called on any thread.
NOTIMPLEMENTED();
}

PowerSaveBlocker::~PowerSaveBlocker() {
}

} // namespace content
64 changes: 0 additions & 64 deletions content/browser/power_save_blocker_common.cc

This file was deleted.

Loading

0 comments on commit 6b55aec

Please sign in to comment.