Commit bb20488b authored by Joshua Bell's avatar Joshua Bell Committed by Commit Bot

BindOnce update for StoragePartition/ShaderDiskCache

Bug: 714018
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I2cb2aba8e1f8460f0dedc25fdeba1df702e845fb
Reviewed-on: https://chromium-review.googlesource.com/1244369Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595570}
parent ef629f77
......@@ -124,22 +124,24 @@ void OnQuotaManagedOriginDeleted(const url::Origin& origin,
CheckQuotaManagedDataDeletionStatus(deletion_task_count, std::move(callback));
}
void ClearedShaderCache(const base::Closure& callback) {
void ClearedShaderCache(base::OnceClosure callback) {
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI},
base::BindOnce(&ClearedShaderCache, callback));
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(&ClearedShaderCache, std::move(callback)));
return;
}
callback.Run();
std::move(callback).Run();
}
void ClearShaderCacheOnIOThread(const base::FilePath& path,
const base::Time begin,
const base::Time end,
const base::Closure& callback) {
base::OnceClosure callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
GetShaderCacheFactorySingleton()->ClearByPath(
path, begin, end, base::Bind(&ClearedShaderCache, callback));
path, begin, end,
base::BindOnce(&ClearedShaderCache, std::move(callback)));
}
void OnLocalStorageUsageInfo(
......
......@@ -122,7 +122,7 @@ class ShaderClearHelper : public base::ThreadChecker {
const base::FilePath& path,
const base::Time& delete_begin,
const base::Time& delete_end,
const base::Closure& callback);
base::OnceClosure callback);
~ShaderClearHelper();
void Clear();
......@@ -138,7 +138,7 @@ class ShaderClearHelper : public base::ThreadChecker {
base::FilePath path_;
base::Time delete_begin_;
base::Time delete_end_;
base::Closure callback_;
base::OnceClosure callback_;
base::WeakPtrFactory<ShaderClearHelper> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ShaderClearHelper);
......@@ -390,14 +390,14 @@ ShaderClearHelper::ShaderClearHelper(ShaderCacheFactory* factory,
const base::FilePath& path,
const base::Time& delete_begin,
const base::Time& delete_end,
const base::Closure& callback)
base::OnceClosure callback)
: factory_(factory),
cache_(std::move(cache)),
op_type_(VERIFY_CACHE_SETUP),
path_(path),
delete_begin_(delete_begin),
delete_end_(delete_end),
callback_(callback),
callback_(std::move(callback)),
weak_ptr_factory_(this) {}
ShaderClearHelper::~ShaderClearHelper() {
......@@ -426,7 +426,7 @@ void ShaderClearHelper::DoClearShaderCache(int rv) {
op_type_ = TERMINATE;
break;
case TERMINATE:
callback_.Run();
std::move(callback_).Run();
// Calling CacheCleared() destroys |this|.
factory_->CacheCleared(path_);
rv = net::ERR_IO_PENDING; // Break the loop.
......@@ -487,12 +487,13 @@ void ShaderCacheFactory::RemoveFromCache(const base::FilePath& key) {
void ShaderCacheFactory::ClearByPath(const base::FilePath& path,
const base::Time& delete_begin,
const base::Time& delete_end,
const base::Closure& callback) {
base::OnceClosure callback) {
DCHECK(CalledOnValidThread());
DCHECK(!callback.is_null());
auto helper = std::make_unique<ShaderClearHelper>(
this, GetByPath(path), path, delete_begin, delete_end, callback);
auto helper = std::make_unique<ShaderClearHelper>(this, GetByPath(path), path,
delete_begin, delete_end,
std::move(callback));
// We could receive requests to clear the same path with different
// begin/end times. So, we keep a list of requests. If we haven't seen this
......@@ -517,12 +518,13 @@ void ShaderCacheFactory::ClearByPath(const base::FilePath& path,
void ShaderCacheFactory::ClearByClientId(int32_t client_id,
const base::Time& delete_begin,
const base::Time& delete_end,
const base::Closure& callback) {
base::OnceClosure callback) {
DCHECK(CalledOnValidThread());
ClientIdToPathMap::iterator iter = client_id_to_path_map_.find(client_id);
if (iter == client_id_to_path_map_.end())
return;
return ClearByPath(iter->second, delete_begin, delete_end, callback);
return ClearByPath(iter->second, delete_begin, delete_end,
std::move(callback));
}
void ShaderCacheFactory::CacheCleared(const base::FilePath& path) {
......
......@@ -31,7 +31,7 @@ class ShaderClearHelper;
class ShaderDiskCache : public base::RefCounted<ShaderDiskCache> {
public:
using ShaderLoadedCallback =
base::Callback<void(const std::string&, const std::string&)>;
base::RepeatingCallback<void(const std::string&, const std::string&)>;
void set_shader_loaded_callback(const ShaderLoadedCallback& callback) {
shader_loaded_callback_ = callback;
......@@ -118,14 +118,14 @@ class ShaderCacheFactory : public base::ThreadChecker {
void ClearByPath(const base::FilePath& path,
const base::Time& begin_time,
const base::Time& end_time,
const base::Closure& callback);
base::OnceClosure callback);
// Same as ClearByPath, but looks up the cache by |client_id|. The |callback|
// will be executed when the clear is complete.
void ClearByClientId(int32_t client_id,
const base::Time& begin_time,
const base::Time& end_time,
const base::Closure& callback);
base::OnceClosure callback);
// Retrieve the shader disk cache for the provided |client_id|.
scoped_refptr<ShaderDiskCache> Get(int32_t client_id);
......
......@@ -5,6 +5,7 @@
#include "gpu/ipc/host/shader_disk_cache.h"
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
#include "base/test/bind_test_util.h"
#include "base/test/scoped_task_environment.h"
#include "net/base/test_completion_callback.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -15,6 +16,8 @@ namespace {
const int kDefaultClientId = 42;
const char kCacheKey[] = "key";
const char kCacheValue[] = "cached value";
const char kCacheKey2[] = "key2";
const char kCacheValue2[] = "cached value2";
} // namespace
......@@ -102,4 +105,39 @@ TEST_F(ShaderDiskCacheTest, SafeToDeleteCacheMidEntryOpen) {
ASSERT_EQ(net::OK, available_cb2.GetResult(rv2));
};
TEST_F(ShaderDiskCacheTest, MultipleLoaderCallbacks) {
InitCache();
// Create a cache and wait for it to open.
scoped_refptr<ShaderDiskCache> cache = factory()->Get(kDefaultClientId);
ASSERT_TRUE(cache.get() != nullptr);
net::TestCompletionCallback available_cb;
int rv = cache->SetAvailableCallback(available_cb.callback());
ASSERT_EQ(net::OK, available_cb.GetResult(rv));
EXPECT_EQ(0, cache->Size());
// Write two entries, wait for them to complete.
const int32_t count = 2;
cache->Cache(kCacheKey, kCacheValue);
cache->Cache(kCacheKey2, kCacheValue2);
net::TestCompletionCallback complete_cb;
rv = cache->SetCacheCompleteCallback(complete_cb.callback());
ASSERT_EQ(net::OK, complete_cb.GetResult(rv));
EXPECT_EQ(count, cache->Size());
// Close, re-open, and verify that two entries were loaded.
cache = nullptr;
cache = factory()->Get(kDefaultClientId);
ASSERT_TRUE(cache.get() != nullptr);
int loaded_calls = 0;
cache->set_shader_loaded_callback(base::BindLambdaForTesting(
[&loaded_calls](const std::string& key, const std::string& value) {
++loaded_calls;
}));
net::TestCompletionCallback available_cb2;
int rv2 = cache->SetAvailableCallback(available_cb2.callback());
ASSERT_EQ(net::OK, available_cb2.GetResult(rv2));
EXPECT_EQ(count, loaded_calls);
};
} // namespace gpu
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment