OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/public/browser/geolocation.h" | 5 #include "content/public/browser/geolocation.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 13 #include "base/stringprintf.h" |
13 #include "content/browser/geolocation/geolocation_provider.h" | 14 #include "content/browser/geolocation/geolocation_provider.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/common/geoposition.h" | 16 #include "content/public/common/geoposition.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 void OverrideLocationForTestingOnIOThread( | 22 void OverrideLocationForTestingOnIOThread( |
22 const Geoposition& position, | 23 const Geoposition& position, |
(...skipping 21 matching lines...) Expand all Loading... |
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
45 GeolocationUpdateCallback io_thread_callback = base::Bind( | 46 GeolocationUpdateCallback io_thread_callback = base::Bind( |
46 &GeolocationUpdateCallbackOnIOThread, | 47 &GeolocationUpdateCallbackOnIOThread, |
47 client_callback, | 48 client_callback, |
48 client_loop); | 49 client_loop); |
49 GeolocationProvider::GetInstance()->RequestCallback(io_thread_callback); | 50 GeolocationProvider::GetInstance()->RequestCallback(io_thread_callback); |
50 } | 51 } |
51 | 52 |
52 } // namespace | 53 } // namespace |
53 | 54 |
| 55 |
| 56 // GeolocationPermissionRequestID --------------------------------------------- |
| 57 |
| 58 GeolocationPermissionRequestID::GeolocationPermissionRequestID( |
| 59 int render_process_id, |
| 60 int render_view_id, |
| 61 int bridge_id) |
| 62 : render_process_id(render_process_id), |
| 63 render_view_id(render_view_id), |
| 64 bridge_id(bridge_id) { |
| 65 } |
| 66 |
| 67 bool GeolocationPermissionRequestID::Equals( |
| 68 const GeolocationPermissionRequestID& other) const { |
| 69 return IsForSameTabAs(other) && (bridge_id == other.bridge_id); |
| 70 } |
| 71 |
| 72 bool GeolocationPermissionRequestID::IsForSameTabAs( |
| 73 const GeolocationPermissionRequestID& other) const { |
| 74 return (render_process_id == other.render_process_id) && |
| 75 (render_view_id == other.render_view_id); |
| 76 } |
| 77 |
| 78 std::string GeolocationPermissionRequestID::ToString() const { |
| 79 return base::StringPrintf("%d,%d,%d", render_process_id, render_view_id, |
| 80 bridge_id); |
| 81 } |
| 82 |
| 83 |
| 84 // ---------------------------------------------------------------------------- |
| 85 |
54 void OverrideLocationForTesting( | 86 void OverrideLocationForTesting( |
55 const Geoposition& position, | 87 const Geoposition& position, |
56 const base::Closure& completion_callback) { | 88 const base::Closure& completion_callback) { |
57 base::Closure closure = base::Bind(&OverrideLocationForTestingOnIOThread, | 89 base::Closure closure = base::Bind(&OverrideLocationForTestingOnIOThread, |
58 position, | 90 position, |
59 completion_callback, | 91 completion_callback, |
60 base::MessageLoopProxy::current()); | 92 base::MessageLoopProxy::current()); |
61 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) | 93 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) |
62 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure); | 94 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure); |
63 else | 95 else |
64 closure.Run(); | 96 closure.Run(); |
65 } | 97 } |
66 | 98 |
67 void RequestLocationUpdate(const GeolocationUpdateCallback& callback) { | 99 void RequestLocationUpdate(const GeolocationUpdateCallback& callback) { |
68 base::Closure closure = base::Bind(&RequestLocationUpdateOnIOThread, | 100 base::Closure closure = base::Bind(&RequestLocationUpdateOnIOThread, |
69 callback, | 101 callback, |
70 base::MessageLoopProxy::current()); | 102 base::MessageLoopProxy::current()); |
71 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) | 103 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) |
72 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure); | 104 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, closure); |
73 else | 105 else |
74 closure.Run(); | 106 closure.Run(); |
75 } | 107 } |
76 | 108 |
77 } // namespace content | 109 } // namespace content |
OLD | NEW |