Chromecast: extracts Linux window creation code to a common place.
[chromium-blink-merge.git] / content / browser / geofencing / geofencing_dispatcher_host.cc
blob077485b38f6a31407c7dc2400408c09bce9bcd31
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"
10 #include "url/gurl.h"
12 namespace content {
14 static const int kMaxRegionIdLength = 200;
16 GeofencingDispatcherHost::GeofencingDispatcherHost(
17 BrowserContext* browser_context)
18 : BrowserMessageFilter(GeofencingMsgStart),
19 browser_context_(browser_context),
20 weak_factory_(this) {
23 GeofencingDispatcherHost::~GeofencingDispatcherHost() {
26 bool GeofencingDispatcherHost::OnMessageReceived(const IPC::Message& message) {
27 bool handled = true;
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)
34 IPC_END_MESSAGE_MAP()
35 return handled;
38 void GeofencingDispatcherHost::OnRegisterRegion(
39 int thread_id,
40 int request_id,
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));
47 return;
49 // TODO(mek): Actually pass service worker information to manager.
50 GeofencingManager::GetInstance()->RegisterRegion(
51 browser_context_,
52 0, /* service_worker_registration_id */
53 GURL(), /* service_worker_origin */
54 region_id,
55 region,
56 base::Bind(&GeofencingDispatcherHost::RegisterRegionCompleted,
57 weak_factory_.GetWeakPtr(),
58 thread_id,
59 request_id));
62 void GeofencingDispatcherHost::OnUnregisterRegion(
63 int thread_id,
64 int request_id,
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));
70 return;
72 // TODO(mek): Actually pass service worker information to manager.
73 GeofencingManager::GetInstance()->UnregisterRegion(
74 browser_context_,
75 0, /* service_worker_registration_id */
76 GURL(), /* service_worker_origin */
77 region_id,
78 base::Bind(&GeofencingDispatcherHost::UnregisterRegionCompleted,
79 weak_factory_.GetWeakPtr(),
80 thread_id,
81 request_id));
84 void GeofencingDispatcherHost::OnGetRegisteredRegions(int thread_id,
85 int request_id) {
86 GeofencingRegistrations result;
87 // TODO(mek): Actually pass service worker information to manager.
88 GeofencingStatus status =
89 GeofencingManager::GetInstance()->GetRegisteredRegions(
90 browser_context_,
91 0, /* service_worker_registration_id */
92 GURL(), /* service_worker_origin */
93 &result);
94 Send(new GeofencingMsg_GetRegisteredRegionsComplete(
95 thread_id, request_id, status, result));
98 void GeofencingDispatcherHost::RegisterRegionCompleted(
99 int thread_id,
100 int request_id,
101 GeofencingStatus status) {
102 Send(new GeofencingMsg_RegisterRegionComplete(thread_id, request_id, status));
105 void GeofencingDispatcherHost::UnregisterRegionCompleted(
106 int thread_id,
107 int request_id,
108 GeofencingStatus status) {
109 Send(new GeofencingMsg_UnregisterRegionComplete(
110 thread_id, request_id, status));
113 } // namespace content