Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: content/browser/geofencing/geofencing_dispatcher_host.cc

Issue 586163003: Basic implementation of GeofencingManager class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@geofencing5
Patch Set: minor cleanup Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/geofencing_messages.h" 8 #include "content/common/geofencing_messages.h"
8 #include "content/common/geofencing_status.h"
9 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h" 9 #include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h"
10 #include "url/gurl.h"
10 11
11 namespace content { 12 namespace content {
12 13
13 static const int kMaxRegionIdLength = 200; 14 static const int kMaxRegionIdLength = 200;
14 15
15 GeofencingDispatcherHost::GeofencingDispatcherHost() 16 GeofencingDispatcherHost::GeofencingDispatcherHost(
16 : BrowserMessageFilter(GeofencingMsgStart) { 17 BrowserContext* browser_context)
18 : BrowserMessageFilter(GeofencingMsgStart),
19 browser_context_(browser_context),
20 weak_factory_(this) {
17 } 21 }
18 22
19 GeofencingDispatcherHost::~GeofencingDispatcherHost() { 23 GeofencingDispatcherHost::~GeofencingDispatcherHost() {
20 } 24 }
21 25
22 bool GeofencingDispatcherHost::OnMessageReceived(const IPC::Message& message) { 26 bool GeofencingDispatcherHost::OnMessageReceived(const IPC::Message& message) {
23 bool handled = true; 27 bool handled = true;
24 IPC_BEGIN_MESSAGE_MAP(GeofencingDispatcherHost, message) 28 IPC_BEGIN_MESSAGE_MAP(GeofencingDispatcherHost, message)
25 IPC_MESSAGE_HANDLER(GeofencingHostMsg_RegisterRegion, OnRegisterRegion) 29 IPC_MESSAGE_HANDLER(GeofencingHostMsg_RegisterRegion, OnRegisterRegion)
26 IPC_MESSAGE_HANDLER(GeofencingHostMsg_UnregisterRegion, OnUnregisterRegion) 30 IPC_MESSAGE_HANDLER(GeofencingHostMsg_UnregisterRegion, OnUnregisterRegion)
27 IPC_MESSAGE_HANDLER(GeofencingHostMsg_GetRegisteredRegions, 31 IPC_MESSAGE_HANDLER(GeofencingHostMsg_GetRegisteredRegions,
28 OnGetRegisteredRegions) 32 OnGetRegisteredRegions)
29 IPC_MESSAGE_UNHANDLED(handled = false) 33 IPC_MESSAGE_UNHANDLED(handled = false)
30 IPC_END_MESSAGE_MAP() 34 IPC_END_MESSAGE_MAP()
31 return handled; 35 return handled;
32 } 36 }
33 37
34 void GeofencingDispatcherHost::OnRegisterRegion( 38 void GeofencingDispatcherHost::OnRegisterRegion(
35 int thread_id, 39 int thread_id,
36 int request_id, 40 int request_id,
37 const std::string& region_id, 41 const std::string& region_id,
38 const blink::WebCircularGeofencingRegion& region) { 42 const blink::WebCircularGeofencingRegion& region) {
39 // Sanity check on region_id 43 // Sanity check on region_id
40 if (region_id.length() > kMaxRegionIdLength) { 44 if (region_id.length() > kMaxRegionIdLength) {
41 Send(new GeofencingMsg_RegisterRegionComplete( 45 Send(new GeofencingMsg_RegisterRegionComplete(
42 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); 46 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR));
43 return; 47 return;
44 } 48 }
45 // TODO(mek): Handle registration request. 49 // TODO(mek): Actually pass service worker information to manager.
46 Send(new GeofencingMsg_RegisterRegionComplete( 50 GeofencingManager::GetInstance()->RegisterRegion(
47 thread_id, 51 browser_context_,
48 request_id, 52 0, /* service_worker_registration_id */
49 GeofencingStatus:: 53 GURL(), /* service_worker_origin */
50 GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE)); 54 region_id,
55 region,
56 base::Bind(&GeofencingDispatcherHost::RegisterRegionCompleted,
57 weak_factory_.GetWeakPtr(),
58 thread_id,
59 request_id));
51 } 60 }
52 61
53 void GeofencingDispatcherHost::OnUnregisterRegion( 62 void GeofencingDispatcherHost::OnUnregisterRegion(
54 int thread_id, 63 int thread_id,
55 int request_id, 64 int request_id,
56 const std::string& region_id) { 65 const std::string& region_id) {
57 // Sanity check on region_id 66 // Sanity check on region_id
58 if (region_id.length() > kMaxRegionIdLength) { 67 if (region_id.length() > kMaxRegionIdLength) {
59 Send(new GeofencingMsg_UnregisterRegionComplete( 68 Send(new GeofencingMsg_UnregisterRegionComplete(
60 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); 69 thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR));
61 return; 70 return;
62 } 71 }
63 // TODO(mek): Handle unregistration request. 72 // TODO(mek): Actually pass service worker information to manager.
64 Send(new GeofencingMsg_UnregisterRegionComplete( 73 GeofencingManager::GetInstance()->UnregisterRegion(
65 thread_id, 74 browser_context_,
66 request_id, 75 0, /* service_worker_registration_id */
67 GeofencingStatus:: 76 GURL(), /* service_worker_origin */
68 GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE)); 77 region_id,
78 base::Bind(&GeofencingDispatcherHost::UnregisterRegionCompleted,
79 weak_factory_.GetWeakPtr(),
80 thread_id,
81 request_id));
69 } 82 }
70 83
71 void GeofencingDispatcherHost::OnGetRegisteredRegions(int thread_id, 84 void GeofencingDispatcherHost::OnGetRegisteredRegions(int thread_id,
72 int request_id) { 85 int request_id) {
73 GeofencingRegistrations result; 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);
74 Send(new GeofencingMsg_GetRegisteredRegionsComplete( 94 Send(new GeofencingMsg_GetRegisteredRegionsComplete(
75 thread_id, 95 thread_id, request_id, status, result));
76 request_id, 96 }
77 GeofencingStatus:: 97
78 GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE, 98 void GeofencingDispatcherHost::RegisterRegionCompleted(
79 result)); 99 int thread_id,
100 int request_id,
101 GeofencingStatus status) {
102 Send(new GeofencingMsg_RegisterRegionComplete(thread_id, request_id, status));
103 }
104
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));
80 } 111 }
81 112
82 } // namespace content 113 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geofencing/geofencing_dispatcher_host.h ('k') | content/browser/geofencing/geofencing_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698