Commit e9fdf22e authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Commit Bot

Add the SiteCharacteristicsDataStore class.

See the (@google.com) design doc: https://docs.google.com/document/d/1MgyIJ096pQChpbqQIqXHTZ0NYRXAOxcBtAq2lJplOpE/edit?usp=sharing

Bug: 773382
Change-Id: Ieff80131e2df38867c059047467abefdd9fe06a7
Reviewed-on: https://chromium-review.googlesource.com/1011253
Commit-Queue: Sébastien Marchand <sebmarchand@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552718}
parent 1646576e
......@@ -2617,8 +2617,11 @@ jumbo_split_static_library("browser") {
"resource_coordinator/local_site_characteristics_data_impl.h",
"resource_coordinator/local_site_characteristics_data_reader.cc",
"resource_coordinator/local_site_characteristics_data_reader.h",
"resource_coordinator/local_site_characteristics_data_store.cc",
"resource_coordinator/local_site_characteristics_data_store.h",
"resource_coordinator/local_site_characteristics_feature_usage.h",
"resource_coordinator/site_characteristics_data_reader.h",
"resource_coordinator/site_characteristics_data_store.h",
"resource_coordinator/tab_activity_watcher.cc",
"resource_coordinator/tab_activity_watcher.h",
"resource_coordinator/tab_lifecycle_observer.h",
......
......@@ -39,17 +39,6 @@ const int64_t
LocalSiteCharacteristicsDataImpl::TimeDeltaToInternalRepresentation(
base::TimeDelta());
LocalSiteCharacteristicsDataImpl::LocalSiteCharacteristicsDataImpl(
const std::string& origin_str)
: origin_str_(origin_str), active_webcontents_count_(0U) {
// Initialize the features element with the default value, this is required
// because some fields might otherwise never be initialized.
for (auto* iter : GetAllFeaturesFromProto(&site_characteristics_))
InitSiteCharacteristicsFeatureProtoWithDefaultValues(iter);
site_characteristics_.set_last_loaded(kZeroIntervalInternalRepresentation);
}
void LocalSiteCharacteristicsDataImpl::NotifySiteLoaded() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Update the last loaded time when this origin gets loaded for the first
......@@ -128,6 +117,21 @@ void LocalSiteCharacteristicsDataImpl::NotifyUsesNotificationsInBackground() {
site_characteristics_.mutable_uses_notifications_in_background());
}
LocalSiteCharacteristicsDataImpl::LocalSiteCharacteristicsDataImpl(
const std::string& origin_str,
OnDestroyDelegate* delegate)
: origin_str_(origin_str),
active_webcontents_count_(0U),
delegate_(delegate) {
DCHECK_NE(nullptr, delegate_);
// Initialize the feature elements with the default value, this is required
// because some fields might otherwise never be initialized.
for (auto* iter : GetAllFeaturesFromProto(&site_characteristics_))
InitSiteCharacteristicsFeatureProtoWithDefaultValues(iter);
site_characteristics_.set_last_loaded(kZeroIntervalInternalRepresentation);
}
base::TimeDelta LocalSiteCharacteristicsDataImpl::FeatureObservationDuration(
const SiteCharacteristicsFeatureProto& feature_proto) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......@@ -156,6 +160,9 @@ LocalSiteCharacteristicsDataImpl::~LocalSiteCharacteristicsDataImpl() {
// object.
// TODO(sebmarchand): Check if this is a valid assumption.
DCHECK_EQ(0U, active_webcontents_count_);
DCHECK_NE(nullptr, delegate_);
delegate_->OnLocalSiteCharacteristicsDataImplDestroyed(this);
}
// static:
......
......@@ -15,23 +15,41 @@
#include "chrome/browser/resource_coordinator/site_characteristics.pb.h"
namespace resource_coordinator {
class LocalSiteCharacteristicsDataStore;
class LocalSiteCharacteristicsDataReaderTest;
namespace internal {
// Tracks observations for a given site. This class shouldn't be used
// directly, it's meant to be used internally by the local site heuristic
// database.
// Internal class used to read/write site characteristics. This is a wrapper
// class around a SiteCharacteristicsProto object and offers various to query
// and/or modify it. This class shouldn't be used directly, instead it should be
// created by a LocalSiteCharacteristicsDataStore that will serve reader and
// writer objects.
//
// Reader and writers objects that are interested in reading/writing information
// about the same origin will share a unique ref counted instance of this
// object, because of this all the operations done on these objects should be
// done on the same thread, this class isn't thread safe.
class LocalSiteCharacteristicsDataImpl
: public base::RefCounted<LocalSiteCharacteristicsDataImpl> {
public:
explicit LocalSiteCharacteristicsDataImpl(const std::string& origin_str);
// Interface that should be implemented in order to receive notifications when
// this object is about to get destroyed.
class OnDestroyDelegate {
public:
// Called when this object is about to get destroyed.
virtual void OnLocalSiteCharacteristicsDataImplDestroyed(
LocalSiteCharacteristicsDataImpl* impl) = 0;
};
// Must be called when a load event is received for this site, this can be
// invoked several time if instances of this class are shared between
// invoked several times if instances of this class are shared between
// multiple tabs.
void NotifySiteLoaded();
// Must be called when an unload event is received for this site, this can be
// invoked several time if instances of this class are shared between
// invoked several times if instances of this class are shared between
// multiple tabs.
void NotifySiteUnloaded();
......@@ -54,6 +72,11 @@ class LocalSiteCharacteristicsDataImpl
protected:
friend class base::RefCounted<LocalSiteCharacteristicsDataImpl>;
friend class LocalSiteCharacteristicsDataImplTest;
friend class resource_coordinator::LocalSiteCharacteristicsDataReaderTest;
friend class resource_coordinator::LocalSiteCharacteristicsDataStore;
LocalSiteCharacteristicsDataImpl(const std::string& origin_str,
OnDestroyDelegate* delegate);
// Helper functions to convert from/to the internal representation that is
// used to store TimeDelta values in the |SiteCharacteristicsProto| protobuf.
......@@ -67,6 +90,8 @@ class LocalSiteCharacteristicsDataImpl
// Returns the minimum observation time before considering a feature as
// unused.
// TODO(sebmarchand): Make these experimentally configurable, define the
// experiment variables in tab_manager_features.h.
static constexpr base::TimeDelta
GetUpdatesFaviconInBackgroundMinObservationWindow() {
return base::TimeDelta::FromHours(2);
......@@ -86,7 +111,7 @@ class LocalSiteCharacteristicsDataImpl
virtual ~LocalSiteCharacteristicsDataImpl();
// Returns the observation duration for a given feature, this is the sum of
// Returns for how long a given feature has been observed, this is the sum of
// the recorded observation duration and the current observation duration
// since this site has been loaded (if applicable). If a feature has been
// used then it returns 0.
......@@ -103,6 +128,8 @@ class LocalSiteCharacteristicsDataImpl
return site_characteristics_;
}
const std::string& origin_str() const { return origin_str_; }
static const int64_t kZeroIntervalInternalRepresentation;
private:
......@@ -139,6 +166,10 @@ class LocalSiteCharacteristicsDataImpl
// tab gets loaded, stops when the last one gets unloaded).
size_t active_webcontents_count_;
// The delegate that should get notified when this object is about to get
// destroyed.
OnDestroyDelegate* const delegate_;
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(LocalSiteCharacteristicsDataImpl);
};
......
......@@ -7,7 +7,9 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/test/simple_test_tick_clock.h"
#include "chrome/browser/resource_coordinator/local_site_characteristics_data_unittest_utils.h"
#include "chrome/browser/resource_coordinator/time.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace resource_coordinator {
......@@ -22,17 +24,20 @@ constexpr base::TimeDelta kInitialTimeSinceEpoch =
class TestLocalSiteCharacteristicsDataImpl
: public LocalSiteCharacteristicsDataImpl {
public:
using LocalSiteCharacteristicsDataImpl::FeatureObservationDuration;
using LocalSiteCharacteristicsDataImpl::
GetUsesAudioInBackgroundMinObservationWindow;
using LocalSiteCharacteristicsDataImpl::
GetUsesNotificationsInBackgroundMinObservationWindow;
using LocalSiteCharacteristicsDataImpl::FeatureObservationDuration;
using LocalSiteCharacteristicsDataImpl::last_loaded_time_for_testing;
using LocalSiteCharacteristicsDataImpl::OnDestroyDelegate;
using LocalSiteCharacteristicsDataImpl::site_characteristics_for_testing;
using LocalSiteCharacteristicsDataImpl::TimeDeltaToInternalRepresentation;
using LocalSiteCharacteristicsDataImpl::last_loaded_time_for_testing;
explicit TestLocalSiteCharacteristicsDataImpl(const std::string& origin_str)
: LocalSiteCharacteristicsDataImpl(origin_str) {}
explicit TestLocalSiteCharacteristicsDataImpl(
const std::string& origin_str,
LocalSiteCharacteristicsDataImpl::OnDestroyDelegate* delegate)
: LocalSiteCharacteristicsDataImpl(origin_str, delegate) {}
base::TimeDelta FeatureObservationTimestamp(
const SiteCharacteristicsFeatureProto& feature_proto) {
......@@ -40,12 +45,12 @@ class TestLocalSiteCharacteristicsDataImpl
}
protected:
~TestLocalSiteCharacteristicsDataImpl() override{};
~TestLocalSiteCharacteristicsDataImpl() override {}
};
} // namespace
class LocalSiteCharacteristicsDataImplTest : public testing::Test {
class LocalSiteCharacteristicsDataImplTest : public ::testing::Test {
public:
LocalSiteCharacteristicsDataImplTest()
: scoped_set_tick_clock_for_testing_(&test_clock_) {}
......@@ -60,11 +65,17 @@ class LocalSiteCharacteristicsDataImplTest : public testing::Test {
protected:
base::SimpleTestTickClock test_clock_;
ScopedSetTickClockForTesting scoped_set_tick_clock_for_testing_;
// Use a NiceMock as there's no need to add expectations in these tests,
// there's a dedicated test that ensure that the delegate works as expected.
::testing::NiceMock<
testing::MockLocalSiteCharacteristicsDataImplOnDestroyDelegate>
destroy_delegate_;
};
TEST_F(LocalSiteCharacteristicsDataImplTest, BasicTestEndToEnd) {
auto local_site_data =
base::MakeRefCounted<TestLocalSiteCharacteristicsDataImpl>(kDummyOrigin);
base::MakeRefCounted<TestLocalSiteCharacteristicsDataImpl>(
kDummyOrigin, &destroy_delegate_);
local_site_data->NotifySiteLoaded();
......@@ -120,7 +131,8 @@ TEST_F(LocalSiteCharacteristicsDataImplTest, BasicTestEndToEnd) {
TEST_F(LocalSiteCharacteristicsDataImplTest, LastLoadedTime) {
auto local_site_data =
base::MakeRefCounted<TestLocalSiteCharacteristicsDataImpl>(kDummyOrigin);
base::MakeRefCounted<TestLocalSiteCharacteristicsDataImpl>(
kDummyOrigin, &destroy_delegate_);
// Create a second instance of this object, simulates having several tab
// owning it.
auto local_site_data2(local_site_data);
......@@ -150,7 +162,8 @@ TEST_F(LocalSiteCharacteristicsDataImplTest, LastLoadedTime) {
TEST_F(LocalSiteCharacteristicsDataImplTest, GetFeatureUsageForUnloadedSite) {
auto local_site_data =
base::MakeRefCounted<TestLocalSiteCharacteristicsDataImpl>(kDummyOrigin);
base::MakeRefCounted<TestLocalSiteCharacteristicsDataImpl>(
kDummyOrigin, &destroy_delegate_);
local_site_data->NotifySiteLoaded();
local_site_data->NotifyUsesAudioInBackground();
......@@ -203,7 +216,8 @@ TEST_F(LocalSiteCharacteristicsDataImplTest, AllDurationGetSavedOnUnload) {
// This test helps making sure that the observation/timestamp fields get saved
// for all the features being tracked.
auto local_site_data =
base::MakeRefCounted<TestLocalSiteCharacteristicsDataImpl>(kDummyOrigin);
base::MakeRefCounted<TestLocalSiteCharacteristicsDataImpl>(
kDummyOrigin, &destroy_delegate_);
const base::TimeDelta kInterval = base::TimeDelta::FromSeconds(1);
const auto kIntervalInternalRepresentation =
......@@ -266,5 +280,21 @@ TEST_F(LocalSiteCharacteristicsDataImplTest, AllDurationGetSavedOnUnload) {
local_site_data->site_characteristics_for_testing().SerializeAsString());
}
// Verify that the OnDestroyDelegate gets notified when a
// LocalSiteCharacteristicsDataImpl object gets destroyed.
TEST_F(LocalSiteCharacteristicsDataImplTest, DestroyNotifiesDelegate) {
::testing::StrictMock<
testing::MockLocalSiteCharacteristicsDataImplOnDestroyDelegate>
strict_delegate;
{
auto local_site_data =
base::MakeRefCounted<TestLocalSiteCharacteristicsDataImpl>(
kDummyOrigin, &strict_delegate);
EXPECT_CALL(strict_delegate, OnLocalSiteCharacteristicsDataImplDestroyed(
local_site_data.get()));
}
::testing::Mock::VerifyAndClear(&strict_delegate);
}
} // namespace internal
} // namespace resource_coordinator
......@@ -30,11 +30,11 @@ class LocalSiteCharacteristicsDataReader
private:
friend class LocalSiteCharacteristicsDataReaderTest;
friend class LocalSiteCharacteristicsDataStoreTest;
friend class LocalSiteCharacteristicsDataStore;
// Private constructor, these objects are meant to be created by a site
// characteristics data store (not currently implemented).
// TODO(sebmarchand): Update this comment once the site characteristics data
// store class gets implemented.
// characteristics data store.
explicit LocalSiteCharacteristicsDataReader(
scoped_refptr<internal::LocalSiteCharacteristicsDataImpl> impl);
......
......@@ -8,18 +8,23 @@
#include "base/memory/ptr_util.h"
#include "base/test/simple_test_tick_clock.h"
#include "chrome/browser/resource_coordinator/local_site_characteristics_data_impl.h"
#include "chrome/browser/resource_coordinator/local_site_characteristics_data_unittest_utils.h"
#include "chrome/browser/resource_coordinator/time.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace resource_coordinator {
class LocalSiteCharacteristicsDataReaderTest : public testing::Test {
public:
class LocalSiteCharacteristicsDataReaderTest : public ::testing::Test {
protected:
// The constructors needs to call 'new' directly rather than using the
// base::MakeRefCounted helper function because the constructor of
// LocalSiteCharacteristicsDataImpl is protected and not visible to
// base::MakeRefCounted.
LocalSiteCharacteristicsDataReaderTest()
: scoped_set_tick_clock_for_testing_(&test_clock_),
test_impl_(
base::MakeRefCounted<internal::LocalSiteCharacteristicsDataImpl>(
"foo.com")) {
test_impl_(base::WrapRefCounted(
new internal::LocalSiteCharacteristicsDataImpl("foo.com",
&delegate_))) {
test_impl_->NotifySiteLoaded();
LocalSiteCharacteristicsDataReader* reader =
new LocalSiteCharacteristicsDataReader(test_impl_.get());
......@@ -28,9 +33,10 @@ class LocalSiteCharacteristicsDataReaderTest : public testing::Test {
~LocalSiteCharacteristicsDataReaderTest() override {
test_impl_->NotifySiteUnloaded();
reader_.reset();
test_impl_ = nullptr;
}
protected:
base::SimpleTestTickClock test_clock_;
ScopedSetTickClockForTesting scoped_set_tick_clock_for_testing_;
......@@ -41,6 +47,13 @@ class LocalSiteCharacteristicsDataReaderTest : public testing::Test {
// to create this object.
std::unique_ptr<LocalSiteCharacteristicsDataReader> reader_;
// The mock delegate used by the LocalSiteCharacteristicsDataImpl objects
// created by this class, NiceMock is used to avoid having to set expectations
// in test cases that don't care about this.
::testing::NiceMock<
testing::MockLocalSiteCharacteristicsDataImplOnDestroyDelegate>
delegate_;
DISALLOW_COPY_AND_ASSIGN(LocalSiteCharacteristicsDataReaderTest);
};
......
// Copyright 2018 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/resource_coordinator/local_site_characteristics_data_store.h"
#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
#include "chrome/browser/resource_coordinator/local_site_characteristics_data_reader.h"
namespace resource_coordinator {
LocalSiteCharacteristicsDataStore::LocalSiteCharacteristicsDataStore() =
default;
LocalSiteCharacteristicsDataStore::~LocalSiteCharacteristicsDataStore() =
default;
std::unique_ptr<SiteCharacteristicsDataReader>
LocalSiteCharacteristicsDataStore::GetReaderForOrigin(
const std::string& origin_str) {
internal::LocalSiteCharacteristicsDataImpl* impl =
GetOrCreateFeatureImpl(origin_str);
DCHECK_NE(nullptr, impl);
SiteCharacteristicsDataReader* data_reader =
new LocalSiteCharacteristicsDataReader(impl);
return base::WrapUnique(data_reader);
}
internal::LocalSiteCharacteristicsDataImpl*
LocalSiteCharacteristicsDataStore::GetOrCreateFeatureImpl(
const std::string& origin_str) {
// Start by checking if there's already an entry for this origin.
auto iter = origin_data_map_.find(origin_str);
if (iter != origin_data_map_.end())
return iter->second;
// If not create a new one and add it to the map.
internal::LocalSiteCharacteristicsDataImpl* site_characteristic_data =
new internal::LocalSiteCharacteristicsDataImpl(origin_str, this);
// internal::LocalSiteCharacteristicsDataImpl is a ref-counted object, it's
// safe to store a raw pointer to it here as this class will get notified when
// it's about to be destroyed and it'll be removed from the map.
origin_data_map_.insert(std::make_pair(origin_str, site_characteristic_data));
return site_characteristic_data;
}
void LocalSiteCharacteristicsDataStore::
OnLocalSiteCharacteristicsDataImplDestroyed(
internal::LocalSiteCharacteristicsDataImpl* impl) {
DCHECK_NE(nullptr, impl);
DCHECK(base::ContainsKey(origin_data_map_, impl->origin_str()));
// Remove the entry for this origin as this is about to get destroyed.
auto num_erased = origin_data_map_.erase(impl->origin_str());
DCHECK_EQ(1U, num_erased);
}
} // namespace resource_coordinator
// Copyright 2018 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_RESOURCE_COORDINATOR_LOCAL_SITE_CHARACTERISTICS_DATA_STORE_H_
#define CHROME_BROWSER_RESOURCE_COORDINATOR_LOCAL_SITE_CHARACTERISTICS_DATA_STORE_H_
#include "base/containers/flat_map.h"
#include "base/macros.h"
#include "chrome/browser/resource_coordinator/local_site_characteristics_data_impl.h"
#include "chrome/browser/resource_coordinator/site_characteristics_data_store.h"
namespace resource_coordinator {
// Implementation of a SiteCharacteristicsDataStore that use the local site
// characteristics database as a backend.
class LocalSiteCharacteristicsDataStore
: public SiteCharacteristicsDataStore,
public internal::LocalSiteCharacteristicsDataImpl::OnDestroyDelegate {
public:
using LocalSiteCharacteristicsMap =
base::flat_map<std::string, internal::LocalSiteCharacteristicsDataImpl*>;
LocalSiteCharacteristicsDataStore();
~LocalSiteCharacteristicsDataStore() override;
// SiteCharacteristicDataStore:
std::unique_ptr<SiteCharacteristicsDataReader> GetReaderForOrigin(
const std::string& origin_str) override;
const LocalSiteCharacteristicsMap& origin_data_map_for_testing() const {
return origin_data_map_;
}
private:
// Returns a pointer to the LocalSiteCharacteristicsDataImpl object
// associated with |origin|, create one and add it to |origin_data_map_|
// if it doesn't exist.
internal::LocalSiteCharacteristicsDataImpl* GetOrCreateFeatureImpl(
const std::string& origin_str);
// internal::LocalSiteCharacteristicsDataImpl::OnDestroyDelegate:
void OnLocalSiteCharacteristicsDataImplDestroyed(
internal::LocalSiteCharacteristicsDataImpl* impl) override;
// Map a serialized origin to a LocalSiteCharacteristicDataInternal
// pointer.
LocalSiteCharacteristicsMap origin_data_map_;
DISALLOW_COPY_AND_ASSIGN(LocalSiteCharacteristicsDataStore);
};
} // namespace resource_coordinator
#endif // CHROME_BROWSER_RESOURCE_COORDINATOR_LOCAL_SITE_CHARACTERISTICS_DATA_STORE_H_
// Copyright 2018 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/resource_coordinator/local_site_characteristics_data_store.h"
#include "base/macros.h"
#include "chrome/browser/resource_coordinator/local_site_characteristics_data_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace resource_coordinator {
using LocalSiteCharacteristicsDataStoreTest = testing::Test;
TEST_F(LocalSiteCharacteristicsDataStoreTest, EndToEnd) {
const std::string kOrigin = "foo.com";
LocalSiteCharacteristicsDataStore data_store;
EXPECT_TRUE(data_store.origin_data_map_for_testing().empty());
auto reader = data_store.GetReaderForOrigin(kOrigin);
EXPECT_NE(nullptr, reader.get());
EXPECT_EQ(1U, data_store.origin_data_map_for_testing().size());
internal::LocalSiteCharacteristicsDataImpl* impl =
data_store.origin_data_map_for_testing().find(kOrigin)->second;
EXPECT_NE(nullptr, impl);
EXPECT_EQ(SiteFeatureUsage::kSiteFeatureUsageUnknown,
reader->UpdatesTitleInBackground());
impl->NotifySiteLoaded();
impl->NotifyUpdatesTitleInBackground();
impl->NotifySiteUnloaded();
EXPECT_EQ(SiteFeatureUsage::kSiteFeatureInUse,
reader->UpdatesTitleInBackground());
auto reader_copy = data_store.GetReaderForOrigin(kOrigin);
EXPECT_EQ(1U, data_store.origin_data_map_for_testing().size());
reader_copy.reset();
reader.reset();
EXPECT_TRUE(data_store.origin_data_map_for_testing().empty());
}
} // namespace resource_coordinator
// Copyright 2018 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/resource_coordinator/local_site_characteristics_data_unittest_utils.h"
namespace resource_coordinator {
namespace testing {
MockLocalSiteCharacteristicsDataImplOnDestroyDelegate::
MockLocalSiteCharacteristicsDataImplOnDestroyDelegate() = default;
MockLocalSiteCharacteristicsDataImplOnDestroyDelegate::
~MockLocalSiteCharacteristicsDataImplOnDestroyDelegate() = default;
} // namespace testing
} // namespace resource_coordinator
// Copyright 2018 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_RESOURCE_COORDINATOR_LOCAL_SITE_CHARACTERISTICS_DATA_UNITTEST_UTILS_H_
#define CHROME_BROWSER_RESOURCE_COORDINATOR_LOCAL_SITE_CHARACTERISTICS_DATA_UNITTEST_UTILS_H_
#include "base/macros.h"
#include "chrome/browser/resource_coordinator/local_site_characteristics_data_impl.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace resource_coordinator {
namespace testing {
class MockLocalSiteCharacteristicsDataImplOnDestroyDelegate
: public internal::LocalSiteCharacteristicsDataImpl::OnDestroyDelegate {
public:
MockLocalSiteCharacteristicsDataImplOnDestroyDelegate();
~MockLocalSiteCharacteristicsDataImplOnDestroyDelegate();
MOCK_METHOD1(OnLocalSiteCharacteristicsDataImplDestroyed,
void(internal::LocalSiteCharacteristicsDataImpl*));
private:
DISALLOW_COPY_AND_ASSIGN(
MockLocalSiteCharacteristicsDataImplOnDestroyDelegate);
};
} // namespace testing
} // namespace resource_coordinator
#endif // CHROME_BROWSER_RESOURCE_COORDINATOR_LOCAL_SITE_CHARACTERISTICS_DATA_UNITTEST_UTILS_H_
// Copyright 2018 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_RESOURCE_COORDINATOR_SITE_CHARACTERISTICS_DATA_STORE_H_
#define CHROME_BROWSER_RESOURCE_COORDINATOR_SITE_CHARACTERISTICS_DATA_STORE_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "chrome/browser/resource_coordinator/site_characteristics_data_reader.h"
namespace resource_coordinator {
// Pure virtual interface for a site characteristics data store.
class SiteCharacteristicsDataStore {
public:
SiteCharacteristicsDataStore() = default;
virtual ~SiteCharacteristicsDataStore() {}
// Returns a SiteCharacteristicsDataReader for the given origin.
virtual std::unique_ptr<SiteCharacteristicsDataReader> GetReaderForOrigin(
const std::string& origin) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(SiteCharacteristicsDataStore);
};
} // namespace resource_coordinator
#endif // CHROME_BROWSER_RESOURCE_COORDINATOR_SITE_CHARACTERISTICS_DATA_STORE_H_
......@@ -2914,6 +2914,9 @@ test("unit_tests") {
"../browser/resource_coordinator/lifecycle_unit_unittest.cc",
"../browser/resource_coordinator/local_site_characteristics_data_impl_unittest.cc",
"../browser/resource_coordinator/local_site_characteristics_data_reader_unittest.cc",
"../browser/resource_coordinator/local_site_characteristics_data_store_unittest.cc",
"../browser/resource_coordinator/local_site_characteristics_data_unittest_utils.cc",
"../browser/resource_coordinator/local_site_characteristics_data_unittest_utils.h",
"../browser/resource_coordinator/tab_activity_watcher_unittest.cc",
"../browser/resource_coordinator/tab_lifecycle_unit_source_unittest.cc",
"../browser/resource_coordinator/tab_lifecycle_unit_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