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

Unified Diff: content/browser/push_messaging_message_filter.cc

Issue 340773006: Dispatch push event to worker from PushServiceImpl#OnMessage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Debugging. Created 6 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: content/browser/push_messaging_message_filter.cc
diff --git a/content/browser/push_messaging_message_filter.cc b/content/browser/push_messaging_message_filter.cc
index 451c11253f6be876828459a742e4928d4780a679..6a059dfe90314302cc8f2b57bf2da021afa7b6b5 100644
--- a/content/browser/push_messaging_message_filter.cc
+++ b/content/browser/push_messaging_message_filter.cc
@@ -8,18 +8,24 @@
#include "base/bind.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
+#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/common/push_messaging_messages.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/push_messaging_application_id.h"
#include "content/public/browser/push_messaging_service.h"
namespace content {
-PushMessagingMessageFilter::PushMessagingMessageFilter(int render_process_id)
+PushMessagingMessageFilter::PushMessagingMessageFilter(
+ int render_process_id,
+ ServiceWorkerContextWrapper* worker_context)
: BrowserMessageFilter(PushMessagingMsgStart),
render_process_id_(render_process_id),
+ worker_context_(worker_context),
service_(NULL),
- weak_factory_(this) {}
+ weak_factory_(this) {
+}
PushMessagingMessageFilter::~PushMessagingMessageFilter() {}
@@ -35,31 +41,51 @@ bool PushMessagingMessageFilter::OnMessageReceived(
void PushMessagingMessageFilter::OnRegister(int routing_id,
int callbacks_id,
- const std::string& sender_id) {
+ const std::string& sender_id,
+ const GURL& url,
+ int worker_provider_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
// TODO(mvanouwerkerk): Validate arguments?
- // TODO(mvanouwerkerk): A WebContentsObserver could avoid this PostTask
- // by receiving the IPC on the UI thread.
- BrowserThread::PostTask(BrowserThread::UI,
- FROM_HERE,
- base::Bind(&PushMessagingMessageFilter::DoRegister,
- weak_factory_.GetWeakPtr(),
- routing_id,
- callbacks_id,
- sender_id));
+ ServiceWorkerProviderHost* worker_host =
+ worker_context_->context()->GetProviderHost(render_process_id_,
+ worker_provider_id);
+ if (!worker_host)
+ LOG(WARNING) << "No worker host.";
+ if (worker_host && !worker_host->active_version())
+ LOG(WARNING) << "No active version."; // Why does this trigger on first page load? Because the SW is not activated yet?
+ if (!worker_host || !worker_host->active_version()) {
+ SendRegisterError(routing_id, callbacks_id);
+ return;
+ }
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&PushMessagingMessageFilter::DoRegister,
+ weak_factory_.GetWeakPtr(),
+ routing_id,
+ callbacks_id,
+ sender_id,
+ url,
+ worker_host->active_version()->registration_id()));
}
void PushMessagingMessageFilter::DoRegister(int routing_id,
int callbacks_id,
- const std::string& sender_id) {
+ const std::string& sender_id,
+ const GURL& url,
+ int64 worker_registration_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!service()) {
- DidRegister(routing_id, callbacks_id, GURL(), "", false);
+ LOG(WARNING) << "No PushMessagingService.";
+ SendRegisterError(routing_id, callbacks_id);
return;
}
- // TODO(mvanouwerkerk): Pass in a real app ID based on Service Worker ID.
- std::string app_id = "https://example.com 0";
- service_->Register(app_id,
+ PushMessagingApplicationId app_id =
+ PushMessagingApplicationId(url.GetOrigin(), worker_registration_id);
+ LOG(WARNING) << app_id.ToString();
+ LOG(WARNING) << app_id.is_valid();
+ DCHECK(app_id.is_valid());
+ service_->Register(app_id.ToString(),
sender_id,
base::Bind(&PushMessagingMessageFilter::DidRegister,
weak_factory_.GetWeakPtr(),
@@ -67,29 +93,47 @@ void PushMessagingMessageFilter::DoRegister(int routing_id,
callbacks_id));
}
-void PushMessagingMessageFilter::DidRegister(int routing_id,
- int callbacks_id,
- const GURL& endpoint,
- const std::string& registration_id,
- bool success) {
+void PushMessagingMessageFilter::DidRegister(
+ int routing_id,
+ int callbacks_id,
+ const GURL& endpoint,
+ const std::string& push_registration_id,
+ bool success) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ LOG(WARNING) << "Registration success: " << success;
if (success) {
- Send(new PushMessagingMsg_RegisterSuccess(routing_id,
- callbacks_id,
- endpoint,
- registration_id));
+ Send(new PushMessagingMsg_RegisterSuccess(
+ routing_id, callbacks_id, endpoint, push_registration_id));
} else {
Send(new PushMessagingMsg_RegisterError(routing_id, callbacks_id));
}
}
+void PushMessagingMessageFilter::SendRegisterError(int routing_id,
+ int callbacks_id) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&PushMessagingMessageFilter::SendRegisterError,
+ this,
+ routing_id,
+ callbacks_id));
+ return;
+ }
+ DidRegister(routing_id, callbacks_id, GURL(), "", false);
+}
+
PushMessagingService* PushMessagingMessageFilter::service() {
+ LOG(WARNING) << "No PushMessagingService yet.";
if (!service_) {
- RenderProcessHostImpl* host = static_cast<RenderProcessHostImpl*>(
+ RenderProcessHostImpl* process_host = static_cast<RenderProcessHostImpl*>(
RenderProcessHost::FromID(render_process_id_));
- if (!host)
+ if (!process_host) {
+ LOG(WARNING) << "No process_host.";
return NULL;
- service_ = host->GetBrowserContext()->GetPushMessagingService();
+ }
+ service_ = process_host->GetBrowserContext()->GetPushMessagingService();
}
return service_;
}

Powered by Google App Engine
This is Rietveld 408576698