Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Unified Diff: chrome/browser/browsing_data/cache_test_util.h

Issue 2556363003: Refactor cache counting into a separate helper class (Closed)
Patch Set: extract cache_test_util and fixes Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/browsing_data/cache_test_util.h
diff --git a/chrome/browser/browsing_data/cache_test_util.h b/chrome/browser/browsing_data/cache_test_util.h
new file mode 100644
index 0000000000000000000000000000000000000000..d4e1d20babc5c1e779d88b3273d19e24fa9fc0d6
--- /dev/null
+++ b/chrome/browser/browsing_data/cache_test_util.h
@@ -0,0 +1,63 @@
+// Copyright 2016 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.
+
+#ifndef CHROME_BROWSER_BROWSING_DATA_CACHE_TEST_UTIL_H_
+#define CHROME_BROWSER_BROWSING_DATA_CACHE_TEST_UTIL_H_
+
+#include <set>
+#include <vector>
+#include "base/run_loop.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/storage_partition.h"
+#include "net/disk_cache/disk_cache.h"
+
+using content::BrowserThread;
+
+// A util class that can be used to create and retreive cache entries.
+class CacheTestUtil {
+ public:
+ explicit CacheTestUtil(content::StoragePartition* partition_);
+
+ ~CacheTestUtil();
+
+ void SetUpOnMainThread();
+ void TearDownOnMainThread();
+
+ void CreateCacheEntries(const std::set<std::string>& keys);
+
+ std::vector<std::string> GetEntryKeys();
+
+ content::StoragePartition* partition() { return partition_; }
+ disk_cache::Backend* backend() { return backend_; }
+
+ private:
+ base::Callback<void(int)> done_callback_;
+
+ content::StoragePartition* partition_;
+ disk_cache::Backend* backend_ = nullptr;
+ std::vector<disk_cache::Entry*> entries_;
+ std::unique_ptr<disk_cache::Backend::Iterator> iterator_;
+
+ disk_cache::Entry* current_entry_;
+ std::vector<std::string> remaining_keys_;
+
+ std::unique_ptr<base::RunLoop> run_loop_;
+ int remaining_tasks_;
+
+ void SetUpOnIOThread();
msramek 2016/12/20 01:02:59 Ordering: Methods before attributes (if you got in
dullweber 2016/12/21 10:29:19 Fixed here and in cache counter. I guess that was
+ void TearDownOnIOThread();
+
+ void CreateCacheEntriesOnIOThread(const std::set<std::string>& keys);
+
+ void GetEntryKeysOnIOThread();
+ void GetNextKey(int error);
+
+ void WaitForTasksOnIOThread();
+ void WaitForCompletion(int value);
+ void SetNumberOfWaitedTasks(int count);
+
+ void DoneCallback(int value);
+};
+
+#endif // CHROME_BROWSER_BROWSING_DATA_CACHE_TEST_UTIL_H_

Powered by Google App Engine
This is Rietveld 408576698