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

Unified Diff: chrome/browser/custom_handlers/protocol_handler_registry.cc

Issue 10546083: Convert ProtocolHandlerRegistry to be a ProfileKeyedService. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Respond to review comments. Fit and finish. Created 8 years, 6 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/custom_handlers/protocol_handler_registry.cc
diff --git a/chrome/browser/custom_handlers/protocol_handler_registry.cc b/chrome/browser/custom_handlers/protocol_handler_registry.cc
index 5a6dfae91134364984447dfffb2269b13714e820..25135a430af81edc0728ff15105d3f19fcbd2b14 100644
--- a/chrome/browser/custom_handlers/protocol_handler_registry.cc
+++ b/chrome/browser/custom_handlers/protocol_handler_registry.cc
@@ -44,6 +44,22 @@ bool ShouldRemoveHandlersNotInOS() {
#endif
}
+void InstallDefaultProtocolHandlers(ProtocolHandlerRegistry* registry) {
+ // only chromeos has default protocol handlers at this point.
+ #if defined(OS_CHROMEOS)
+ registry->AddPredefinedHandler(
+ ProtocolHandler::CreateProtocolHandler(
+ "mailto",
+ GURL(l10n_util::GetStringUTF8(IDS_GOOGLE_MAILTO_HANDLER_URL)),
+ l10n_util::GetStringUTF16(IDS_GOOGLE_MAILTO_HANDLER_NAME)));
+ registry->AddPredefinedHandler(
+ ProtocolHandler::CreateProtocolHandler(
+ "webcal",
+ GURL(l10n_util::GetStringUTF8(IDS_GOOGLE_WEBCAL_HANDLER_URL)),
+ l10n_util::GetStringUTF16(IDS_GOOGLE_WEBCAL_HANDLER_NAME)));
+ #endif
+}
+
} // namespace
static const ProtocolHandler& LookupHandler(
@@ -146,7 +162,8 @@ void ProtocolHandlerRegistry::Delegate::RegisterWithOSAsDefaultClient(
// ProtocolHandlerRegistry -----------------------------------------------------
-ProtocolHandlerRegistry::ProtocolHandlerRegistry(Profile* profile,
+ProtocolHandlerRegistry::ProtocolHandlerRegistry(
+ Profile* profile,
Delegate* delegate)
: profile_(profile),
delegate_(delegate),
@@ -233,11 +250,14 @@ ProtocolHandlerRegistry::GetReplacedHandlers(
void ProtocolHandlerRegistry::ClearDefault(const std::string& scheme) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
default_handlers_.erase(scheme);
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- base::Bind(&ProtocolHandlerRegistry::ClearDefaultIO, this, scheme));
+ base::Bind(&ProtocolHandlerRegistry::ClearDefaultIO,
+ base::Unretained(this),
+ scheme));
Save();
NotifyChanged();
}
@@ -248,7 +268,11 @@ bool ProtocolHandlerRegistry::IsDefault(
return GetHandlerFor(handler.protocol()) == handler;
}
-void ProtocolHandlerRegistry::Load() {
+void ProtocolHandlerRegistry::InitProtocolSettings() {
+
+ // Install predefined protocol handlers.
+ InstallDefaultProtocolHandlers(this);
+
// Any further default additions to the table will get rejected from now on.
is_loaded_ = true;
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -259,8 +283,10 @@ void ProtocolHandlerRegistry::Load() {
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- base::Bind(enabled_ ? &ProtocolHandlerRegistry::EnableIO :
- &ProtocolHandlerRegistry::DisableIO, this));
+ base::Bind(enabled_ ?
+ &ProtocolHandlerRegistry::EnableIO :
+ &ProtocolHandlerRegistry::DisableIO,
+ base::Unretained(this)));
}
std::vector<const DictionaryValue*> registered_handlers =
GetHandlersFromPref(prefs::kRegisteredProtocolHandlers);
@@ -452,7 +478,8 @@ void ProtocolHandlerRegistry::RemoveHandler(
} else {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- base::Bind(&ProtocolHandlerRegistry::ClearDefaultIO, this,
+ base::Bind(&ProtocolHandlerRegistry::ClearDefaultIO,
+ base::Unretained(this),
q->second.protocol()));
default_handlers_.erase(q);
}
@@ -502,7 +529,7 @@ void ProtocolHandlerRegistry::Enable() {
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- base::Bind(&ProtocolHandlerRegistry::EnableIO, this));
+ base::Bind(&ProtocolHandlerRegistry::EnableIO, base::Unretained(this)));
ProtocolHandlerMap::const_iterator p;
for (p = default_handlers_.begin(); p != default_handlers_.end(); ++p) {
delegate_->RegisterExternalHandler(p->first);
@@ -520,7 +547,8 @@ void ProtocolHandlerRegistry::Disable() {
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- base::Bind(&ProtocolHandlerRegistry::DisableIO, this));
+ base::Bind(&ProtocolHandlerRegistry::DisableIO,
+ base::Unretained(this)));
ProtocolHandlerMap::const_iterator p;
for (p = default_handlers_.begin(); p != default_handlers_.end(); ++p) {
delegate_->DeregisterExternalHandler(p->first);
@@ -529,7 +557,7 @@ void ProtocolHandlerRegistry::Disable() {
NotifyChanged();
}
-void ProtocolHandlerRegistry::Finalize() {
+void ProtocolHandlerRegistry::Shutdown() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
delegate_.reset(NULL);
// We free these now in case there are any outstanding workers running. If
@@ -553,7 +581,7 @@ void ProtocolHandlerRegistry::RegisterPrefs(PrefService* pref_service) {
}
ProtocolHandlerRegistry::~ProtocolHandlerRegistry() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(default_client_observers_.empty());
}
@@ -618,7 +646,9 @@ void ProtocolHandlerRegistry::SetDefault(const ProtocolHandler& handler) {
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- base::Bind(&ProtocolHandlerRegistry::SetDefaultIO, this, handler));
+ base::Bind(&ProtocolHandlerRegistry::SetDefaultIO,
+ base::Unretained(this),
+ handler));
}
void ProtocolHandlerRegistry::InsertHandler(const ProtocolHandler& handler) {
@@ -720,5 +750,3 @@ void ProtocolHandlerRegistry::AddPredefinedHandler(
RegisterProtocolHandler(handler);
SetDefault(handler);
}
-
-

Powered by Google App Engine
This is Rietveld 408576698