| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "content/browser/geofencing/geofencing_dispatcher_host.h" | |
| 6 | |
| 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" | |
| 11 #include "content/common/geofencing_messages.h" | |
| 12 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 static const int kMaxRegionIdLength = 200; | |
| 17 | |
| 18 GeofencingDispatcherHost::GeofencingDispatcherHost( | |
| 19 GeofencingManager* geofencing_manager) | |
| 20 : BrowserMessageFilter(GeofencingMsgStart), | |
| 21 manager_(geofencing_manager), | |
| 22 weak_factory_(this) { | |
| 23 } | |
| 24 | |
| 25 GeofencingDispatcherHost::~GeofencingDispatcherHost() { | |
| 26 } | |
| 27 | |
| 28 bool GeofencingDispatcherHost::OnMessageReceived(const IPC::Message& message) { | |
| 29 bool handled = true; | |
| 30 IPC_BEGIN_MESSAGE_MAP(GeofencingDispatcherHost, message) | |
| 31 IPC_MESSAGE_HANDLER(GeofencingHostMsg_RegisterRegion, OnRegisterRegion) | |
| 32 IPC_MESSAGE_HANDLER(GeofencingHostMsg_UnregisterRegion, OnUnregisterRegion) | |
| 33 IPC_MESSAGE_HANDLER(GeofencingHostMsg_GetRegisteredRegions, | |
| 34 OnGetRegisteredRegions) | |
| 35 IPC_MESSAGE_FORWARD(GeofencingHostMsg_SetMockProvider, manager_.get(), | |
| 36 GeofencingManager::SetMockProvider) | |
| 37 IPC_MESSAGE_FORWARD(GeofencingHostMsg_SetMockPosition, manager_.get(), | |
| 38 GeofencingManager::SetMockPosition) | |
| 39 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 40 IPC_END_MESSAGE_MAP() | |
| 41 return handled; | |
| 42 } | |
| 43 | |
| 44 void GeofencingDispatcherHost::OnRegisterRegion( | |
| 45 int thread_id, | |
| 46 int request_id, | |
| 47 const std::string& region_id, | |
| 48 const blink::WebCircularGeofencingRegion& region, | |
| 49 int64_t service_worker_registration_id) { | |
| 50 // Sanity check on region_id | |
| 51 if (region_id.length() > kMaxRegionIdLength) { | |
| 52 Send(new GeofencingMsg_RegisterRegionComplete( | |
| 53 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); | |
| 54 return; | |
| 55 } | |
| 56 | |
| 57 manager_->RegisterRegion( | |
| 58 service_worker_registration_id, | |
| 59 region_id, | |
| 60 region, | |
| 61 base::Bind(&GeofencingDispatcherHost::RegisterRegionCompleted, | |
| 62 weak_factory_.GetWeakPtr(), | |
| 63 thread_id, | |
| 64 request_id)); | |
| 65 } | |
| 66 | |
| 67 void GeofencingDispatcherHost::OnUnregisterRegion( | |
| 68 int thread_id, | |
| 69 int request_id, | |
| 70 const std::string& region_id, | |
| 71 int64_t service_worker_registration_id) { | |
| 72 // Sanity check on region_id | |
| 73 if (region_id.length() > kMaxRegionIdLength) { | |
| 74 Send(new GeofencingMsg_UnregisterRegionComplete( | |
| 75 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); | |
| 76 return; | |
| 77 } | |
| 78 | |
| 79 manager_->UnregisterRegion( | |
| 80 service_worker_registration_id, | |
| 81 region_id, | |
| 82 base::Bind(&GeofencingDispatcherHost::UnregisterRegionCompleted, | |
| 83 weak_factory_.GetWeakPtr(), | |
| 84 thread_id, | |
| 85 request_id)); | |
| 86 } | |
| 87 | |
| 88 void GeofencingDispatcherHost::OnGetRegisteredRegions( | |
| 89 int thread_id, | |
| 90 int request_id, | |
| 91 int64_t service_worker_registration_id) { | |
| 92 GeofencingRegistrations result; | |
| 93 | |
| 94 GeofencingStatus status = | |
| 95 manager_->GetRegisteredRegions(service_worker_registration_id, &result); | |
| 96 Send(new GeofencingMsg_GetRegisteredRegionsComplete( | |
| 97 thread_id, request_id, status, result)); | |
| 98 } | |
| 99 | |
| 100 void GeofencingDispatcherHost::RegisterRegionCompleted( | |
| 101 int thread_id, | |
| 102 int request_id, | |
| 103 GeofencingStatus status) { | |
| 104 Send(new GeofencingMsg_RegisterRegionComplete(thread_id, request_id, status)); | |
| 105 } | |
| 106 | |
| 107 void GeofencingDispatcherHost::UnregisterRegionCompleted( | |
| 108 int thread_id, | |
| 109 int request_id, | |
| 110 GeofencingStatus status) { | |
| 111 Send(new GeofencingMsg_UnregisterRegionComplete( | |
| 112 thread_id, request_id, status)); | |
| 113 } | |
| 114 | |
| 115 } // namespace content | |
| OLD | NEW |