-
Notifications
You must be signed in to change notification settings - Fork 896
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ads] Add ads service waiter for testing
- Loading branch information
Showing
9 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/brave_ads/test_ads_service_waiter.h" | ||
|
||
#include "base/check.h" | ||
#include "brave/components/brave_ads/browser/ads_service.h" | ||
|
||
namespace brave_ads { | ||
|
||
AdsServiceWaiter::AdsServiceWaiter(AdsService* const ads_service) | ||
: ads_service_(ads_service) { | ||
CHECK(ads_service_); | ||
|
||
ads_service_->AddObserver(this); | ||
} | ||
|
||
AdsServiceWaiter::~AdsServiceWaiter() { | ||
ads_service_->RemoveObserver(this); | ||
} | ||
|
||
void AdsServiceWaiter::Wait() { | ||
run_loop_.Run(); | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
void AdsServiceWaiter::OnAdsServiceInitialized() { | ||
run_loop_.Quit(); | ||
} | ||
|
||
} // namespace brave_ads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_BRAVE_ADS_TEST_ADS_SERVICE_WAITER_H_ | ||
#define BRAVE_BROWSER_BRAVE_ADS_TEST_ADS_SERVICE_WAITER_H_ | ||
|
||
#include "base/memory/raw_ptr.h" | ||
#include "base/run_loop.h" | ||
#include "brave/components/brave_ads/browser/ads_service_observer.h" | ||
|
||
namespace brave_ads { | ||
|
||
class AdsService; | ||
|
||
// This class waits for the ads service to be initialized. | ||
class AdsServiceWaiter : public AdsServiceObserver { | ||
public: | ||
explicit AdsServiceWaiter(AdsService* const ads_service); | ||
~AdsServiceWaiter() override; | ||
|
||
AdsServiceWaiter(const AdsServiceWaiter&) = delete; | ||
AdsServiceWaiter& operator=(const AdsServiceWaiter&) = delete; | ||
|
||
void Wait(); | ||
|
||
private: | ||
// AdsServiceObserver: | ||
void OnAdsServiceInitialized() override; | ||
|
||
const raw_ptr<AdsService> ads_service_; // not owned. | ||
|
||
base::RunLoop run_loop_; | ||
}; | ||
|
||
} // namespace brave_ads | ||
|
||
#endif // BRAVE_BROWSER_BRAVE_ADS_TEST_ADS_SERVICE_WAITER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* Copyright (c) 2024 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_ADS_SERVICE_OBSERVER_H_ | ||
#define BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_ADS_SERVICE_OBSERVER_H_ | ||
|
||
#include "base/observer_list_types.h" | ||
|
||
namespace brave_ads { | ||
|
||
class AdsServiceObserver : public base::CheckedObserver { | ||
public: | ||
// Invoked when the ads service has initialized. | ||
virtual void OnAdsServiceInitialized() {} | ||
}; | ||
|
||
} // namespace brave_ads | ||
|
||
#endif // BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_ADS_SERVICE_OBSERVER_H_ |