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

Side by Side Diff: content/browser/geofencing/geofencing_dispatcher_host.cc

Issue 623823002: Chrome side of passing on the service worker registration with geofencing API calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/geofencing/geofencing_dispatcher_host.h" 5 #include "content/browser/geofencing/geofencing_dispatcher_host.h"
6 6
7 #include "content/browser/geofencing/geofencing_manager.h" 7 #include "content/browser/geofencing/geofencing_manager.h"
8 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
9 #include "content/browser/service_worker/service_worker_registration.h"
10 #include "content/browser/service_worker/service_worker_registration_handle.h"
8 #include "content/common/geofencing_messages.h" 11 #include "content/common/geofencing_messages.h"
9 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h" 12 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h"
10 #include "url/gurl.h" 13 #include "url/gurl.h"
11 14
12 namespace content { 15 namespace content {
13 16
14 static const int kMaxRegionIdLength = 200; 17 static const int kMaxRegionIdLength = 200;
15 18
16 GeofencingDispatcherHost::GeofencingDispatcherHost( 19 GeofencingDispatcherHost::GeofencingDispatcherHost(
17 BrowserContext* browser_context) 20 BrowserContext* browser_context,
21 scoped_refptr<ServiceWorkerDispatcherHost> service_worker_filter)
18 : BrowserMessageFilter(GeofencingMsgStart), 22 : BrowserMessageFilter(GeofencingMsgStart),
19 browser_context_(browser_context), 23 browser_context_(browser_context),
24 service_worker_filter_(service_worker_filter),
20 weak_factory_(this) { 25 weak_factory_(this) {
21 } 26 }
22 27
23 GeofencingDispatcherHost::~GeofencingDispatcherHost() { 28 GeofencingDispatcherHost::~GeofencingDispatcherHost() {
24 } 29 }
25 30
26 bool GeofencingDispatcherHost::OnMessageReceived(const IPC::Message& message) { 31 bool GeofencingDispatcherHost::OnMessageReceived(const IPC::Message& message) {
27 bool handled = true; 32 bool handled = true;
28 IPC_BEGIN_MESSAGE_MAP(GeofencingDispatcherHost, message) 33 IPC_BEGIN_MESSAGE_MAP(GeofencingDispatcherHost, message)
29 IPC_MESSAGE_HANDLER(GeofencingHostMsg_RegisterRegion, OnRegisterRegion) 34 IPC_MESSAGE_HANDLER(GeofencingHostMsg_RegisterRegion, OnRegisterRegion)
30 IPC_MESSAGE_HANDLER(GeofencingHostMsg_UnregisterRegion, OnUnregisterRegion) 35 IPC_MESSAGE_HANDLER(GeofencingHostMsg_UnregisterRegion, OnUnregisterRegion)
31 IPC_MESSAGE_HANDLER(GeofencingHostMsg_GetRegisteredRegions, 36 IPC_MESSAGE_HANDLER(GeofencingHostMsg_GetRegisteredRegions,
32 OnGetRegisteredRegions) 37 OnGetRegisteredRegions)
33 IPC_MESSAGE_UNHANDLED(handled = false) 38 IPC_MESSAGE_UNHANDLED(handled = false)
34 IPC_END_MESSAGE_MAP() 39 IPC_END_MESSAGE_MAP()
35 return handled; 40 return handled;
36 } 41 }
37 42
38 void GeofencingDispatcherHost::OnRegisterRegion( 43 void GeofencingDispatcherHost::OnRegisterRegion(
39 int thread_id, 44 int thread_id,
40 int request_id, 45 int request_id,
41 const std::string& region_id, 46 const std::string& region_id,
42 const blink::WebCircularGeofencingRegion& region) { 47 const blink::WebCircularGeofencingRegion& region,
48 int service_worker_registration_handle_id) {
43 // Sanity check on region_id 49 // Sanity check on region_id
44 if (region_id.length() > kMaxRegionIdLength) { 50 if (region_id.length() > kMaxRegionIdLength) {
45 Send(new GeofencingMsg_RegisterRegionComplete( 51 Send(new GeofencingMsg_RegisterRegionComplete(
46 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); 52 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR));
47 return; 53 return;
48 } 54 }
49 // TODO(mek): Actually pass service worker information to manager. 55 // Look up service worker.
56 ServiceWorkerRegistrationHandle* service_worker_handle =
57 service_worker_filter_->GetRegistrationHandle(
Michael van Ouwerkerk 2014/10/09 12:28:09 I think GetRegistration(Handle) should be exposed
Marijn Kruisselbrink 2014/10/09 22:28:58 The problem is that handle IDs currently only exis
58 service_worker_registration_handle_id);
59 ServiceWorkerRegistration* service_worker =
Michael van Ouwerkerk 2014/10/09 12:28:09 Let's be clear and call the variable service_worke
Marijn Kruisselbrink 2014/10/13 19:29:48 Done.
60 service_worker_handle ? service_worker_handle->registration() : nullptr;
61 int64 service_worker_registration_id =
62 service_worker ? service_worker->id() : -1;
63 GURL service_worker_origin =
64 service_worker ? service_worker->pattern().GetOrigin() : GURL();
65
50 GeofencingManager::GetInstance()->RegisterRegion( 66 GeofencingManager::GetInstance()->RegisterRegion(
51 browser_context_, 67 browser_context_,
52 0, /* service_worker_registration_id */ 68 service_worker_registration_id,
53 GURL(), /* service_worker_origin */ 69 service_worker_origin,
54 region_id, 70 region_id,
55 region, 71 region,
56 base::Bind(&GeofencingDispatcherHost::RegisterRegionCompleted, 72 base::Bind(&GeofencingDispatcherHost::RegisterRegionCompleted,
57 weak_factory_.GetWeakPtr(), 73 weak_factory_.GetWeakPtr(),
58 thread_id, 74 thread_id,
59 request_id)); 75 request_id));
60 } 76 }
61 77
62 void GeofencingDispatcherHost::OnUnregisterRegion( 78 void GeofencingDispatcherHost::OnUnregisterRegion(
63 int thread_id, 79 int thread_id,
64 int request_id, 80 int request_id,
65 const std::string& region_id) { 81 const std::string& region_id,
82 int service_worker_registration_handle_id) {
66 // Sanity check on region_id 83 // Sanity check on region_id
67 if (region_id.length() > kMaxRegionIdLength) { 84 if (region_id.length() > kMaxRegionIdLength) {
68 Send(new GeofencingMsg_UnregisterRegionComplete( 85 Send(new GeofencingMsg_UnregisterRegionComplete(
69 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); 86 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR));
70 return; 87 return;
71 } 88 }
72 // TODO(mek): Actually pass service worker information to manager. 89 // Look up service worker.
90 ServiceWorkerRegistrationHandle* service_worker_handle =
91 service_worker_filter_->GetRegistrationHandle(
92 service_worker_registration_handle_id);
93 ServiceWorkerRegistration* service_worker =
94 service_worker_handle ? service_worker_handle->registration() : nullptr;
95 int64 service_worker_registration_id =
96 service_worker ? service_worker->id() : -1;
97 GURL service_worker_origin =
98 service_worker ? service_worker->pattern().GetOrigin() : GURL();
99
73 GeofencingManager::GetInstance()->UnregisterRegion( 100 GeofencingManager::GetInstance()->UnregisterRegion(
74 browser_context_, 101 browser_context_,
75 0, /* service_worker_registration_id */ 102 service_worker_registration_id,
76 GURL(), /* service_worker_origin */ 103 service_worker_origin,
77 region_id, 104 region_id,
78 base::Bind(&GeofencingDispatcherHost::UnregisterRegionCompleted, 105 base::Bind(&GeofencingDispatcherHost::UnregisterRegionCompleted,
79 weak_factory_.GetWeakPtr(), 106 weak_factory_.GetWeakPtr(),
80 thread_id, 107 thread_id,
81 request_id)); 108 request_id));
82 } 109 }
83 110
84 void GeofencingDispatcherHost::OnGetRegisteredRegions(int thread_id, 111 void GeofencingDispatcherHost::OnGetRegisteredRegions(
85 int request_id) { 112 int thread_id,
113 int request_id,
114 int service_worker_registration_handle_id) {
115 // Look up service worker.
116 ServiceWorkerRegistrationHandle* service_worker_handle =
117 service_worker_filter_->GetRegistrationHandle(
118 service_worker_registration_handle_id);
119 ServiceWorkerRegistration* service_worker =
120 service_worker_handle ? service_worker_handle->registration() : nullptr;
121 int64 service_worker_registration_id =
122 service_worker ? service_worker->id() : -1;
jsbell 2014/10/08 18:41:29 Can you make this an enum value in the GeofencingM
Marijn Kruisselbrink 2014/10/13 19:29:48 I changed the code to just never call GeofencingMa
123 GURL service_worker_origin =
124 service_worker ? service_worker->pattern().GetOrigin() : GURL();
125
86 GeofencingRegistrations result; 126 GeofencingRegistrations result;
87 // TODO(mek): Actually pass service worker information to manager.
88 GeofencingStatus status = 127 GeofencingStatus status =
89 GeofencingManager::GetInstance()->GetRegisteredRegions( 128 GeofencingManager::GetInstance()->GetRegisteredRegions(
90 browser_context_, 129 browser_context_,
91 0, /* service_worker_registration_id */ 130 service_worker_registration_id,
92 GURL(), /* service_worker_origin */ 131 service_worker_origin,
93 &result); 132 &result);
94 Send(new GeofencingMsg_GetRegisteredRegionsComplete( 133 Send(new GeofencingMsg_GetRegisteredRegionsComplete(
95 thread_id, request_id, status, result)); 134 thread_id, request_id, status, result));
96 } 135 }
97 136
98 void GeofencingDispatcherHost::RegisterRegionCompleted( 137 void GeofencingDispatcherHost::RegisterRegionCompleted(
99 int thread_id, 138 int thread_id,
100 int request_id, 139 int request_id,
101 GeofencingStatus status) { 140 GeofencingStatus status) {
102 Send(new GeofencingMsg_RegisterRegionComplete(thread_id, request_id, status)); 141 Send(new GeofencingMsg_RegisterRegionComplete(thread_id, request_id, status));
103 } 142 }
104 143
105 void GeofencingDispatcherHost::UnregisterRegionCompleted( 144 void GeofencingDispatcherHost::UnregisterRegionCompleted(
106 int thread_id, 145 int thread_id,
107 int request_id, 146 int request_id,
108 GeofencingStatus status) { 147 GeofencingStatus status) {
109 Send(new GeofencingMsg_UnregisterRegionComplete( 148 Send(new GeofencingMsg_UnregisterRegionComplete(
110 thread_id, request_id, status)); 149 thread_id, request_id, status));
111 } 150 }
112 151
113 } // namespace content 152 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698