Commit 093eb2b7 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Cleanups near callback list uses.

Mostly, converts typedef -> using per style guide. Also uses
CallbackList::CallbackType more (and more systematically), and some
other misc. cleanup like using stl_util.h, explicitly declaring types
more, etc.

Bug: none
Change-Id: I63241972f5bede0c1cdb85ade8a0ba1155979cf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354621
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarRyan Sleevi <rsleevi@chromium.org>
Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarOrin Jaworski <orinj@chromium.org>
Reviewed-by: default avatarJohn Wu <jzw@chromium.org>
Reviewed-by: default avatarAchuith Bhandarkar <achuith@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798656}
parent af2991e7
...@@ -80,14 +80,12 @@ struct AccessibilityStatusEventDetails { ...@@ -80,14 +80,12 @@ struct AccessibilityStatusEventDetails {
bool enabled; bool enabled;
}; };
typedef base::RepeatingCallback<void(const AccessibilityStatusEventDetails&)> using AccessibilityStatusCallbackList =
AccessibilityStatusCallback; base::CallbackList<void(const AccessibilityStatusEventDetails&)>;
using AccessibilityStatusCallback =
typedef base::CallbackList<void(const AccessibilityStatusEventDetails&)> AccessibilityStatusCallbackList::CallbackType;
AccessibilityStatusCallbackList; using AccessibilityStatusSubscription =
AccessibilityStatusCallbackList::Subscription;
typedef AccessibilityStatusCallbackList::Subscription
AccessibilityStatusSubscription;
class AccessibilityPanelWidgetObserver; class AccessibilityPanelWidgetObserver;
......
...@@ -32,8 +32,8 @@ namespace chromeos { ...@@ -32,8 +32,8 @@ namespace chromeos {
// make a decision. // make a decision.
class AutoEnrollmentController { class AutoEnrollmentController {
public: public:
typedef base::CallbackList<void(policy::AutoEnrollmentState)> using ProgressCallbackList =
ProgressCallbackList; base::CallbackList<void(policy::AutoEnrollmentState)>;
// Parameter values for the kEnterpriseEnableForcedReEnrollment flag. // Parameter values for the kEnterpriseEnableForcedReEnrollment flag.
static const char kForcedReEnrollmentAlways[]; static const char kForcedReEnrollmentAlways[];
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "base/notreached.h" #include "base/notreached.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/values.h" #include "base/values.h"
...@@ -104,10 +105,10 @@ class CloudExternalDataManagerBase::Backend { ...@@ -104,10 +105,10 @@ class CloudExternalDataManagerBase::Backend {
private: private:
// List of callbacks to invoke when the attempt to retrieve external data // List of callbacks to invoke when the attempt to retrieve external data
// referenced by a policy completes successfully or fails permanently. // referenced by a policy completes successfully or fails permanently.
typedef std::vector<ExternalDataFetcher::FetchCallback> FetchCallbackList; using FetchCallbackList = std::vector<ExternalDataFetcher::FetchCallback>;
// Map from policy names to the lists of callbacks defined above. // Map from policy names to the lists of callbacks defined above.
typedef std::map<std::string, FetchCallbackList> FetchCallbackMap; using FetchCallbackMap = std::map<std::string, FetchCallbackList>;
// Looks up the maximum size that the data referenced by |policy| can have. // Looks up the maximum size that the data referenced by |policy| can have.
size_t GetMaxExternalDataSize(const std::string& policy) const; size_t GetMaxExternalDataSize(const std::string& policy) const;
...@@ -214,11 +215,9 @@ void CloudExternalDataManagerBase::Backend::OnMetadataUpdated( ...@@ -214,11 +215,9 @@ void CloudExternalDataManagerBase::Backend::OnMetadataUpdated(
// Cancel the external data download. // Cancel the external data download.
updater_->CancelExternalDataFetch(policy); updater_->CancelExternalDataFetch(policy);
} }
for (ExternalDataFetcher::FetchCallback& callback : it->second) { // Invoke all callbacks for |policy|, indicating permanent failure.
// Invoke all callbacks for |policy|, indicating permanent failure. for (ExternalDataFetcher::FetchCallback& callback : it->second)
RunCallback(std::move(callback), std::unique_ptr<std::string>(), RunCallback(std::move(callback), nullptr, base::FilePath());
base::FilePath());
}
pending_downloads_.erase(it++); pending_downloads_.erase(it++);
continue; continue;
} }
...@@ -244,8 +243,8 @@ bool CloudExternalDataManagerBase::Backend::OnDownloadSuccess( ...@@ -244,8 +243,8 @@ bool CloudExternalDataManagerBase::Backend::OnDownloadSuccess(
if (external_data_store_) if (external_data_store_)
file_path = external_data_store_->Store(policy, hash, data); file_path = external_data_store_->Store(policy, hash, data);
FetchCallbackList& pending_callbacks = pending_downloads_[policy]; for (ExternalDataFetcher::FetchCallback& callback :
for (ExternalDataFetcher::FetchCallback& callback : pending_callbacks) { pending_downloads_[policy]) {
RunCallback(std::move(callback), std::make_unique<std::string>(data), RunCallback(std::move(callback), std::make_unique<std::string>(data),
file_path); file_path);
} }
...@@ -262,22 +261,14 @@ void CloudExternalDataManagerBase::Backend::Fetch( ...@@ -262,22 +261,14 @@ void CloudExternalDataManagerBase::Backend::Fetch(
if (metadata == metadata_.end()) { if (metadata == metadata_.end()) {
// If |policy| does not reference any external data, indicate permanent // If |policy| does not reference any external data, indicate permanent
// failure. // failure.
RunCallback(std::move(callback), std::unique_ptr<std::string>(), RunCallback(std::move(callback), nullptr, base::FilePath());
base::FilePath());
return; return;
} }
if (pending_downloads_.find(policy) != pending_downloads_.end()) { const bool has_pending_download = base::Contains(pending_downloads_, policy);
// If a download of the external data referenced by |policy| has already if (!has_pending_download && external_data_store_) {
// been requested, add |callback| to the list of callbacks for |policy| and auto data = std::make_unique<std::string>();
// return. const base::FilePath file_path =
pending_downloads_[policy].push_back(std::move(callback));
return;
}
std::unique_ptr<std::string> data(new std::string);
if (external_data_store_) {
base::FilePath file_path =
external_data_store_->Load(policy, metadata->second.hash, external_data_store_->Load(policy, metadata->second.hash,
GetMaxExternalDataSize(policy), data.get()); GetMaxExternalDataSize(policy), data.get());
if (!file_path.empty()) { if (!file_path.empty()) {
...@@ -288,10 +279,9 @@ void CloudExternalDataManagerBase::Backend::Fetch( ...@@ -288,10 +279,9 @@ void CloudExternalDataManagerBase::Backend::Fetch(
} }
} }
// Request a download of the the external data referenced by |policy| and
// initialize the list of callbacks by adding |callback|.
pending_downloads_[policy].push_back(std::move(callback)); pending_downloads_[policy].push_back(std::move(callback));
StartDownload(policy); if (!has_pending_download)
StartDownload(policy);
} }
void CloudExternalDataManagerBase::Backend::FetchAll() { void CloudExternalDataManagerBase::Backend::FetchAll() {
...@@ -300,7 +290,7 @@ void CloudExternalDataManagerBase::Backend::FetchAll() { ...@@ -300,7 +290,7 @@ void CloudExternalDataManagerBase::Backend::FetchAll() {
for (const auto& it : metadata_) { for (const auto& it : metadata_) {
const std::string& policy = it.first; const std::string& policy = it.first;
std::unique_ptr<std::string> data(new std::string); std::unique_ptr<std::string> data(new std::string);
if (pending_downloads_.find(policy) != pending_downloads_.end() || if (base::Contains(pending_downloads_, policy) ||
(external_data_store_ && (external_data_store_ &&
!external_data_store_ !external_data_store_
->Load(policy, it.second.hash, GetMaxExternalDataSize(policy), ->Load(policy, it.second.hash, GetMaxExternalDataSize(policy),
...@@ -349,7 +339,7 @@ void CloudExternalDataManagerBase::Backend::RunCallback( ...@@ -349,7 +339,7 @@ void CloudExternalDataManagerBase::Backend::RunCallback(
void CloudExternalDataManagerBase::Backend::StartDownload( void CloudExternalDataManagerBase::Backend::StartDownload(
const std::string& policy) { const std::string& policy) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(pending_downloads_.find(policy) != pending_downloads_.end()); DCHECK(base::Contains(pending_downloads_, policy));
if (!updater_) if (!updater_)
return; return;
......
...@@ -32,7 +32,7 @@ ServerBackedStateKeysBroker::~ServerBackedStateKeysBroker() { ...@@ -32,7 +32,7 @@ ServerBackedStateKeysBroker::~ServerBackedStateKeysBroker() {
ServerBackedStateKeysBroker::Subscription ServerBackedStateKeysBroker::Subscription
ServerBackedStateKeysBroker::RegisterUpdateCallback( ServerBackedStateKeysBroker::RegisterUpdateCallback(
const base::RepeatingClosure& callback) { const UpdateCallback& callback) {
if (!available()) if (!available())
FetchStateKeys(); FetchStateKeys();
return update_callbacks_.Add(callback); return update_callbacks_.Add(callback);
...@@ -80,7 +80,7 @@ void ServerBackedStateKeysBroker::StoreStateKeys( ...@@ -80,7 +80,7 @@ void ServerBackedStateKeysBroker::StoreStateKeys(
if (send_notification) if (send_notification)
update_callbacks_.Notify(); update_callbacks_.Notify();
std::vector<StateKeysCallback> callbacks; StateKeysCallbackList callbacks;
request_callbacks_.swap(callbacks); request_callbacks_.swap(callbacks);
for (auto& callback : callbacks) { for (auto& callback : callbacks) {
if (!callback.is_null()) if (!callback.is_null())
......
...@@ -25,10 +25,12 @@ namespace policy { ...@@ -25,10 +25,12 @@ namespace policy {
// register callbacks to invoke when the state keys change. // register callbacks to invoke when the state keys change.
class ServerBackedStateKeysBroker { class ServerBackedStateKeysBroker {
public: public:
typedef std::unique_ptr<base::CallbackList<void()>::Subscription> using UpdateCallbackList = base::CallbackList<void()>;
Subscription; using UpdateCallback = UpdateCallbackList::CallbackType;
typedef base::OnceCallback<void(const std::vector<std::string>&)> using Subscription = std::unique_ptr<UpdateCallbackList::Subscription>;
StateKeysCallback; using StateKeysCallback =
base::OnceCallback<void(const std::vector<std::string>&)>;
using StateKeysCallbackList = std::vector<StateKeysCallback>;
ServerBackedStateKeysBroker( ServerBackedStateKeysBroker(
chromeos::SessionManagerClient* session_manager_client); chromeos::SessionManagerClient* session_manager_client);
...@@ -38,7 +40,7 @@ class ServerBackedStateKeysBroker { ...@@ -38,7 +40,7 @@ class ServerBackedStateKeysBroker {
// Note that consuming code needs to hold on to the returned Subscription as // Note that consuming code needs to hold on to the returned Subscription as
// long as it wants to receive the callback. If the state keys haven't been // long as it wants to receive the callback. If the state keys haven't been
// requested yet, calling this will also trigger their initial fetch. // requested yet, calling this will also trigger their initial fetch.
Subscription RegisterUpdateCallback(const base::RepeatingClosure& callback); Subscription RegisterUpdateCallback(const UpdateCallback& callback);
// Requests state keys asynchronously. Invokes the passed callback at most // Requests state keys asynchronously. Invokes the passed callback at most
// once, with the current state keys passed as a parameter to the callback. If // once, with the current state keys passed as a parameter to the callback. If
...@@ -80,10 +82,10 @@ class ServerBackedStateKeysBroker { ...@@ -80,10 +82,10 @@ class ServerBackedStateKeysBroker {
bool requested_; bool requested_;
// List of callbacks to receive update notifications. // List of callbacks to receive update notifications.
base::CallbackList<void()> update_callbacks_; UpdateCallbackList update_callbacks_;
// List of pending one-shot state key request callbacks. // List of pending one-shot state key request callbacks.
std::vector<StateKeysCallback> request_callbacks_; StateKeysCallbackList request_callbacks_;
base::WeakPtrFactory<ServerBackedStateKeysBroker> weak_factory_{this}; base::WeakPtrFactory<ServerBackedStateKeysBroker> weak_factory_{this};
......
...@@ -107,47 +107,34 @@ typedef base::OnceCallback<void(DownloadCheckResult)> CheckDownloadCallback; ...@@ -107,47 +107,34 @@ typedef base::OnceCallback<void(DownloadCheckResult)> CheckDownloadCallback;
typedef base::RepeatingCallback<void(DownloadCheckResult)> typedef base::RepeatingCallback<void(DownloadCheckResult)>
CheckDownloadRepeatingCallback; CheckDownloadRepeatingCallback;
// A type of callback run on the main thread when a ClientDownloadRequest has // Callbacks run on the main thread when a ClientDownloadRequest has
// been formed for a download, or when one has not been formed for a supported // been formed for a download, or when one has not been formed for a supported
// download. // download.
typedef base::RepeatingCallback<void(download::DownloadItem*, using ClientDownloadRequestCallbackList =
const ClientDownloadRequest*)> base::CallbackList<void(download::DownloadItem*,
ClientDownloadRequestCallback; const ClientDownloadRequest*)>;
using ClientDownloadRequestCallback =
// A list of ClientDownloadRequest callbacks. ClientDownloadRequestCallbackList::CallbackType;
typedef base::CallbackList<void(download::DownloadItem*, using ClientDownloadRequestSubscription =
const ClientDownloadRequest*)> std::unique_ptr<ClientDownloadRequestCallbackList::Subscription>;
ClientDownloadRequestCallbackList;
// Callbacks run on the main thread when a NativeFileSystemWriteRequest has been
// A subscription to a registered ClientDownloadRequest callback. // formed for a write operation.
typedef std::unique_ptr<ClientDownloadRequestCallbackList::Subscription> using NativeFileSystemWriteRequestCallbackList =
ClientDownloadRequestSubscription; base::CallbackList<void(const ClientDownloadRequest*)>;
using NativeFileSystemWriteRequestCallback =
// A type of callback run on the main thread when a NativeFileSystemWriteRequest NativeFileSystemWriteRequestCallbackList::CallbackType;
// has been formed for a write operation. using NativeFileSystemWriteRequestSubscription =
typedef base::Callback<void(const ClientDownloadRequest*)> std::unique_ptr<NativeFileSystemWriteRequestCallbackList::Subscription>;
NativeFileSystemWriteRequestCallback;
// Callbacks run on the main thread when a PPAPI ClientDownloadRequest has been
// A list of NativeFileSystemWriteRequest callbacks. // formed for a download.
typedef base::CallbackList<void(const ClientDownloadRequest*)> using PPAPIDownloadRequestCallbackList =
NativeFileSystemWriteRequestCallbackList; base::CallbackList<void(const ClientDownloadRequest*)>;
using PPAPIDownloadRequestCallback =
// A subscription to a registered NativeFileSystemWriteRequest callback. PPAPIDownloadRequestCallbackList::CallbackType;
typedef std::unique_ptr<NativeFileSystemWriteRequestCallbackList::Subscription> using PPAPIDownloadRequestSubscription =
NativeFileSystemWriteRequestSubscription; std::unique_ptr<PPAPIDownloadRequestCallbackList::Subscription>;
// A type of callback run on the main thread when a PPAPI
// ClientDownloadRequest has been formed for a download.
typedef base::RepeatingCallback<void(const ClientDownloadRequest*)>
PPAPIDownloadRequestCallback;
// A list of PPAPI ClientDownloadRequest callbacks.
typedef base::CallbackList<void(const ClientDownloadRequest*)>
PPAPIDownloadRequestCallbackList;
// A subscription to a registered PPAPI ClientDownloadRequest callback.
typedef std::unique_ptr<PPAPIDownloadRequestCallbackList::Subscription>
PPAPIDownloadRequestSubscription;
void RecordCountOfWhitelistedDownload(WhitelistType type); void RecordCountOfWhitelistedDownload(WhitelistType type);
......
...@@ -289,7 +289,7 @@ class MockCustomLinksManager : public CustomLinksManager { ...@@ -289,7 +289,7 @@ class MockCustomLinksManager : public CustomLinksManager {
class PopularSitesFactoryForTest { class PopularSitesFactoryForTest {
public: public:
PopularSitesFactoryForTest( explicit PopularSitesFactoryForTest(
sync_preferences::TestingPrefServiceSyncable* pref_service) sync_preferences::TestingPrefServiceSyncable* pref_service)
: prefs_(pref_service) { : prefs_(pref_service) {
test_shared_loader_factory_ = test_shared_loader_factory_ =
...@@ -423,10 +423,7 @@ class TopSitesCallbackList { ...@@ -423,10 +423,7 @@ class TopSitesCallbackList {
class MostVisitedSitesTest class MostVisitedSitesTest
: public ::testing::TestWithParam<std::tuple<bool, bool>> { : public ::testing::TestWithParam<std::tuple<bool, bool>> {
protected: protected:
MostVisitedSitesTest() MostVisitedSitesTest() {
: is_custom_links_enabled_(false),
popular_sites_factory_(&pref_service_),
mock_top_sites_(new StrictMock<MockTopSites>()) {
MostVisitedSites::RegisterProfilePrefs(pref_service_.registry()); MostVisitedSites::RegisterProfilePrefs(pref_service_.registry());
std::vector<base::Feature> enabled_features; std::vector<base::Feature> enabled_features;
...@@ -548,7 +545,7 @@ class MostVisitedSitesTest ...@@ -548,7 +545,7 @@ class MostVisitedSitesTest
void EnableCustomLinks() { is_custom_links_enabled_ = true; } void EnableCustomLinks() { is_custom_links_enabled_ = true; }
bool is_custom_links_enabled_; bool is_custom_links_enabled_ = false;
base::CallbackList<SuggestionsService::ResponseCallback::RunType> base::CallbackList<SuggestionsService::ResponseCallback::RunType>
suggestions_service_callbacks_; suggestions_service_callbacks_;
TopSitesCallbackList top_sites_callbacks_; TopSitesCallbackList top_sites_callbacks_;
...@@ -556,8 +553,9 @@ class MostVisitedSitesTest ...@@ -556,8 +553,9 @@ class MostVisitedSitesTest
base::test::SingleThreadTaskEnvironment task_environment_; base::test::SingleThreadTaskEnvironment task_environment_;
data_decoder::test::InProcessDataDecoder in_process_data_decoder_; data_decoder::test::InProcessDataDecoder in_process_data_decoder_;
sync_preferences::TestingPrefServiceSyncable pref_service_; sync_preferences::TestingPrefServiceSyncable pref_service_;
PopularSitesFactoryForTest popular_sites_factory_; PopularSitesFactoryForTest popular_sites_factory_{&pref_service_};
scoped_refptr<StrictMock<MockTopSites>> mock_top_sites_; scoped_refptr<StrictMock<MockTopSites>> mock_top_sites_ =
base::MakeRefCounted<StrictMock<MockTopSites>>();
StrictMock<MockSuggestionsService> mock_suggestions_service_; StrictMock<MockSuggestionsService> mock_suggestions_service_;
StrictMock<MockMostVisitedSitesObserver> mock_observer_; StrictMock<MockMostVisitedSitesObserver> mock_observer_;
std::unique_ptr<MostVisitedSites> most_visited_sites_; std::unique_ptr<MostVisitedSites> most_visited_sites_;
...@@ -1248,7 +1246,7 @@ TEST_P(MostVisitedSitesWithCustomLinksTest, ...@@ -1248,7 +1246,7 @@ TEST_P(MostVisitedSitesWithCustomLinksTest,
VerifyAndClearExpectations(); VerifyAndClearExpectations();
EXPECT_CALL(mock_observer_, OnURLsAvailable(_)).Times(0); EXPECT_CALL(mock_observer_, OnURLsAvailable(_)).Times(0);
top_sites_callbacks_.ClearAndNotify( top_sites_callbacks_.ClearAndNotify(
{MakeMostVisitedURL("Site 2", "http://site2/")}); MostVisitedURLList({MakeMostVisitedURL("Site 2", "http://site2/")}));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
...@@ -1852,10 +1850,10 @@ TEST_P(MostVisitedSitesWithCacheHitTest, ...@@ -1852,10 +1850,10 @@ TEST_P(MostVisitedSitesWithCacheHitTest,
MatchesTile("Site 7", "http://site7/", MatchesTile("Site 7", "http://site7/",
TileSource::TOP_SITES)))))); TileSource::TOP_SITES))))));
top_sites_callbacks_.ClearAndNotify( top_sites_callbacks_.ClearAndNotify(
{MakeMostVisitedURL("Site 4", "http://site4/"), MostVisitedURLList({MakeMostVisitedURL("Site 4", "http://site4/"),
MakeMostVisitedURL("Site 5", "http://site5/"), MakeMostVisitedURL("Site 5", "http://site5/"),
MakeMostVisitedURL("Site 6", "http://site6/"), MakeMostVisitedURL("Site 6", "http://site6/"),
MakeMostVisitedURL("Site 7", "http://site7/")}); MakeMostVisitedURL("Site 7", "http://site7/")}));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
...@@ -1954,7 +1952,7 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest, ...@@ -1954,7 +1952,7 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest,
// Reply from top sites is ignored (i.e. not reported to observer). // Reply from top sites is ignored (i.e. not reported to observer).
top_sites_callbacks_.ClearAndNotify( top_sites_callbacks_.ClearAndNotify(
{MakeMostVisitedURL("Site 4", "http://site4/")}); MostVisitedURLList({MakeMostVisitedURL("Site 4", "http://site4/")}));
VerifyAndClearExpectations(); VerifyAndClearExpectations();
// Update by TopSites is also ignored. // Update by TopSites is also ignored.
...@@ -1980,9 +1978,9 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest, ...@@ -1980,9 +1978,9 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest,
MatchesTile("Site 3", "http://site3/", MatchesTile("Site 3", "http://site3/",
TileSource::TOP_SITES)))))); TileSource::TOP_SITES))))));
top_sites_callbacks_.ClearAndNotify( top_sites_callbacks_.ClearAndNotify(
{MakeMostVisitedURL("Site 1", "http://site1/"), MostVisitedURLList({MakeMostVisitedURL("Site 1", "http://site1/"),
MakeMostVisitedURL("Site 2", "http://site2/"), MakeMostVisitedURL("Site 2", "http://site2/"),
MakeMostVisitedURL("Site 3", "http://site3/")}); MakeMostVisitedURL("Site 3", "http://site3/")}));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
...@@ -1999,9 +1997,9 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest, ...@@ -1999,9 +1997,9 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest,
MatchesTile("Site 3", "http://site3/", MatchesTile("Site 3", "http://site3/",
TileSource::TOP_SITES)))))); TileSource::TOP_SITES))))));
top_sites_callbacks_.ClearAndNotify( top_sites_callbacks_.ClearAndNotify(
{MakeMostVisitedURL("Site 1", "http://site1/"), MostVisitedURLList({MakeMostVisitedURL("Site 1", "http://site1/"),
MakeMostVisitedURL("Site 2", "http://site2/"), MakeMostVisitedURL("Site 2", "http://site2/"),
MakeMostVisitedURL("Site 3", "http://site3/")}); MakeMostVisitedURL("Site 3", "http://site3/")}));
VerifyAndClearExpectations(); VerifyAndClearExpectations();
// Reply from suggestions service overrides top sites. // Reply from suggestions service overrides top sites.
...@@ -2035,9 +2033,9 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest, ...@@ -2035,9 +2033,9 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest,
MatchesTile("Site 3", "http://site3/", MatchesTile("Site 3", "http://site3/",
TileSource::TOP_SITES)))))); TileSource::TOP_SITES))))));
top_sites_callbacks_.ClearAndNotify( top_sites_callbacks_.ClearAndNotify(
{MakeMostVisitedURL("Site 1", "http://site1/"), MostVisitedURLList({MakeMostVisitedURL("Site 1", "http://site1/"),
MakeMostVisitedURL("Site 2", "http://site2/"), MakeMostVisitedURL("Site 2", "http://site2/"),
MakeMostVisitedURL("Site 3", "http://site3/")}); MakeMostVisitedURL("Site 3", "http://site3/")}));
VerifyAndClearExpectations(); VerifyAndClearExpectations();
// Reply from suggestions service is empty and thus ignored. // Reply from suggestions service is empty and thus ignored.
...@@ -2057,9 +2055,9 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest, ShouldPropagateUpdateByTopSites) { ...@@ -2057,9 +2055,9 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest, ShouldPropagateUpdateByTopSites) {
MatchesTile("Site 3", "http://site3/", MatchesTile("Site 3", "http://site3/",
TileSource::TOP_SITES)))))); TileSource::TOP_SITES))))));
top_sites_callbacks_.ClearAndNotify( top_sites_callbacks_.ClearAndNotify(
{MakeMostVisitedURL("Site 1", "http://site1/"), MostVisitedURLList({MakeMostVisitedURL("Site 1", "http://site1/"),
MakeMostVisitedURL("Site 2", "http://site2/"), MakeMostVisitedURL("Site 2", "http://site2/"),
MakeMostVisitedURL("Site 3", "http://site3/")}); MakeMostVisitedURL("Site 3", "http://site3/")}));
VerifyAndClearExpectations(); VerifyAndClearExpectations();
// Reply from suggestions service is empty and thus ignored. // Reply from suggestions service is empty and thus ignored.
...@@ -2105,7 +2103,7 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest, ...@@ -2105,7 +2103,7 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest,
SectionType::PERSONALIZED, IsEmpty())))); SectionType::PERSONALIZED, IsEmpty()))));
} }
suggestions_service_callbacks_.Notify(SuggestionsProfile()); suggestions_service_callbacks_.Notify(SuggestionsProfile());
top_sites_callbacks_.ClearAndNotify(MostVisitedURLList{}); top_sites_callbacks_.ClearAndNotify(MostVisitedURLList());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
...@@ -2125,9 +2123,9 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest, ...@@ -2125,9 +2123,9 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest,
suggestions_service_callbacks_.Notify(SuggestionsProfile()); suggestions_service_callbacks_.Notify(SuggestionsProfile());
top_sites_callbacks_.ClearAndNotify( top_sites_callbacks_.ClearAndNotify(
{MakeMostVisitedURL("Site 1", "http://site1/"), MostVisitedURLList({MakeMostVisitedURL("Site 1", "http://site1/"),
MakeMostVisitedURL("Site 2", "http://site2/"), MakeMostVisitedURL("Site 2", "http://site2/"),
MakeMostVisitedURL("Site 3", "http://site3/")}); MakeMostVisitedURL("Site 3", "http://site3/")}));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
...@@ -2137,9 +2135,9 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest, ...@@ -2137,9 +2135,9 @@ TEST_P(MostVisitedSitesWithEmptyCacheTest,
history::TopSitesObserver::ChangeReason::MOST_VISITED); history::TopSitesObserver::ChangeReason::MOST_VISITED);
EXPECT_FALSE(top_sites_callbacks_.empty()); EXPECT_FALSE(top_sites_callbacks_.empty());
top_sites_callbacks_.ClearAndNotify( top_sites_callbacks_.ClearAndNotify(
{MakeMostVisitedURL("Site 1", "http://site1/"), MostVisitedURLList({MakeMostVisitedURL("Site 1", "http://site1/"),
MakeMostVisitedURL("Site 2", "http://site2/"), MakeMostVisitedURL("Site 2", "http://site2/"),
MakeMostVisitedURL("Site 3", "http://site3/")}); MakeMostVisitedURL("Site 3", "http://site3/")}));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
} }
......
...@@ -10,7 +10,8 @@ OmniboxEventGlobalTracker* OmniboxEventGlobalTracker::GetInstance() { ...@@ -10,7 +10,8 @@ OmniboxEventGlobalTracker* OmniboxEventGlobalTracker::GetInstance() {
return base::Singleton<OmniboxEventGlobalTracker>::get(); return base::Singleton<OmniboxEventGlobalTracker>::get();
} }
std::unique_ptr<base::CallbackList<void(OmniboxLog*)>::Subscription> std::unique_ptr<
OmniboxEventGlobalTracker::OnURLOpenedCallbackList::Subscription>
OmniboxEventGlobalTracker::RegisterCallback(const OnURLOpenedCallback& cb) { OmniboxEventGlobalTracker::RegisterCallback(const OnURLOpenedCallback& cb) {
return on_url_opened_callback_list_.Add(cb); return on_url_opened_callback_list_.Add(cb);
} }
......
...@@ -24,14 +24,15 @@ struct OmniboxLog; ...@@ -24,14 +24,15 @@ struct OmniboxLog;
// forwards the event to its registered observers. // forwards the event to its registered observers.
class OmniboxEventGlobalTracker { class OmniboxEventGlobalTracker {
public: public:
typedef base::RepeatingCallback<void(OmniboxLog*)> OnURLOpenedCallback; using OnURLOpenedCallbackList = base::CallbackList<void(OmniboxLog*)>;
using OnURLOpenedCallback = OnURLOpenedCallbackList::CallbackType;
// Returns the instance of OmniboxEventGlobalTracker. // Returns the instance of OmniboxEventGlobalTracker.
static OmniboxEventGlobalTracker* GetInstance(); static OmniboxEventGlobalTracker* GetInstance();
// Registers |cb| to be invoked when user open an URL from the omnibox. // Registers |cb| to be invoked when user open an URL from the omnibox.
std::unique_ptr<base::CallbackList<void(OmniboxLog*)>::Subscription> std::unique_ptr<OnURLOpenedCallbackList::Subscription> RegisterCallback(
RegisterCallback(const OnURLOpenedCallback& cb); const OnURLOpenedCallback& cb);
// Called to notify all registered callbacks that an URL was opened from // Called to notify all registered callbacks that an URL was opened from
// the omnibox. // the omnibox.
...@@ -46,7 +47,7 @@ class OmniboxEventGlobalTracker { ...@@ -46,7 +47,7 @@ class OmniboxEventGlobalTracker {
OmniboxEventGlobalTracker& operator=(const OmniboxEventGlobalTracker&) = OmniboxEventGlobalTracker& operator=(const OmniboxEventGlobalTracker&) =
delete; delete;
base::CallbackList<void(OmniboxLog*)> on_url_opened_callback_list_; OnURLOpenedCallbackList on_url_opened_callback_list_;
}; };
#endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EVENT_GLOBAL_TRACKER_H_ #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_EVENT_GLOBAL_TRACKER_H_
...@@ -55,10 +55,9 @@ class TranslateLanguageList { ...@@ -55,10 +55,9 @@ class TranslateLanguageList {
// pending request. // pending request.
void SetResourceRequestsAllowed(bool allowed); void SetResourceRequestsAllowed(bool allowed);
typedef base::RepeatingCallback<void(const TranslateEventDetails&)> using EventCallbackList =
EventCallback; base::CallbackList<void(const TranslateEventDetails&)>;
typedef base::CallbackList<void(const TranslateEventDetails&)> using EventCallback = EventCallbackList::CallbackType;
EventCallbackList;
// Registers a callback for translate events related to the language list, // Registers a callback for translate events related to the language list,
// such as updates and download errors. // such as updates and download errors.
......
...@@ -139,16 +139,14 @@ class TranslateManager { ...@@ -139,16 +139,14 @@ class TranslateManager {
void ReportLanguageDetectionError(); void ReportLanguageDetectionError();
// Callback types for translate errors. // Callback types for translate errors.
typedef base::RepeatingCallback<void(const TranslateErrorDetails&)> using TranslateErrorCallbackList =
TranslateErrorCallback; base::CallbackList<void(const TranslateErrorDetails&)>;
typedef base::CallbackList<void(const TranslateErrorDetails&)> using TranslateErrorCallback = TranslateErrorCallbackList::CallbackType;
TranslateErrorCallbackList;
// Callback types for translate initialization. // Callback types for translate initialization.
typedef base::RepeatingCallback<void(const TranslateInitDetails&)> using TranslateInitCallbackList =
TranslateInitCallback; base::CallbackList<void(const TranslateInitDetails&)>;
typedef base::CallbackList<void(const TranslateInitDetails&)> using TranslateInitCallback = TranslateInitCallbackList::CallbackType;
TranslateInitCallbackList;
// Registers a callback for translate errors. // Registers a callback for translate errors.
static std::unique_ptr<TranslateErrorCallbackList::Subscription> static std::unique_ptr<TranslateErrorCallbackList::Subscription>
......
...@@ -93,7 +93,7 @@ class TranslateScript { ...@@ -93,7 +93,7 @@ class TranslateScript {
base::TimeDelta expiration_delay_; base::TimeDelta expiration_delay_;
// The callbacks called when the server sends a response. // The callbacks called when the server sends a response.
typedef std::vector<RequestCallback> RequestCallbackList; using RequestCallbackList = std::vector<RequestCallback>;
RequestCallbackList callback_list_; RequestCallbackList callback_list_;
base::WeakPtrFactory<TranslateScript> weak_method_factory_{this}; base::WeakPtrFactory<TranslateScript> weak_method_factory_{this};
......
...@@ -49,9 +49,11 @@ const char kChapsPath[] = "libchaps.so"; ...@@ -49,9 +49,11 @@ const char kChapsPath[] = "libchaps.so";
class ChromeOSUserData { class ChromeOSUserData {
public: public:
using SlotReadyCallback = base::OnceCallback<void(ScopedPK11Slot)>;
explicit ChromeOSUserData(ScopedPK11Slot public_slot) explicit ChromeOSUserData(ScopedPK11Slot public_slot)
: public_slot_(std::move(public_slot)), : public_slot_(std::move(public_slot)) {}
private_slot_initialization_started_(false) {}
~ChromeOSUserData() { ~ChromeOSUserData() {
if (public_slot_) { if (public_slot_) {
SECStatus status = SECMOD_CloseUserDB(public_slot_.get()); SECStatus status = SECMOD_CloseUserDB(public_slot_.get());
...@@ -65,8 +67,7 @@ class ChromeOSUserData { ...@@ -65,8 +67,7 @@ class ChromeOSUserData {
: nullptr); : nullptr);
} }
ScopedPK11Slot GetPrivateSlot( ScopedPK11Slot GetPrivateSlot(SlotReadyCallback callback) {
base::OnceCallback<void(ScopedPK11Slot)> callback) {
if (private_slot_) if (private_slot_)
return ScopedPK11Slot(PK11_ReferenceSlot(private_slot_.get())); return ScopedPK11Slot(PK11_ReferenceSlot(private_slot_.get()));
if (!callback.is_null()) if (!callback.is_null())
...@@ -96,13 +97,14 @@ class ChromeOSUserData { ...@@ -96,13 +97,14 @@ class ChromeOSUserData {
} }
private: private:
using SlotReadyCallbackList =
std::vector<base::OnceCallback<void(ScopedPK11Slot)>>;
ScopedPK11Slot public_slot_; ScopedPK11Slot public_slot_;
ScopedPK11Slot private_slot_; ScopedPK11Slot private_slot_;
bool private_slot_initialization_started_; bool private_slot_initialization_started_ = false;
typedef std::vector<base::OnceCallback<void(ScopedPK11Slot)>>
SlotReadyCallbackList;
SlotReadyCallbackList tpm_ready_callback_list_; SlotReadyCallbackList tpm_ready_callback_list_;
}; };
......
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