forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OnPurgeMemory() to MemoryCoordinatorClient
Before this CL, MemoryCoordinatorClient has only one callback called OnMemoryStateChange(). Clients try to free up memory when state change happens (e.g. NORMAL -> SUSPENDED). This may not be a good strategy on some platforms because we may touch compressed pages (see [1] for details). This CL add another callback called OnPurgeMemory() to separate logic for purging existing memory from memory state changes. This way we can build flexible strategies for handling memory pressure. [1] https://groups.google.com/a/chromium.org/forum/?utm_medium=email&utm_source=footer#!msg/project-trim/s96xSirL2Hs/18uq1zfHEgAJ BUG=684287 Review-Url: https://codereview.chromium.org/2655083003 Cr-Commit-Position: refs/heads/master@{#446951}
- Loading branch information
Showing
5 changed files
with
96 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
base/memory/memory_coordinator_client_registry_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2017 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. | ||
|
||
#include "base/memory/memory_coordinator_client_registry.h" | ||
|
||
#include "base/message_loop/message_loop.h" | ||
#include "base/run_loop.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace base { | ||
|
||
namespace { | ||
|
||
class TestMemoryCoordinatorClient : public MemoryCoordinatorClient { | ||
public: | ||
void OnMemoryStateChange(MemoryState state) override { state_ = state; } | ||
|
||
void OnPurgeMemory() override { ++purge_count_; } | ||
|
||
MemoryState state() const { return state_; } | ||
size_t purge_count() const { return purge_count_; } | ||
|
||
private: | ||
MemoryState state_ = MemoryState::UNKNOWN; | ||
size_t purge_count_ = 0; | ||
}; | ||
|
||
void RunUntilIdle() { | ||
base::RunLoop loop; | ||
loop.RunUntilIdle(); | ||
} | ||
|
||
TEST(MemoryCoordinatorClientRegistryTest, NotifyStateChange) { | ||
MessageLoop loop; | ||
auto* registry = MemoryCoordinatorClientRegistry::GetInstance(); | ||
TestMemoryCoordinatorClient client; | ||
registry->Register(&client); | ||
registry->Notify(MemoryState::THROTTLED); | ||
RunUntilIdle(); | ||
ASSERT_EQ(MemoryState::THROTTLED, client.state()); | ||
registry->Unregister(&client); | ||
} | ||
|
||
TEST(MemoryCoordinatorClientRegistryTest, PurgeMemory) { | ||
MessageLoop loop; | ||
auto* registry = MemoryCoordinatorClientRegistry::GetInstance(); | ||
TestMemoryCoordinatorClient client; | ||
registry->Register(&client); | ||
registry->PurgeMemory(); | ||
RunUntilIdle(); | ||
ASSERT_EQ(1u, client.purge_count()); | ||
registry->Unregister(&client); | ||
} | ||
|
||
} // namespace | ||
|
||
} // namespace base |