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

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: address comments 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_context_core.h"
9 #include "content/browser/service_worker/service_worker_context_wrapper.h"
10 #include "content/browser/service_worker/service_worker_registration.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<ServiceWorkerContextWrapper> service_worker_context)
18 : BrowserMessageFilter(GeofencingMsgStart), 22 : BrowserMessageFilter(GeofencingMsgStart),
19 browser_context_(browser_context), 23 browser_context_(browser_context),
24 service_worker_context_(service_worker_context),
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 int64 service_worker_registration_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
56 // Look up service worker.
57 ServiceWorkerRegistration* service_worker_registration =
58 service_worker_context_->context()->GetLiveRegistration(
59 service_worker_registration_id);
60
61 if (!service_worker_registration) {
62 Send(new GeofencingMsg_RegisterRegionComplete(
63 thread_id,
64 request_id,
65 GeofencingStatus::
66 GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER));
67 return;
68 }
69
70 GURL service_worker_origin =
71 service_worker_registration
michaeln 2014/10/14 01:03:52 don't need to check for null here
Marijn Kruisselbrink 2014/10/14 18:51:22 Done.
72 ? service_worker_registration->pattern().GetOrigin()
73 : GURL();
74
50 GeofencingManager::GetInstance()->RegisterRegion( 75 GeofencingManager::GetInstance()->RegisterRegion(
51 browser_context_, 76 browser_context_,
52 0, /* service_worker_registration_id */ 77 service_worker_registration_id,
53 GURL(), /* service_worker_origin */ 78 service_worker_origin,
54 region_id, 79 region_id,
55 region, 80 region,
56 base::Bind(&GeofencingDispatcherHost::RegisterRegionCompleted, 81 base::Bind(&GeofencingDispatcherHost::RegisterRegionCompleted,
57 weak_factory_.GetWeakPtr(), 82 weak_factory_.GetWeakPtr(),
58 thread_id, 83 thread_id,
59 request_id)); 84 request_id));
60 } 85 }
61 86
62 void GeofencingDispatcherHost::OnUnregisterRegion( 87 void GeofencingDispatcherHost::OnUnregisterRegion(
63 int thread_id, 88 int thread_id,
64 int request_id, 89 int request_id,
65 const std::string& region_id) { 90 const std::string& region_id,
91 int64 service_worker_registration_id) {
66 // Sanity check on region_id 92 // Sanity check on region_id
67 if (region_id.length() > kMaxRegionIdLength) { 93 if (region_id.length() > kMaxRegionIdLength) {
68 Send(new GeofencingMsg_UnregisterRegionComplete( 94 Send(new GeofencingMsg_UnregisterRegionComplete(
69 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); 95 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR));
70 return; 96 return;
71 } 97 }
72 // TODO(mek): Actually pass service worker information to manager. 98
99 // Look up service worker.
100 ServiceWorkerRegistration* service_worker_registration =
101 service_worker_context_->context()->GetLiveRegistration(
102 service_worker_registration_id);
103
104 if (!service_worker_registration) {
105 Send(new GeofencingMsg_UnregisterRegionComplete(
106 thread_id,
107 request_id,
108 GeofencingStatus::
109 GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER));
110 return;
111 }
112
113 GURL service_worker_origin =
114 service_worker_registration
115 ? service_worker_registration->pattern().GetOrigin()
michaeln 2014/10/14 01:03:52 ditto, null check not needed
Marijn Kruisselbrink 2014/10/14 18:51:22 Done.
116 : GURL();
117
73 GeofencingManager::GetInstance()->UnregisterRegion( 118 GeofencingManager::GetInstance()->UnregisterRegion(
74 browser_context_, 119 browser_context_,
75 0, /* service_worker_registration_id */ 120 service_worker_registration_id,
76 GURL(), /* service_worker_origin */ 121 service_worker_origin,
77 region_id, 122 region_id,
78 base::Bind(&GeofencingDispatcherHost::UnregisterRegionCompleted, 123 base::Bind(&GeofencingDispatcherHost::UnregisterRegionCompleted,
79 weak_factory_.GetWeakPtr(), 124 weak_factory_.GetWeakPtr(),
80 thread_id, 125 thread_id,
81 request_id)); 126 request_id));
82 } 127 }
83 128
84 void GeofencingDispatcherHost::OnGetRegisteredRegions(int thread_id, 129 void GeofencingDispatcherHost::OnGetRegisteredRegions(
85 int request_id) { 130 int thread_id,
131 int request_id,
132 int64 service_worker_registration_id) {
86 GeofencingRegistrations result; 133 GeofencingRegistrations result;
87 // TODO(mek): Actually pass service worker information to manager. 134
135 // Look up service worker.
136 ServiceWorkerRegistration* service_worker_registration =
137 service_worker_context_->context()->GetLiveRegistration(
138 service_worker_registration_id);
139
140 if (!service_worker_registration) {
141 Send(new GeofencingMsg_GetRegisteredRegionsComplete(
142 thread_id,
143 request_id,
144 GeofencingStatus::GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER,
145 result));
146 return;
147 }
148
149 GURL service_worker_origin =
150 service_worker_registration
michaeln 2014/10/14 01:03:52 here too
Marijn Kruisselbrink 2014/10/14 18:51:22 Done.
151 ? service_worker_registration->pattern().GetOrigin()
152 : GURL();
153
88 GeofencingStatus status = 154 GeofencingStatus status =
89 GeofencingManager::GetInstance()->GetRegisteredRegions( 155 GeofencingManager::GetInstance()->GetRegisteredRegions(
90 browser_context_, 156 browser_context_,
91 0, /* service_worker_registration_id */ 157 service_worker_registration_id,
92 GURL(), /* service_worker_origin */ 158 service_worker_origin,
93 &result); 159 &result);
94 Send(new GeofencingMsg_GetRegisteredRegionsComplete( 160 Send(new GeofencingMsg_GetRegisteredRegionsComplete(
95 thread_id, request_id, status, result)); 161 thread_id, request_id, status, result));
96 } 162 }
97 163
98 void GeofencingDispatcherHost::RegisterRegionCompleted( 164 void GeofencingDispatcherHost::RegisterRegionCompleted(
99 int thread_id, 165 int thread_id,
100 int request_id, 166 int request_id,
101 GeofencingStatus status) { 167 GeofencingStatus status) {
102 Send(new GeofencingMsg_RegisterRegionComplete(thread_id, request_id, status)); 168 Send(new GeofencingMsg_RegisterRegionComplete(thread_id, request_id, status));
103 } 169 }
104 170
105 void GeofencingDispatcherHost::UnregisterRegionCompleted( 171 void GeofencingDispatcherHost::UnregisterRegionCompleted(
106 int thread_id, 172 int thread_id,
107 int request_id, 173 int request_id,
108 GeofencingStatus status) { 174 GeofencingStatus status) {
109 Send(new GeofencingMsg_UnregisterRegionComplete( 175 Send(new GeofencingMsg_UnregisterRegionComplete(
110 thread_id, request_id, status)); 176 thread_id, request_id, status));
111 } 177 }
112 178
113 } // namespace content 179 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698