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

Add the SiteCharacteristicsDataReader class.

Bug: 773382
Change-Id: Ic0f82d85a2d92c194f495d3f3b244af8b4725236
Reviewed-on: https://chromium-review.googlesource.com/1008168
Commit-Queue: Sébastien Marchand <sebmarchand@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552067}
parent 5d42f3a9
...@@ -2615,7 +2615,10 @@ jumbo_split_static_library("browser") { ...@@ -2615,7 +2615,10 @@ jumbo_split_static_library("browser") {
"resource_coordinator/lifecycle_unit_source_observer.h", "resource_coordinator/lifecycle_unit_source_observer.h",
"resource_coordinator/local_site_characteristics_data_impl.cc", "resource_coordinator/local_site_characteristics_data_impl.cc",
"resource_coordinator/local_site_characteristics_data_impl.h", "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_feature_usage.h", "resource_coordinator/local_site_characteristics_feature_usage.h",
"resource_coordinator/site_characteristics_data_reader.h",
"resource_coordinator/tab_activity_watcher.cc", "resource_coordinator/tab_activity_watcher.cc",
"resource_coordinator/tab_activity_watcher.h", "resource_coordinator/tab_activity_watcher.h",
"resource_coordinator/tab_lifecycle_observer.h", "resource_coordinator/tab_lifecycle_observer.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_reader.h"
#include "chrome/browser/resource_coordinator/local_site_characteristics_data_impl.h"
namespace resource_coordinator {
LocalSiteCharacteristicsDataReader::LocalSiteCharacteristicsDataReader(
scoped_refptr<internal::LocalSiteCharacteristicsDataImpl> impl)
: impl_(std::move(impl)) {}
LocalSiteCharacteristicsDataReader::~LocalSiteCharacteristicsDataReader() {}
SiteFeatureUsage
LocalSiteCharacteristicsDataReader::UpdatesFaviconInBackground() const {
return impl_->UpdatesFaviconInBackground();
}
SiteFeatureUsage LocalSiteCharacteristicsDataReader::UpdatesTitleInBackground()
const {
return impl_->UpdatesTitleInBackground();
}
SiteFeatureUsage LocalSiteCharacteristicsDataReader::UsesAudioInBackground()
const {
return impl_->UsesAudioInBackground();
}
SiteFeatureUsage
LocalSiteCharacteristicsDataReader::UsesNotificationsInBackground() const {
return impl_->UsesNotificationsInBackground();
}
} // 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_READER_H_
#define CHROME_BROWSER_RESOURCE_COORDINATOR_LOCAL_SITE_CHARACTERISTICS_DATA_READER_H_
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/resource_coordinator/site_characteristics_data_reader.h"
namespace resource_coordinator {
namespace internal {
class LocalSiteCharacteristicsDataImpl;
} // namespace internal
// Specialization of a SiteCharacteristicDataReader that delegates to a
// LocalSiteCharacteristicsDataImpl.
class LocalSiteCharacteristicsDataReader
: public SiteCharacteristicsDataReader {
public:
~LocalSiteCharacteristicsDataReader() override;
// SiteCharacteristicsDataReader:
SiteFeatureUsage UpdatesFaviconInBackground() const override;
SiteFeatureUsage UpdatesTitleInBackground() const override;
SiteFeatureUsage UsesAudioInBackground() const override;
SiteFeatureUsage UsesNotificationsInBackground() const override;
private:
friend class LocalSiteCharacteristicsDataReaderTest;
// 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.
explicit LocalSiteCharacteristicsDataReader(
scoped_refptr<internal::LocalSiteCharacteristicsDataImpl> impl);
// The LocalSiteCharacteristicDataInternal object we delegate to.
const scoped_refptr<internal::LocalSiteCharacteristicsDataImpl> impl_;
DISALLOW_COPY_AND_ASSIGN(LocalSiteCharacteristicsDataReader);
};
} // namespace resource_coordinator
#endif // CHROME_BROWSER_RESOURCE_COORDINATOR_LOCAL_SITE_CHARACTERISTICS_DATA_READER_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_reader.h"
#include "base/macros.h"
#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/time.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace resource_coordinator {
class LocalSiteCharacteristicsDataReaderTest : public testing::Test {
public:
LocalSiteCharacteristicsDataReaderTest()
: scoped_set_tick_clock_for_testing_(&test_clock_),
test_impl_(
base::MakeRefCounted<internal::LocalSiteCharacteristicsDataImpl>(
"foo.com")) {
test_impl_->NotifySiteLoaded();
LocalSiteCharacteristicsDataReader* reader =
new LocalSiteCharacteristicsDataReader(test_impl_.get());
reader_ = base::WrapUnique(reader);
}
~LocalSiteCharacteristicsDataReaderTest() override {
test_impl_->NotifySiteUnloaded();
}
protected:
base::SimpleTestTickClock test_clock_;
ScopedSetTickClockForTesting scoped_set_tick_clock_for_testing_;
// The LocalSiteCharacteristicsDataImpl object used in these tests.
scoped_refptr<internal::LocalSiteCharacteristicsDataImpl> test_impl_;
// A LocalSiteCharacteristicsDataReader object associated with the origin used
// to create this object.
std::unique_ptr<LocalSiteCharacteristicsDataReader> reader_;
DISALLOW_COPY_AND_ASSIGN(LocalSiteCharacteristicsDataReaderTest);
};
TEST_F(LocalSiteCharacteristicsDataReaderTest, TestAccessors) {
// Initially we have no information about any of the features.
EXPECT_EQ(SiteFeatureUsage::kSiteFeatureUsageUnknown,
reader_->UpdatesFaviconInBackground());
EXPECT_EQ(SiteFeatureUsage::kSiteFeatureUsageUnknown,
reader_->UpdatesTitleInBackground());
EXPECT_EQ(SiteFeatureUsage::kSiteFeatureUsageUnknown,
reader_->UsesAudioInBackground());
EXPECT_EQ(SiteFeatureUsage::kSiteFeatureUsageUnknown,
reader_->UsesNotificationsInBackground());
// Simulates a title update event, make sure it gets reported directly.
test_impl_->NotifyUpdatesTitleInBackground();
EXPECT_EQ(SiteFeatureUsage::kSiteFeatureInUse,
reader_->UpdatesTitleInBackground());
// Advance the clock by a large amount of time, enough for the unused features
// observation windows to expire.
test_clock_.Advance(base::TimeDelta::FromDays(31));
EXPECT_EQ(SiteFeatureUsage::kSiteFeatureNotInUse,
reader_->UpdatesFaviconInBackground());
EXPECT_EQ(SiteFeatureUsage::kSiteFeatureInUse,
reader_->UpdatesTitleInBackground());
EXPECT_EQ(SiteFeatureUsage::kSiteFeatureNotInUse,
reader_->UsesAudioInBackground());
EXPECT_EQ(SiteFeatureUsage::kSiteFeatureNotInUse,
reader_->UsesNotificationsInBackground());
}
} // 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_SITE_CHARACTERISTICS_DATA_READER_H_
#define CHROME_BROWSER_RESOURCE_COORDINATOR_SITE_CHARACTERISTICS_DATA_READER_H_
#include "chrome/browser/resource_coordinator/local_site_characteristics_feature_usage.h"
namespace resource_coordinator {
// Pure virtual interface to read the characteristics of an origin. This is a
// usable abstraction for both the local and global database.
class SiteCharacteristicsDataReader {
public:
SiteCharacteristicsDataReader() = default;
virtual ~SiteCharacteristicsDataReader() {}
// Accessors for the site characteristics usage.
virtual SiteFeatureUsage UpdatesFaviconInBackground() const = 0;
virtual SiteFeatureUsage UpdatesTitleInBackground() const = 0;
virtual SiteFeatureUsage UsesAudioInBackground() const = 0;
virtual SiteFeatureUsage UsesNotificationsInBackground() const = 0;
};
} // namespace resource_coordinator
#endif // CHROME_BROWSER_RESOURCE_COORDINATOR_SITE_CHARACTERISTICS_DATA_READER_H_
...@@ -2910,6 +2910,7 @@ test("unit_tests") { ...@@ -2910,6 +2910,7 @@ test("unit_tests") {
"../browser/resource_coordinator/lifecycle_unit_base_unittest.cc", "../browser/resource_coordinator/lifecycle_unit_base_unittest.cc",
"../browser/resource_coordinator/lifecycle_unit_unittest.cc", "../browser/resource_coordinator/lifecycle_unit_unittest.cc",
"../browser/resource_coordinator/local_site_characteristics_data_impl_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/tab_activity_watcher_unittest.cc", "../browser/resource_coordinator/tab_activity_watcher_unittest.cc",
"../browser/resource_coordinator/tab_lifecycle_unit_source_unittest.cc", "../browser/resource_coordinator/tab_lifecycle_unit_source_unittest.cc",
"../browser/resource_coordinator/tab_lifecycle_unit_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