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/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 | 13 |
11 namespace content { | 14 namespace content { |
12 | 15 |
13 static const int kMaxRegionIdLength = 200; | 16 static const int kMaxRegionIdLength = 200; |
14 | 17 |
15 GeofencingDispatcherHost::GeofencingDispatcherHost( | 18 GeofencingDispatcherHost::GeofencingDispatcherHost( |
16 GeofencingManager* geofencing_manager) | 19 GeofencingManager* geofencing_manager) |
17 : BrowserMessageFilter(GeofencingMsgStart), | 20 : BrowserMessageFilter(GeofencingMsgStart), |
(...skipping 13 matching lines...) Expand all Loading... |
31 OnGetRegisteredRegions) | 34 OnGetRegisteredRegions) |
32 IPC_MESSAGE_UNHANDLED(handled = false) | 35 IPC_MESSAGE_UNHANDLED(handled = false) |
33 IPC_END_MESSAGE_MAP() | 36 IPC_END_MESSAGE_MAP() |
34 return handled; | 37 return handled; |
35 } | 38 } |
36 | 39 |
37 void GeofencingDispatcherHost::OnRegisterRegion( | 40 void GeofencingDispatcherHost::OnRegisterRegion( |
38 int thread_id, | 41 int thread_id, |
39 int request_id, | 42 int request_id, |
40 const std::string& region_id, | 43 const std::string& region_id, |
41 const blink::WebCircularGeofencingRegion& region) { | 44 const blink::WebCircularGeofencingRegion& region, |
| 45 int64 service_worker_registration_id) { |
42 // Sanity check on region_id | 46 // Sanity check on region_id |
43 if (region_id.length() > kMaxRegionIdLength) { | 47 if (region_id.length() > kMaxRegionIdLength) { |
44 Send(new GeofencingMsg_RegisterRegionComplete( | 48 Send(new GeofencingMsg_RegisterRegionComplete( |
45 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); | 49 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); |
46 return; | 50 return; |
47 } | 51 } |
48 // TODO(mek): Actually pass service worker information to manager. | 52 |
49 manager_->RegisterRegion( | 53 manager_->RegisterRegion( |
50 0, /* service_worker_registration_id */ | 54 service_worker_registration_id, |
51 region_id, | 55 region_id, |
52 region, | 56 region, |
53 base::Bind(&GeofencingDispatcherHost::RegisterRegionCompleted, | 57 base::Bind(&GeofencingDispatcherHost::RegisterRegionCompleted, |
54 weak_factory_.GetWeakPtr(), | 58 weak_factory_.GetWeakPtr(), |
55 thread_id, | 59 thread_id, |
56 request_id)); | 60 request_id)); |
57 } | 61 } |
58 | 62 |
59 void GeofencingDispatcherHost::OnUnregisterRegion( | 63 void GeofencingDispatcherHost::OnUnregisterRegion( |
60 int thread_id, | 64 int thread_id, |
61 int request_id, | 65 int request_id, |
62 const std::string& region_id) { | 66 const std::string& region_id, |
| 67 int64 service_worker_registration_id) { |
63 // Sanity check on region_id | 68 // Sanity check on region_id |
64 if (region_id.length() > kMaxRegionIdLength) { | 69 if (region_id.length() > kMaxRegionIdLength) { |
65 Send(new GeofencingMsg_UnregisterRegionComplete( | 70 Send(new GeofencingMsg_UnregisterRegionComplete( |
66 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); | 71 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); |
67 return; | 72 return; |
68 } | 73 } |
69 // TODO(mek): Actually pass service worker information to manager. | 74 |
70 manager_->UnregisterRegion( | 75 manager_->UnregisterRegion( |
71 0, /* service_worker_registration_id */ | 76 service_worker_registration_id, |
72 region_id, | 77 region_id, |
73 base::Bind(&GeofencingDispatcherHost::UnregisterRegionCompleted, | 78 base::Bind(&GeofencingDispatcherHost::UnregisterRegionCompleted, |
74 weak_factory_.GetWeakPtr(), | 79 weak_factory_.GetWeakPtr(), |
75 thread_id, | 80 thread_id, |
76 request_id)); | 81 request_id)); |
77 } | 82 } |
78 | 83 |
79 void GeofencingDispatcherHost::OnGetRegisteredRegions(int thread_id, | 84 void GeofencingDispatcherHost::OnGetRegisteredRegions( |
80 int request_id) { | 85 int thread_id, |
| 86 int request_id, |
| 87 int64 service_worker_registration_id) { |
81 GeofencingRegistrations result; | 88 GeofencingRegistrations result; |
82 // TODO(mek): Actually pass service worker information to manager. | 89 |
83 GeofencingStatus status = | 90 GeofencingStatus status = |
84 manager_->GetRegisteredRegions(0, /* service_worker_registration_id */ | 91 manager_->GetRegisteredRegions(service_worker_registration_id, &result); |
85 &result); | |
86 Send(new GeofencingMsg_GetRegisteredRegionsComplete( | 92 Send(new GeofencingMsg_GetRegisteredRegionsComplete( |
87 thread_id, request_id, status, result)); | 93 thread_id, request_id, status, result)); |
88 } | 94 } |
89 | 95 |
90 void GeofencingDispatcherHost::RegisterRegionCompleted( | 96 void GeofencingDispatcherHost::RegisterRegionCompleted( |
91 int thread_id, | 97 int thread_id, |
92 int request_id, | 98 int request_id, |
93 GeofencingStatus status) { | 99 GeofencingStatus status) { |
94 Send(new GeofencingMsg_RegisterRegionComplete(thread_id, request_id, status)); | 100 Send(new GeofencingMsg_RegisterRegionComplete(thread_id, request_id, status)); |
95 } | 101 } |
96 | 102 |
97 void GeofencingDispatcherHost::UnregisterRegionCompleted( | 103 void GeofencingDispatcherHost::UnregisterRegionCompleted( |
98 int thread_id, | 104 int thread_id, |
99 int request_id, | 105 int request_id, |
100 GeofencingStatus status) { | 106 GeofencingStatus status) { |
101 Send(new GeofencingMsg_UnregisterRegionComplete( | 107 Send(new GeofencingMsg_UnregisterRegionComplete( |
102 thread_id, request_id, status)); | 108 thread_id, request_id, status)); |
103 } | 109 } |
104 | 110 |
105 } // namespace content | 111 } // namespace content |
OLD | NEW |