cc: Make picture pile base thread safe.
[chromium-blink-merge.git] / content / browser / geofencing / geofencing_dispatcher_host.cc
blob5cae1136bc98afa4b8ae41cf5b22c2669524781d
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/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"
14 namespace content {
16 static const int kMaxRegionIdLength = 200;
18 GeofencingDispatcherHost::GeofencingDispatcherHost(
19 GeofencingManager* geofencing_manager)
20 : BrowserMessageFilter(GeofencingMsgStart),
21 manager_(geofencing_manager),
22 weak_factory_(this) {
25 GeofencingDispatcherHost::~GeofencingDispatcherHost() {
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_UNHANDLED(handled = false)
36 IPC_END_MESSAGE_MAP()
37 return handled;
40 void GeofencingDispatcherHost::OnRegisterRegion(
41 int thread_id,
42 int request_id,
43 const std::string& region_id,
44 const blink::WebCircularGeofencingRegion& region,
45 int64 service_worker_registration_id) {
46 // Sanity check on region_id
47 if (region_id.length() > kMaxRegionIdLength) {
48 Send(new GeofencingMsg_RegisterRegionComplete(
49 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR));
50 return;
53 manager_->RegisterRegion(
54 service_worker_registration_id,
55 region_id,
56 region,
57 base::Bind(&GeofencingDispatcherHost::RegisterRegionCompleted,
58 weak_factory_.GetWeakPtr(),
59 thread_id,
60 request_id));
63 void GeofencingDispatcherHost::OnUnregisterRegion(
64 int thread_id,
65 int request_id,
66 const std::string& region_id,
67 int64 service_worker_registration_id) {
68 // Sanity check on region_id
69 if (region_id.length() > kMaxRegionIdLength) {
70 Send(new GeofencingMsg_UnregisterRegionComplete(
71 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR));
72 return;
75 manager_->UnregisterRegion(
76 service_worker_registration_id,
77 region_id,
78 base::Bind(&GeofencingDispatcherHost::UnregisterRegionCompleted,
79 weak_factory_.GetWeakPtr(),
80 thread_id,
81 request_id));
84 void GeofencingDispatcherHost::OnGetRegisteredRegions(
85 int thread_id,
86 int request_id,
87 int64 service_worker_registration_id) {
88 GeofencingRegistrations result;
90 GeofencingStatus status =
91 manager_->GetRegisteredRegions(service_worker_registration_id, &result);
92 Send(new GeofencingMsg_GetRegisteredRegionsComplete(
93 thread_id, request_id, status, result));
96 void GeofencingDispatcherHost::RegisterRegionCompleted(
97 int thread_id,
98 int request_id,
99 GeofencingStatus status) {
100 Send(new GeofencingMsg_RegisterRegionComplete(thread_id, request_id, status));
103 void GeofencingDispatcherHost::UnregisterRegionCompleted(
104 int thread_id,
105 int request_id,
106 GeofencingStatus status) {
107 Send(new GeofencingMsg_UnregisterRegionComplete(
108 thread_id, request_id, status));
111 } // namespace content