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

Unified Diff: chrome/browser/ui/webui/password_manager_internals/password_manager_internals_ui.cc

Issue 269513003: Password manager internals page service: wiring it in (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding forgotten s/NotifyCanUseLogRouter/OnLogRouterAvailabilityChanged in tests Created 6 years, 7 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
Index: chrome/browser/ui/webui/password_manager_internals/password_manager_internals_ui.cc
diff --git a/chrome/browser/ui/webui/password_manager_internals/password_manager_internals_ui.cc b/chrome/browser/ui/webui/password_manager_internals/password_manager_internals_ui.cc
index 34d46112af75a041f980bb3165e77da57f15c7f6..90963475735491cadc9969b73ffd35eb8898a5c0 100644
--- a/chrome/browser/ui/webui/password_manager_internals/password_manager_internals_ui.cc
+++ b/chrome/browser/ui/webui/password_manager_internals/password_manager_internals_ui.cc
@@ -7,26 +7,18 @@
#include <algorithm>
#include <set>
-#include "base/strings/string16.h"
-#include "base/strings/stringprintf.h"
-#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
-#include "chrome/browser/password_manager/chrome_password_manager_client.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/android/tab_model/tab_model.h"
-#include "chrome/browser/ui/android/tab_model/tab_model_list.h"
-#include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
#include "chrome/common/url_constants.h"
-#include "content/public/browser/browser_context.h"
-#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/web_contents.h"
+#include "components/password_manager/content/browser/password_manager_internals_service_factory.h"
+#include "components/password_manager/core/browser/password_manager_internals_service.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "grit/password_manager_internals_resources.h"
#include "net/base/escape.h"
-using content::BrowserContext;
-using content::WebContents;
+using password_manager::PasswordManagerInternalsService;
+using password_manager::PasswordManagerInternalsServiceFactory;
namespace {
@@ -42,92 +34,46 @@ content::WebUIDataSource* CreatePasswordManagerInternalsHTMLSource() {
return source;
}
-void InsertWebContentsIfProfileMatches(
- WebContents* web_contents,
- const Profile* profile_to_match,
- std::set<WebContents*>* set_of_web_contents) {
- if (static_cast<const BrowserContext*>(profile_to_match) ==
- web_contents->GetBrowserContext()) {
- set_of_web_contents->insert(web_contents);
- }
-}
-
} // namespace
PasswordManagerInternalsUI::PasswordManagerInternalsUI(content::WebUI* web_ui)
: WebUIController(web_ui),
WebContentsObserver(web_ui->GetWebContents()),
- did_stop_loading_(false) {
+ registered_with_logging_service_(false) {
// Set up the chrome://password-manager-internals/ source.
content::WebUIDataSource::Add(Profile::FromWebUI(web_ui),
CreatePasswordManagerInternalsHTMLSource());
- NotifyAllPasswordManagerClients(PAGE_OPENED);
}
PasswordManagerInternalsUI::~PasswordManagerInternalsUI() {
- NotifyAllPasswordManagerClients(PAGE_CLOSED);
+ if (!registered_with_logging_service_)
+ return;
+ PasswordManagerInternalsService* service =
+ PasswordManagerInternalsServiceFactory::GetForBrowserContext(
+ Profile::FromWebUI(web_ui()));
+ if (service)
+ service->UnregisterReceiver(this);
}
void PasswordManagerInternalsUI::DidStopLoading(
content::RenderViewHost* /* render_view_host */) {
- did_stop_loading_ = true;
- if (log_buffer_.empty())
- return;
- LogInternal(log_buffer_);
- log_buffer_.clear();
+ PasswordManagerInternalsService* service =
+ PasswordManagerInternalsServiceFactory::GetForBrowserContext(
+ Profile::FromWebUI(web_ui()));
+ if (service) {
+ registered_with_logging_service_ = true;
+ std::string past_logs(service->RegisterReceiver(this));
+ LogSavePasswordProgress(past_logs);
+ }
}
void PasswordManagerInternalsUI::LogSavePasswordProgress(
const std::string& text) {
- if (did_stop_loading_)
- LogInternal(text);
- else
- log_buffer_.append(text);
-}
-
-void PasswordManagerInternalsUI::LogInternal(const std::string& text) {
+ if (!registered_with_logging_service_)
+ return;
std::string no_quotes(text);
std::replace(no_quotes.begin(), no_quotes.end(), '"', ' ');
base::StringValue text_string_value(net::EscapeForHTML(no_quotes));
web_ui()->CallJavascriptFunction("addSavePasswordProgressLog",
text_string_value);
}
-
-void PasswordManagerInternalsUI::NotifyAllPasswordManagerClients(
- ClientNotificationType notification_type) {
- // First, find all the WebContents objects of the current profile.
- Profile* current_profile = Profile::FromWebUI(web_ui());
- std::set<WebContents*> profile_web_contents;
-#if defined(OS_ANDROID)
- for (TabModelList::const_iterator iter = TabModelList::begin();
- iter != TabModelList::end();
- ++iter) {
- TabModel* model = *iter;
- for (int i = 0; i < model->GetTabCount(); ++i) {
- InsertWebContentsIfProfileMatches(
- model->GetWebContentsAt(i), current_profile, &profile_web_contents);
- }
- }
-#else
- for (TabContentsIterator iter; !iter.done(); iter.Next()) {
- InsertWebContentsIfProfileMatches(
- *iter, current_profile, &profile_web_contents);
- }
-#endif
-
- // Now get the corresponding PasswordManagerClients, and attach/detach |this|.
- for (std::set<WebContents*>::iterator it = profile_web_contents.begin();
- it != profile_web_contents.end();
- ++it) {
- ChromePasswordManagerClient* client =
- ChromePasswordManagerClient::FromWebContents(*it);
- switch (notification_type) {
- case PAGE_OPENED:
- client->SetLogger(this);
- break;
- case PAGE_CLOSED:
- client->SetLogger(NULL);
- break;
- }
- }
-}

Powered by Google App Engine
This is Rietveld 408576698