Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Unified Diff: chrome/browser/extensions/api/passwords_private/passwords_private_apitest.cc

Issue 1857513002: Update code so 1:1 relation between delegate and router is more clear. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Feedback Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/api/passwords_private/passwords_private_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/passwords_private/passwords_private_apitest.cc
diff --git a/chrome/browser/extensions/api/passwords_private/passwords_private_apitest.cc b/chrome/browser/extensions/api/passwords_private/passwords_private_apitest.cc
index b49e886c16ee95bd27f69fde712df666c6bdce72..870b2008b381022d9128406143dd3f0c248ea720 100644
--- a/chrome/browser/extensions/api/passwords_private/passwords_private_apitest.cc
+++ b/chrome/browser/extensions/api/passwords_private/passwords_private_apitest.cc
@@ -14,6 +14,8 @@
#include "base/values.h"
#include "chrome/browser/extensions/api/passwords_private/passwords_private_delegate.h"
#include "chrome/browser/extensions/api/passwords_private/passwords_private_delegate_factory.h"
+#include "chrome/browser/extensions/api/passwords_private/passwords_private_event_router.h"
+#include "chrome/browser/extensions/api/passwords_private/passwords_private_event_router_factory.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/common/extensions/api/passwords_private.h"
#include "chrome/test/base/testing_profile.h"
@@ -53,7 +55,7 @@ std::string CreateException(size_t num) {
// or RemovePasswordException() is called.
class TestDelegate : public PasswordsPrivateDelegate {
public:
- TestDelegate() {
+ TestDelegate() : profile_(nullptr) {
// Create mock data.
for (size_t i = 0; i < kNumMocks; i++) {
current_entries_.push_back(CreateEntry(i));
@@ -62,14 +64,18 @@ class TestDelegate : public PasswordsPrivateDelegate {
}
~TestDelegate() override {}
- void AddObserver(Observer* observer) override {
- observers_.AddObserver(observer);
- SendSavedPasswordsList();
- SendPasswordExceptionsList();
+ void SendSavedPasswordsList() override {
+ PasswordsPrivateEventRouter* router =
+ PasswordsPrivateEventRouterFactory::GetForProfile(profile_);
+ if (router)
+ router->OnSavedPasswordsListChanged(current_entries_);
}
- void RemoveObserver(Observer* observer) override {
- observers_.RemoveObserver(observer);
+ void SendPasswordExceptionsList() override {
+ PasswordsPrivateEventRouter* router =
+ PasswordsPrivateEventRouterFactory::GetForProfile(profile_);
+ if (router)
+ router->OnPasswordExceptionsListChanged(current_exceptions_);
}
void RemoveSavedPassword(
@@ -98,30 +104,23 @@ class TestDelegate : public PasswordsPrivateDelegate {
content::WebContents* web_contents) override {
// Return a mocked password value.
std::string plaintext_password(kPlaintextPassword);
- FOR_EACH_OBSERVER(
- Observer, observers_,
- OnPlaintextPasswordFetched(origin_url, username, plaintext_password));
- }
-
- private:
- void SendSavedPasswordsList() {
- FOR_EACH_OBSERVER(Observer, observers_,
- OnSavedPasswordsListChanged(current_entries_));
+ PasswordsPrivateEventRouter* router =
+ PasswordsPrivateEventRouterFactory::GetForProfile(profile_);
+ if (router) {
+ router->OnPlaintextPasswordFetched(origin_url, username,
+ plaintext_password);
+ }
}
- void SendPasswordExceptionsList() {
- FOR_EACH_OBSERVER(Observer, observers_,
- OnPasswordExceptionsListChanged(current_exceptions_));
- }
+ void SetProfile(Profile* profile) { profile_ = profile; }
+ private:
// The current list of entries/exceptions. Cached here so that when new
// observers are added, this delegate can send the current lists without
// having to request them from |password_manager_presenter_| again.
std::vector<api::passwords_private::PasswordUiEntry> current_entries_;
std::vector<std::string> current_exceptions_;
-
- // The observers.
- base::ObserverList<Observer> observers_;
+ Profile* profile_;
};
class PasswordsPrivateApiTest : public ExtensionApiTest {
@@ -151,6 +150,7 @@ class PasswordsPrivateApiTest : public ExtensionApiTest {
ExtensionApiTest::SetUpOnMainThread();
PasswordsPrivateDelegateFactory::GetInstance()->SetTestingFactory(
profile(), &PasswordsPrivateApiTest::GetPasswordsPrivateDelegate);
+ s_test_delegate_->SetProfile(profile());
content::RunAllPendingInMessageLoop();
}
« no previous file with comments | « no previous file | chrome/browser/extensions/api/passwords_private/passwords_private_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698