| OLD | NEW |
| 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/common/geofencing_messages.h" | 8 #include "content/common/geofencing_messages.h" |
| 9 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h" | 9 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h" |
| 10 #include "url/gurl.h" | |
| 11 | 10 |
| 12 namespace content { | 11 namespace content { |
| 13 | 12 |
| 14 static const int kMaxRegionIdLength = 200; | 13 static const int kMaxRegionIdLength = 200; |
| 15 | 14 |
| 16 GeofencingDispatcherHost::GeofencingDispatcherHost( | 15 GeofencingDispatcherHost::GeofencingDispatcherHost( |
| 17 BrowserContext* browser_context) | 16 GeofencingManager* geofencing_manager) |
| 18 : BrowserMessageFilter(GeofencingMsgStart), | 17 : BrowserMessageFilter(GeofencingMsgStart), |
| 19 browser_context_(browser_context), | 18 manager_(geofencing_manager), |
| 20 weak_factory_(this) { | 19 weak_factory_(this) { |
| 21 } | 20 } |
| 22 | 21 |
| 23 GeofencingDispatcherHost::~GeofencingDispatcherHost() { | 22 GeofencingDispatcherHost::~GeofencingDispatcherHost() { |
| 24 } | 23 } |
| 25 | 24 |
| 26 bool GeofencingDispatcherHost::OnMessageReceived(const IPC::Message& message) { | 25 bool GeofencingDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
| 27 bool handled = true; | 26 bool handled = true; |
| 28 IPC_BEGIN_MESSAGE_MAP(GeofencingDispatcherHost, message) | 27 IPC_BEGIN_MESSAGE_MAP(GeofencingDispatcherHost, message) |
| 29 IPC_MESSAGE_HANDLER(GeofencingHostMsg_RegisterRegion, OnRegisterRegion) | 28 IPC_MESSAGE_HANDLER(GeofencingHostMsg_RegisterRegion, OnRegisterRegion) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 40 int request_id, | 39 int request_id, |
| 41 const std::string& region_id, | 40 const std::string& region_id, |
| 42 const blink::WebCircularGeofencingRegion& region) { | 41 const blink::WebCircularGeofencingRegion& region) { |
| 43 // Sanity check on region_id | 42 // Sanity check on region_id |
| 44 if (region_id.length() > kMaxRegionIdLength) { | 43 if (region_id.length() > kMaxRegionIdLength) { |
| 45 Send(new GeofencingMsg_RegisterRegionComplete( | 44 Send(new GeofencingMsg_RegisterRegionComplete( |
| 46 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); | 45 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); |
| 47 return; | 46 return; |
| 48 } | 47 } |
| 49 // TODO(mek): Actually pass service worker information to manager. | 48 // TODO(mek): Actually pass service worker information to manager. |
| 50 GeofencingManager::GetInstance()->RegisterRegion( | 49 manager_->RegisterRegion( |
| 51 browser_context_, | 50 0, /* service_worker_registration_id */ |
| 52 0, /* service_worker_registration_id */ | |
| 53 GURL(), /* service_worker_origin */ | |
| 54 region_id, | 51 region_id, |
| 55 region, | 52 region, |
| 56 base::Bind(&GeofencingDispatcherHost::RegisterRegionCompleted, | 53 base::Bind(&GeofencingDispatcherHost::RegisterRegionCompleted, |
| 57 weak_factory_.GetWeakPtr(), | 54 weak_factory_.GetWeakPtr(), |
| 58 thread_id, | 55 thread_id, |
| 59 request_id)); | 56 request_id)); |
| 60 } | 57 } |
| 61 | 58 |
| 62 void GeofencingDispatcherHost::OnUnregisterRegion( | 59 void GeofencingDispatcherHost::OnUnregisterRegion( |
| 63 int thread_id, | 60 int thread_id, |
| 64 int request_id, | 61 int request_id, |
| 65 const std::string& region_id) { | 62 const std::string& region_id) { |
| 66 // Sanity check on region_id | 63 // Sanity check on region_id |
| 67 if (region_id.length() > kMaxRegionIdLength) { | 64 if (region_id.length() > kMaxRegionIdLength) { |
| 68 Send(new GeofencingMsg_UnregisterRegionComplete( | 65 Send(new GeofencingMsg_UnregisterRegionComplete( |
| 69 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); | 66 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); |
| 70 return; | 67 return; |
| 71 } | 68 } |
| 72 // TODO(mek): Actually pass service worker information to manager. | 69 // TODO(mek): Actually pass service worker information to manager. |
| 73 GeofencingManager::GetInstance()->UnregisterRegion( | 70 manager_->UnregisterRegion( |
| 74 browser_context_, | 71 0, /* service_worker_registration_id */ |
| 75 0, /* service_worker_registration_id */ | |
| 76 GURL(), /* service_worker_origin */ | |
| 77 region_id, | 72 region_id, |
| 78 base::Bind(&GeofencingDispatcherHost::UnregisterRegionCompleted, | 73 base::Bind(&GeofencingDispatcherHost::UnregisterRegionCompleted, |
| 79 weak_factory_.GetWeakPtr(), | 74 weak_factory_.GetWeakPtr(), |
| 80 thread_id, | 75 thread_id, |
| 81 request_id)); | 76 request_id)); |
| 82 } | 77 } |
| 83 | 78 |
| 84 void GeofencingDispatcherHost::OnGetRegisteredRegions(int thread_id, | 79 void GeofencingDispatcherHost::OnGetRegisteredRegions(int thread_id, |
| 85 int request_id) { | 80 int request_id) { |
| 86 GeofencingRegistrations result; | 81 GeofencingRegistrations result; |
| 87 // TODO(mek): Actually pass service worker information to manager. | 82 // TODO(mek): Actually pass service worker information to manager. |
| 88 GeofencingStatus status = | 83 GeofencingStatus status = |
| 89 GeofencingManager::GetInstance()->GetRegisteredRegions( | 84 manager_->GetRegisteredRegions(0, /* service_worker_registration_id */ |
| 90 browser_context_, | 85 &result); |
| 91 0, /* service_worker_registration_id */ | |
| 92 GURL(), /* service_worker_origin */ | |
| 93 &result); | |
| 94 Send(new GeofencingMsg_GetRegisteredRegionsComplete( | 86 Send(new GeofencingMsg_GetRegisteredRegionsComplete( |
| 95 thread_id, request_id, status, result)); | 87 thread_id, request_id, status, result)); |
| 96 } | 88 } |
| 97 | 89 |
| 98 void GeofencingDispatcherHost::RegisterRegionCompleted( | 90 void GeofencingDispatcherHost::RegisterRegionCompleted( |
| 99 int thread_id, | 91 int thread_id, |
| 100 int request_id, | 92 int request_id, |
| 101 GeofencingStatus status) { | 93 GeofencingStatus status) { |
| 102 Send(new GeofencingMsg_RegisterRegionComplete(thread_id, request_id, status)); | 94 Send(new GeofencingMsg_RegisterRegionComplete(thread_id, request_id, status)); |
| 103 } | 95 } |
| 104 | 96 |
| 105 void GeofencingDispatcherHost::UnregisterRegionCompleted( | 97 void GeofencingDispatcherHost::UnregisterRegionCompleted( |
| 106 int thread_id, | 98 int thread_id, |
| 107 int request_id, | 99 int request_id, |
| 108 GeofencingStatus status) { | 100 GeofencingStatus status) { |
| 109 Send(new GeofencingMsg_UnregisterRegionComplete( | 101 Send(new GeofencingMsg_UnregisterRegionComplete( |
| 110 thread_id, request_id, status)); | 102 thread_id, request_id, status)); |
| 111 } | 103 } |
| 112 | 104 |
| 113 } // namespace content | 105 } // namespace content |
| OLD | NEW |