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
3 // found in the LICENSE file.
5 #include "content/browser/geofencing/geofencing_dispatcher_host.h"
7 #include "content/browser/geofencing/geofencing_manager.h"
8 #include "content/common/geofencing_messages.h"
9 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h"
14 static const int kMaxRegionIdLength
= 200;
16 GeofencingDispatcherHost::GeofencingDispatcherHost(
17 BrowserContext
* browser_context
)
18 : BrowserMessageFilter(GeofencingMsgStart
),
19 browser_context_(browser_context
),
23 GeofencingDispatcherHost::~GeofencingDispatcherHost() {
26 bool GeofencingDispatcherHost::OnMessageReceived(const IPC::Message
& message
) {
28 IPC_BEGIN_MESSAGE_MAP(GeofencingDispatcherHost
, message
)
29 IPC_MESSAGE_HANDLER(GeofencingHostMsg_RegisterRegion
, OnRegisterRegion
)
30 IPC_MESSAGE_HANDLER(GeofencingHostMsg_UnregisterRegion
, OnUnregisterRegion
)
31 IPC_MESSAGE_HANDLER(GeofencingHostMsg_GetRegisteredRegions
,
32 OnGetRegisteredRegions
)
33 IPC_MESSAGE_UNHANDLED(handled
= false)
38 void GeofencingDispatcherHost::OnRegisterRegion(
41 const std::string
& region_id
,
42 const blink::WebCircularGeofencingRegion
& region
) {
43 // Sanity check on region_id
44 if (region_id
.length() > kMaxRegionIdLength
) {
45 Send(new GeofencingMsg_RegisterRegionComplete(
46 thread_id
, request_id
, GeofencingStatus::GEOFENCING_STATUS_ERROR
));
49 // TODO(mek): Actually pass service worker information to manager.
50 GeofencingManager::GetInstance()->RegisterRegion(
52 0, /* service_worker_registration_id */
53 GURL(), /* service_worker_origin */
56 base::Bind(&GeofencingDispatcherHost::RegisterRegionCompleted
,
57 weak_factory_
.GetWeakPtr(),
62 void GeofencingDispatcherHost::OnUnregisterRegion(
65 const std::string
& region_id
) {
66 // Sanity check on region_id
67 if (region_id
.length() > kMaxRegionIdLength
) {
68 Send(new GeofencingMsg_UnregisterRegionComplete(
69 thread_id
, request_id
, GeofencingStatus::GEOFENCING_STATUS_ERROR
));
72 // TODO(mek): Actually pass service worker information to manager.
73 GeofencingManager::GetInstance()->UnregisterRegion(
75 0, /* service_worker_registration_id */
76 GURL(), /* service_worker_origin */
78 base::Bind(&GeofencingDispatcherHost::UnregisterRegionCompleted
,
79 weak_factory_
.GetWeakPtr(),
84 void GeofencingDispatcherHost::OnGetRegisteredRegions(int thread_id
,
86 GeofencingRegistrations result
;
87 // TODO(mek): Actually pass service worker information to manager.
88 GeofencingStatus status
=
89 GeofencingManager::GetInstance()->GetRegisteredRegions(
91 0, /* service_worker_registration_id */
92 GURL(), /* service_worker_origin */
94 Send(new GeofencingMsg_GetRegisteredRegionsComplete(
95 thread_id
, request_id
, status
, result
));
98 void GeofencingDispatcherHost::RegisterRegionCompleted(
101 GeofencingStatus status
) {
102 Send(new GeofencingMsg_RegisterRegionComplete(thread_id
, request_id
, status
));
105 void GeofencingDispatcherHost::UnregisterRegionCompleted(
108 GeofencingStatus status
) {
109 Send(new GeofencingMsg_UnregisterRegionComplete(
110 thread_id
, request_id
, status
));
113 } // namespace content