Commit b7310e3f authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

Revert "[PM] Add the non recording site data cache."

This reverts commit 759c81d7.

Reason for revert: Test failing on Linux TSan bot
https://ci.chromium.org/p/chromium/builders/ci/Linux%20TSan%20Tests/40627

Original change's description:
> [PM] Add the non recording site data cache.
> 
> Bug: 961336
> Change-Id: I91c40d8d6a603ab6ea7fdef31b2fb76a01ee28b1
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1659468
> Auto-Submit: Sébastien Marchand <sebmarchand@chromium.org>
> Reviewed-by: Chris Hamilton <chrisha@chromium.org>
> Commit-Queue: Sébastien Marchand <sebmarchand@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#673313}

TBR=chrisha@chromium.org,sebmarchand@chromium.org

Change-Id: I0a8b865c7ccdb17fb62b865e43925f5080972b77
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 961336
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1682248Reviewed-by: default avatarElla Ge <eirage@chromium.org>
Commit-Queue: Ella Ge <eirage@chromium.org>
Cr-Commit-Position: refs/heads/master@{#673448}
parent ff899e1c
...@@ -1070,8 +1070,6 @@ jumbo_split_static_library("browser") { ...@@ -1070,8 +1070,6 @@ jumbo_split_static_library("browser") {
"performance_manager/persistence/site_data/feature_usage.h", "performance_manager/persistence/site_data/feature_usage.h",
"performance_manager/persistence/site_data/leveldb_site_data_store.cc", "performance_manager/persistence/site_data/leveldb_site_data_store.cc",
"performance_manager/persistence/site_data/leveldb_site_data_store.h", "performance_manager/persistence/site_data/leveldb_site_data_store.h",
"performance_manager/persistence/site_data/non_recording_site_data_cache.cc",
"performance_manager/persistence/site_data/non_recording_site_data_cache.h",
"performance_manager/persistence/site_data/noop_site_data_writer.cc", "performance_manager/persistence/site_data/noop_site_data_writer.cc",
"performance_manager/persistence/site_data/noop_site_data_writer.h", "performance_manager/persistence/site_data/noop_site_data_writer.h",
"performance_manager/persistence/site_data/site_data_cache.h", "performance_manager/persistence/site_data/site_data_cache.h",
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <limits> #include <limits>
#include <string> #include <string>
#include "base/auto_reset.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/hash/md5.h" #include "base/hash/md5.h"
...@@ -21,15 +20,12 @@ ...@@ -21,15 +20,12 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "third_party/leveldatabase/env_chromium.h" #include "third_party/leveldatabase/env_chromium.h"
#include "third_party/leveldatabase/leveldb_chrome.h" #include "third_party/leveldatabase/leveldb_chrome.h"
#include "third_party/leveldatabase/src/include/leveldb/env.h"
#include "third_party/leveldatabase/src/include/leveldb/write_batch.h" #include "third_party/leveldatabase/src/include/leveldb/write_batch.h"
namespace performance_manager { namespace performance_manager {
namespace { namespace {
bool g_use_in_memory_db_for_testing = false;
// The name of the following histograms is the same as the one used in the // The name of the following histograms is the same as the one used in the
// //c/b/resource_coordinator version of this file. It's fine to keep the same // //c/b/resource_coordinator version of this file. It's fine to keep the same
// name as these 2 codepath will never be enabled at the same time. These // name as these 2 codepath will never be enabled at the same time. These
...@@ -174,10 +170,6 @@ class LevelDBSiteDataStore::AsyncHelper { ...@@ -174,10 +170,6 @@ class LevelDBSiteDataStore::AsyncHelper {
// Implementation for the OpenOrCreateDatabase function. // Implementation for the OpenOrCreateDatabase function.
OpeningType OpenOrCreateDatabaseImpl(); OpeningType OpenOrCreateDatabaseImpl();
// A levelDB environment that gets used for testing. This allows using an
// in-memory database when needed.
std::unique_ptr<leveldb::Env> env_for_testing_;
// The on disk location of the database. // The on disk location of the database.
const base::FilePath db_path_; const base::FilePath db_path_;
// The connection to the LevelDB database. // The connection to the LevelDB database.
...@@ -370,12 +362,6 @@ LevelDBSiteDataStore::AsyncHelper::OpenOrCreateDatabaseImpl() { ...@@ -370,12 +362,6 @@ LevelDBSiteDataStore::AsyncHelper::OpenOrCreateDatabaseImpl() {
leveldb_env::Options options; leveldb_env::Options options;
options.create_if_missing = true; options.create_if_missing = true;
if (g_use_in_memory_db_for_testing) {
env_for_testing_ = leveldb_chrome::NewMemEnv("LevelDBSiteDataStore");
options.env = env_for_testing_.get();
}
leveldb::Status status = leveldb::Status status =
leveldb_env::OpenDB(options, db_path_.AsUTF8Unsafe(), &db_); leveldb_env::OpenDB(options, db_path_.AsUTF8Unsafe(), &db_);
...@@ -490,11 +476,4 @@ leveldb::DB* LevelDBSiteDataStore::GetDBForTesting() { ...@@ -490,11 +476,4 @@ leveldb::DB* LevelDBSiteDataStore::GetDBForTesting() {
return async_helper_->GetDBForTesting(); return async_helper_->GetDBForTesting();
} }
// static
std::unique_ptr<base::AutoReset<bool>>
LevelDBSiteDataStore::UseInMemoryDBForTesting() {
return std::make_unique<base::AutoReset<bool>>(
&g_use_in_memory_db_for_testing, true);
}
} // namespace performance_manager } // namespace performance_manager
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#ifndef CHROME_BROWSER_PERFORMANCE_MANAGER_PERSISTENCE_SITE_DATA_LEVELDB_SITE_DATA_STORE_H_ #ifndef CHROME_BROWSER_PERFORMANCE_MANAGER_PERSISTENCE_SITE_DATA_LEVELDB_SITE_DATA_STORE_H_
#define CHROME_BROWSER_PERFORMANCE_MANAGER_PERSISTENCE_SITE_DATA_LEVELDB_SITE_DATA_STORE_H_ #define CHROME_BROWSER_PERFORMANCE_MANAGER_PERSISTENCE_SITE_DATA_LEVELDB_SITE_DATA_STORE_H_
#include "base/auto_reset.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
...@@ -52,10 +51,6 @@ class LevelDBSiteDataStore : public SiteDataStore { ...@@ -52,10 +51,6 @@ class LevelDBSiteDataStore : public SiteDataStore {
// thread safe. // thread safe.
leveldb::DB* GetDBForTesting(); leveldb::DB* GetDBForTesting();
// Make the new instances of this class use an in memory database rather than
// creating it on disk.
static std::unique_ptr<base::AutoReset<bool>> UseInMemoryDBForTesting();
static const size_t kDbVersion; static const size_t kDbVersion;
static const char kDbMetadataKey[]; static const char kDbMetadataKey[];
......
// Copyright 2019 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 "chrome/browser/performance_manager/persistence/site_data/non_recording_site_data_cache.h"
#include "base/memory/ptr_util.h"
#include "chrome/browser/performance_manager/persistence/site_data/noop_site_data_writer.h"
#include "chrome/browser/performance_manager/persistence/site_data/site_data_cache_factory.h"
#include "chrome/browser/performance_manager/persistence/site_data/site_data_reader.h"
#include "chrome/browser/performance_manager/persistence/site_data/site_data_writer.h"
namespace performance_manager {
NonRecordingSiteDataCache::NonRecordingSiteDataCache(
const std::string& browser_context_id,
SiteDataCacheInspector* data_cache_inspector,
SiteDataCache* data_cache_for_readers)
: data_cache_for_readers_(data_cache_for_readers),
data_cache_inspector_(data_cache_inspector),
browser_context_id_(browser_context_id) {
DCHECK(data_cache_for_readers_);
// Register the debug interface against the browser context.
SiteDataCacheFactory::GetInstance()->SetDataCacheInspectorForBrowserContext(
this, browser_context_id_);
}
NonRecordingSiteDataCache::~NonRecordingSiteDataCache() {
SiteDataCacheFactory::GetInstance()->SetDataCacheInspectorForBrowserContext(
nullptr, browser_context_id_);
}
std::unique_ptr<SiteDataReader> NonRecordingSiteDataCache::GetReaderForOrigin(
const url::Origin& origin) {
return data_cache_for_readers_->GetReaderForOrigin(origin);
}
std::unique_ptr<SiteDataWriter> NonRecordingSiteDataCache::GetWriterForOrigin(
const url::Origin& origin,
performance_manager::TabVisibility tab_visibility) {
// Return a fake data writer.
SiteDataWriter* writer = new NoopSiteDataWriter();
return base::WrapUnique(writer);
}
bool NonRecordingSiteDataCache::IsRecordingForTesting() {
return false;
}
const char* NonRecordingSiteDataCache::GetDataCacheName() {
return "NonRecordingSiteDataCache";
}
std::vector<url::Origin> NonRecordingSiteDataCache::GetAllInMemoryOrigins() {
if (!data_cache_inspector_)
return std::vector<url::Origin>();
return data_cache_inspector_->GetAllInMemoryOrigins();
}
void NonRecordingSiteDataCache::GetDataStoreSize(
DataStoreSizeCallback on_have_data) {
if (!data_cache_inspector_) {
std::move(on_have_data).Run(base::nullopt, base::nullopt);
return;
}
data_cache_inspector_->GetDataStoreSize(std::move(on_have_data));
}
bool NonRecordingSiteDataCache::GetDataForOrigin(
const url::Origin& origin,
bool* is_dirty,
std::unique_ptr<SiteDataProto>* data) {
if (!data_cache_inspector_)
return false;
return data_cache_inspector_->GetDataForOrigin(origin, is_dirty, data);
}
NonRecordingSiteDataCache* NonRecordingSiteDataCache::GetDataCache() {
return this;
}
} // namespace performance_manager
// Copyright 2019 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_PERFORMANCE_MANAGER_PERSISTENCE_SITE_DATA_NON_RECORDING_SITE_DATA_CACHE_H_
#define CHROME_BROWSER_PERFORMANCE_MANAGER_PERSISTENCE_SITE_DATA_NON_RECORDING_SITE_DATA_CACHE_H_
#include <memory>
#include <string>
#include <vector>
#include "base/macros.h"
#include "chrome/browser/performance_manager/persistence/site_data/site_data_cache.h"
#include "chrome/browser/performance_manager/persistence/site_data/site_data_cache_inspector.h"
namespace performance_manager {
// Implementation of a SiteDataCache that ensures that no data gets persisted.
//
// This class should be used for off the record profiles.
class NonRecordingSiteDataCache : public SiteDataCache,
public SiteDataCacheInspector {
public:
NonRecordingSiteDataCache(const std::string& browser_context_id,
SiteDataCacheInspector* data_cache_inspector,
SiteDataCache* data_cache_for_readers);
~NonRecordingSiteDataCache() override;
// SiteDataCache:
std::unique_ptr<SiteDataReader> GetReaderForOrigin(
const url::Origin& origin) override;
std::unique_ptr<SiteDataWriter> GetWriterForOrigin(
const url::Origin& origin,
performance_manager::TabVisibility tab_visibility) override;
bool IsRecordingForTesting() override;
// SiteDataCacheInspector:
const char* GetDataCacheName() override;
std::vector<url::Origin> GetAllInMemoryOrigins() override;
void GetDataStoreSize(DataStoreSizeCallback on_have_data) override;
bool GetDataForOrigin(const url::Origin& origin,
bool* is_dirty,
std::unique_ptr<SiteDataProto>* data) override;
NonRecordingSiteDataCache* GetDataCache() override;
private:
// The data cache to use to create the readers served by this data store. E.g.
// during an incognito session it should point to the data cache used by the
// parent session.
SiteDataCache* data_cache_for_readers_;
// The inspector implementation this instance delegates to.
SiteDataCacheInspector* data_cache_inspector_;
// The ID of the browser context this data store is associated with.
const std::string browser_context_id_;
DISALLOW_COPY_AND_ASSIGN(NonRecordingSiteDataCache);
};
} // namespace performance_manager
#endif // CHROME_BROWSER_PERFORMANCE_MANAGER_PERSISTENCE_SITE_DATA_NON_RECORDING_SITE_DATA_CACHE_H_
// Copyright 2019 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 "chrome/browser/performance_manager/persistence/site_data/non_recording_site_data_cache.h"
#include "chrome/browser/performance_manager/persistence/site_data/leveldb_site_data_store.h"
#include "chrome/browser/performance_manager/persistence/site_data/site_data_cache.h"
#include "chrome/browser/performance_manager/persistence/site_data/site_data_cache_factory.h"
#include "chrome/browser/performance_manager/persistence/site_data/site_data_cache_impl.h"
#include "chrome/browser/performance_manager/persistence/site_data/site_data_cache_inspector.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace performance_manager {
namespace {
class NonRecordingSiteDataCacheTest : public testing::Test {
public:
NonRecordingSiteDataCacheTest()
: use_in_memory_db_for_testing_(
LevelDBSiteDataStore::UseInMemoryDBForTesting()),
factory_(SiteDataCacheFactory::CreateForTesting(
test_browser_thread_bundle_.GetMainThreadTaskRunner())),
off_the_record_profile_(parent_profile_.GetOffTheRecordProfile()) {}
~NonRecordingSiteDataCacheTest() override { factory_.reset(); }
void SetUp() override {
recording_data_cache_ = base::WrapUnique(new SiteDataCacheImpl(
parent_profile_.UniqueId(), parent_profile_.GetPath()));
non_recording_data_cache_ = std::make_unique<NonRecordingSiteDataCache>(
off_the_record_profile_->UniqueId(), recording_data_cache_.get(),
recording_data_cache_.get());
}
protected:
const url::Origin kTestOrigin =
url::Origin::Create(GURL("http://www.foo.com"));
content::TestBrowserThreadBundle test_browser_thread_bundle_;
// Ensure that the database used by the data store owned by
// |recording_data_cache_| gets created in memory. This avoid having to wait
// for it to be fully closed before destroying |parent_profile_|.
std::unique_ptr<base::AutoReset<bool>> use_in_memory_db_for_testing_;
// The data cache factory that will be used by the caches tested here.
std::unique_ptr<SiteDataCacheFactory, base::OnTaskRunnerDeleter> factory_;
// The on the record profile.
TestingProfile parent_profile_;
// An off the record profile owned by |parent_profile|.
Profile* off_the_record_profile_;
std::unique_ptr<SiteDataCacheImpl> recording_data_cache_;
std::unique_ptr<NonRecordingSiteDataCache> non_recording_data_cache_;
};
} // namespace
TEST_F(NonRecordingSiteDataCacheTest, EndToEnd) {
// Ensures that the observation made via a writer created by the non
// recording data cache aren't recorded.
auto reader = non_recording_data_cache_->GetReaderForOrigin(kTestOrigin);
EXPECT_TRUE(reader);
auto fake_writer = non_recording_data_cache_->GetWriterForOrigin(
kTestOrigin, performance_manager::TabVisibility::kBackground);
EXPECT_TRUE(fake_writer);
auto real_writer = recording_data_cache_->GetWriterForOrigin(
kTestOrigin, performance_manager::TabVisibility::kBackground);
EXPECT_TRUE(real_writer);
EXPECT_EQ(performance_manager::SiteFeatureUsage::kSiteFeatureUsageUnknown,
reader->UpdatesTitleInBackground());
fake_writer->NotifySiteLoaded();
fake_writer->NotifyUpdatesTitleInBackground();
EXPECT_EQ(performance_manager::SiteFeatureUsage::kSiteFeatureUsageUnknown,
reader->UpdatesTitleInBackground());
real_writer->NotifySiteLoaded();
real_writer->NotifyUpdatesTitleInBackground();
EXPECT_EQ(performance_manager::SiteFeatureUsage::kSiteFeatureInUse,
reader->UpdatesTitleInBackground());
// These unload events shouldn't be registered, make sure that they aren't by
// unloading the site more time than it has been loaded.
fake_writer->NotifySiteUnloaded();
fake_writer->NotifySiteUnloaded();
real_writer->NotifySiteUnloaded();
}
TEST_F(NonRecordingSiteDataCacheTest, InspectorWorks) {
// Make sure the inspector interface was registered at construction.
SiteDataCacheInspector* inspector = factory_->GetInspectorForBrowserContext(
off_the_record_profile_->UniqueId());
EXPECT_NE(nullptr, inspector);
EXPECT_EQ(non_recording_data_cache_.get(), inspector);
EXPECT_STREQ("NonRecordingSiteDataCache", inspector->GetDataCacheName());
// We expect an empty data cache at the outset.
EXPECT_EQ(0U, inspector->GetAllInMemoryOrigins().size());
std::unique_ptr<SiteDataProto> data;
bool is_dirty = false;
EXPECT_FALSE(inspector->GetDataForOrigin(kTestOrigin, &is_dirty, &data));
EXPECT_FALSE(is_dirty);
EXPECT_EQ(nullptr, data.get());
{
// Add an entry through the writing data cache, see that it's reflected in
// the inspector interface.
auto writer = recording_data_cache_->GetWriterForOrigin(
kTestOrigin, performance_manager::TabVisibility::kBackground);
EXPECT_EQ(1U, inspector->GetAllInMemoryOrigins().size());
EXPECT_TRUE(inspector->GetDataForOrigin(kTestOrigin, &is_dirty, &data));
EXPECT_FALSE(is_dirty);
ASSERT_NE(nullptr, data.get());
// Touch the underlying data, see that the dirty bit updates.
writer->NotifySiteLoaded();
EXPECT_TRUE(inspector->GetDataForOrigin(kTestOrigin, &is_dirty, &data));
}
// Make sure the interface is unregistered from the browser context on
// destruction.
non_recording_data_cache_.reset();
EXPECT_EQ(nullptr, factory_->GetInspectorForBrowserContext(
off_the_record_profile_->UniqueId()));
}
} // namespace performance_manager
...@@ -30,9 +30,8 @@ class NoopSiteDataWriter : public SiteDataWriter { ...@@ -30,9 +30,8 @@ class NoopSiteDataWriter : public SiteDataWriter {
uint64_t private_footprint_kb_estimate) override; uint64_t private_footprint_kb_estimate) override;
private: private:
friend class NonRecordingSiteDataCache; // Private constructor, these objects are meant to be created by a noop site
// Private constructor, these objects are meant to be created by a // data store.
// NonRecordingSiteDataCache.
NoopSiteDataWriter(); NoopSiteDataWriter();
DISALLOW_COPY_AND_ASSIGN(NoopSiteDataWriter); DISALLOW_COPY_AND_ASSIGN(NoopSiteDataWriter);
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/task_runner_util.h" #include "base/task_runner_util.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "chrome/browser/performance_manager/performance_manager.h" #include "chrome/browser/performance_manager/performance_manager.h"
#include "chrome/browser/performance_manager/persistence/site_data/non_recording_site_data_cache.h"
#include "chrome/browser/performance_manager/persistence/site_data/site_data_cache_impl.h" #include "chrome/browser/performance_manager/persistence/site_data/site_data_cache_impl.h"
#include "chrome/browser/performance_manager/persistence/site_data/site_data_cache_inspector.h" #include "chrome/browser/performance_manager/persistence/site_data/site_data_cache_inspector.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
...@@ -30,6 +30,7 @@ SiteDataCacheFactory::SiteDataCacheFactory( ...@@ -30,6 +30,7 @@ SiteDataCacheFactory::SiteDataCacheFactory(
const scoped_refptr<base::SequencedTaskRunner> task_runner) const scoped_refptr<base::SequencedTaskRunner> task_runner)
: task_runner_(task_runner) { : task_runner_(task_runner) {
DETACH_FROM_SEQUENCE(sequence_checker_); DETACH_FROM_SEQUENCE(sequence_checker_);
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
} }
SiteDataCacheFactory::~SiteDataCacheFactory() { SiteDataCacheFactory::~SiteDataCacheFactory() {
...@@ -67,24 +68,19 @@ SiteDataCacheFactory::CreateForTesting( ...@@ -67,24 +68,19 @@ SiteDataCacheFactory::CreateForTesting(
// static // static
void SiteDataCacheFactory::OnBrowserContextCreatedOnUIThread( void SiteDataCacheFactory::OnBrowserContextCreatedOnUIThread(
SiteDataCacheFactory* factory, SiteDataCacheFactory* factory,
content::BrowserContext* browser_context, content::BrowserContext* browser_context) {
content::BrowserContext* parent_context) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(factory); DCHECK(factory);
// As |factory| will be deleted on its task runner it's safe to pass the raw // As |factory| will be deleted on its task runner it's safe to pass the raw
// pointer to BindOnce, it's guaranteed that this task will run before the // pointer to BindOnce, it's guaranteed that this task will run before the
// factory. // factory.
base::Optional<std::string> parent_context_id;
if (parent_context) {
DCHECK(browser_context->IsOffTheRecord());
parent_context_id = parent_context->UniqueId();
}
factory->task_runner_->PostTask( factory->task_runner_->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&SiteDataCacheFactory::OnBrowserContextCreated, base::BindOnce(&SiteDataCacheFactory::OnBrowserContextCreated,
base::Unretained(factory), browser_context->UniqueId(), base::Unretained(factory), browser_context->UniqueId(),
browser_context->GetPath(), parent_context_id)); browser_context->GetPath(),
browser_context->IsOffTheRecord()));
} }
// static // static
...@@ -101,28 +97,28 @@ void SiteDataCacheFactory::OnBrowserContextDestroyedOnUIThread( ...@@ -101,28 +97,28 @@ void SiteDataCacheFactory::OnBrowserContextDestroyedOnUIThread(
base::Unretained(factory), browser_context->UniqueId())); base::Unretained(factory), browser_context->UniqueId()));
} }
// static
SiteDataCache* SiteDataCacheFactory::GetDataCacheForBrowserContext( SiteDataCache* SiteDataCacheFactory::GetDataCacheForBrowserContext(
const std::string& browser_context_id) const { const std::string& browser_context_id) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto it = data_cache_map_.find(browser_context_id); auto it = data_cache_map_.find(browser_context_id);
if (it != data_cache_map_.end()) if (it != data_cache_map_.end())
return it->second.get(); return it->second.get();
return nullptr; return nullptr;
} }
// static
SiteDataCacheInspector* SiteDataCacheFactory::GetInspectorForBrowserContext( SiteDataCacheInspector* SiteDataCacheFactory::GetInspectorForBrowserContext(
const std::string& browser_context_id) const { const std::string& browser_context_id) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto it = data_cache_inspector_map_.find(browser_context_id); auto it = data_cache_inspector_map_.find(browser_context_id);
if (it != data_cache_inspector_map_.end()) if (it != data_cache_inspector_map_.end())
return it->second; return it->second;
return nullptr; return nullptr;
} }
// static
void SiteDataCacheFactory::SetDataCacheInspectorForBrowserContext( void SiteDataCacheFactory::SetDataCacheInspectorForBrowserContext(
SiteDataCacheInspector* inspector, SiteDataCacheInspector* inspector,
const std::string& browser_context_id) { const std::string& browser_context_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (inspector) { if (inspector) {
DCHECK_EQ(nullptr, GetInspectorForBrowserContext(browser_context_id)); DCHECK_EQ(nullptr, GetInspectorForBrowserContext(browser_context_id));
data_cache_inspector_map_.emplace( data_cache_inspector_map_.emplace(
...@@ -136,23 +132,14 @@ void SiteDataCacheFactory::SetDataCacheInspectorForBrowserContext( ...@@ -136,23 +132,14 @@ void SiteDataCacheFactory::SetDataCacheInspectorForBrowserContext(
void SiteDataCacheFactory::OnBrowserContextCreated( void SiteDataCacheFactory::OnBrowserContextCreated(
const std::string& browser_context_id, const std::string& browser_context_id,
const base::FilePath& context_path, const base::FilePath& context_path,
base::Optional<std::string> parent_context_id) { bool context_is_off_the_record) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!base::Contains(data_cache_map_, browser_context_id)); DCHECK(!base::Contains(data_cache_map_, browser_context_id));
if (parent_context_id) { if (context_is_off_the_record) {
SiteDataCacheInspector* parent_debug = // TODO(sebmarchand): Add support for off-the-record contexts.
GetInspectorForBrowserContext(parent_context_id.value()); NOTREACHED();
DCHECK(parent_debug);
DCHECK(base::Contains(data_cache_map_, parent_context_id.value()));
SiteDataCache* data_cache_for_readers =
data_cache_map_[parent_context_id.value()].get();
DCHECK(data_cache_for_readers);
data_cache_map_.emplace(std::make_pair(
std::move(browser_context_id),
std::make_unique<NonRecordingSiteDataCache>(
browser_context_id, parent_debug, data_cache_for_readers)));
} else { } else {
data_cache_map_.emplace(std::make_pair( data_cache_map_.emplace(std::make_pair(
std::move(browser_context_id), std::move(browser_context_id),
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/location.h" #include "base/location.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "chrome/browser/performance_manager/persistence/site_data/site_data_cache.h" #include "chrome/browser/performance_manager/persistence/site_data/site_data_cache.h"
...@@ -58,14 +57,9 @@ class SiteDataCacheFactory { ...@@ -58,14 +57,9 @@ class SiteDataCacheFactory {
// destroyed. They should be called from the UI thread, a task will then be // destroyed. They should be called from the UI thread, a task will then be
// posted to the task_runner owned by |factory| to create the data store // posted to the task_runner owned by |factory| to create the data store
// associated with this browser context. // associated with this browser context.
//
// If this browser context is inheriting from a parent context (e.g. if it's
// off the record) then this parent context should be specified via
// |parent_context|.
static void OnBrowserContextCreatedOnUIThread( static void OnBrowserContextCreatedOnUIThread(
SiteDataCacheFactory* factory, SiteDataCacheFactory* factory,
content::BrowserContext* browser_context, content::BrowserContext* browser_context);
content::BrowserContext* parent_context);
static void OnBrowserContextDestroyedOnUIThread( static void OnBrowserContextDestroyedOnUIThread(
SiteDataCacheFactory* factory, SiteDataCacheFactory* factory,
content::BrowserContext* browser_context); content::BrowserContext* browser_context);
...@@ -104,7 +98,7 @@ class SiteDataCacheFactory { ...@@ -104,7 +98,7 @@ class SiteDataCacheFactory {
// that runs on this object's task runner. // that runs on this object's task runner.
void OnBrowserContextCreated(const std::string& browser_context_id, void OnBrowserContextCreated(const std::string& browser_context_id,
const base::FilePath& context_path, const base::FilePath& context_path,
base::Optional<std::string> parent_context_id); bool context_is_off_the_record);
void OnBrowserContextDestroyed(const std::string& browser_context_id); void OnBrowserContextDestroyed(const std::string& browser_context_id);
// The task runner on which this object lives, this is expected to be the // The task runner on which this object lives, this is expected to be the
......
...@@ -41,7 +41,7 @@ class SiteDataCacheFactoryTest : public ::testing::Test { ...@@ -41,7 +41,7 @@ class SiteDataCacheFactoryTest : public ::testing::Test {
TEST_F(SiteDataCacheFactoryTest, EndToEnd) { TEST_F(SiteDataCacheFactoryTest, EndToEnd) {
SiteDataCacheFactory::OnBrowserContextCreatedOnUIThread(factory_.get(), SiteDataCacheFactory::OnBrowserContextCreatedOnUIThread(factory_.get(),
&profile_, nullptr); &profile_);
base::RunLoop run_loop; base::RunLoop run_loop;
task_runner_->PostTask( task_runner_->PostTask(
......
...@@ -2937,7 +2937,6 @@ test("unit_tests") { ...@@ -2937,7 +2937,6 @@ test("unit_tests") {
"../browser/performance_manager/performance_manager_unittest.cc", "../browser/performance_manager/performance_manager_unittest.cc",
"../browser/performance_manager/persistence/site_data/exponential_moving_average_unittest.cc", "../browser/performance_manager/persistence/site_data/exponential_moving_average_unittest.cc",
"../browser/performance_manager/persistence/site_data/leveldb_site_data_store_unittest.cc", "../browser/performance_manager/persistence/site_data/leveldb_site_data_store_unittest.cc",
"../browser/performance_manager/persistence/site_data/non_recording_site_data_cache_unittest.cc",
"../browser/performance_manager/persistence/site_data/site_data_cache_factory_unittest.cc", "../browser/performance_manager/persistence/site_data/site_data_cache_factory_unittest.cc",
"../browser/performance_manager/persistence/site_data/site_data_cache_impl_unittest.cc", "../browser/performance_manager/persistence/site_data/site_data_cache_impl_unittest.cc",
"../browser/performance_manager/persistence/site_data/site_data_impl_unittest.cc", "../browser/performance_manager/persistence/site_data/site_data_impl_unittest.cc",
......
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