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 "ppapi/proxy/ppb_flash_proxy.h" | 5 #include "ppapi/proxy/ppb_flash_proxy.h" |
6 | 6 |
| 7 #include <math.h> |
| 8 |
7 #include <limits> | 9 #include <limits> |
8 | 10 |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
11 #include "base/time.h" | 13 #include "base/time.h" |
12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
13 #include "ppapi/c/dev/ppb_font_dev.h" | 15 #include "ppapi/c/dev/ppb_font_dev.h" |
14 #include "ppapi/c/dev/ppb_var_deprecated.h" | 16 #include "ppapi/c/dev/ppb_var_deprecated.h" |
15 #include "ppapi/c/pp_errors.h" | 17 #include "ppapi/c/pp_errors.h" |
16 #include "ppapi/c/pp_resource.h" | 18 #include "ppapi/c/pp_resource.h" |
(...skipping 23 matching lines...) Expand all Loading... |
40 #include "ppapi/thunk/resource_creation_api.h" | 42 #include "ppapi/thunk/resource_creation_api.h" |
41 | 43 |
42 using ppapi::thunk::EnterInstanceNoLock; | 44 using ppapi::thunk::EnterInstanceNoLock; |
43 using ppapi::thunk::EnterResourceNoLock; | 45 using ppapi::thunk::EnterResourceNoLock; |
44 | 46 |
45 namespace ppapi { | 47 namespace ppapi { |
46 namespace proxy { | 48 namespace proxy { |
47 | 49 |
48 namespace { | 50 namespace { |
49 | 51 |
| 52 // Returns true if |t1| and |t2| are times in the same minute. |
| 53 bool InSameMinute(PP_Time t1, PP_Time t2) { |
| 54 return floor(t1 / 60.0) == floor(t2 / 60.0); |
| 55 } |
| 56 |
50 IPC::PlatformFileForTransit PlatformFileToPlatformFileForTransit( | 57 IPC::PlatformFileForTransit PlatformFileToPlatformFileForTransit( |
51 Dispatcher* dispatcher, | 58 Dispatcher* dispatcher, |
52 int32_t* error, | 59 int32_t* error, |
53 base::PlatformFile file) { | 60 base::PlatformFile file) { |
54 if (*error != PP_OK) | 61 if (*error != PP_OK) |
55 return IPC::InvalidPlatformFileForTransit(); | 62 return IPC::InvalidPlatformFileForTransit(); |
56 IPC::PlatformFileForTransit out_handle = | 63 IPC::PlatformFileForTransit out_handle = |
57 dispatcher->ShareHandleWithRemote(file, true); | 64 dispatcher->ShareHandleWithRemote(file, true); |
58 if (out_handle == IPC::InvalidPlatformFileForTransit()) | 65 if (out_handle == IPC::InvalidPlatformFileForTransit()) |
59 *error = PP_ERROR_NOACCESS; | 66 *error = PP_ERROR_NOACCESS; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 dispatcher()->Send(msg); | 231 dispatcher()->Send(msg); |
225 } | 232 } |
226 | 233 |
227 void PPB_Flash_Proxy::QuitMessageLoop(PP_Instance instance) { | 234 void PPB_Flash_Proxy::QuitMessageLoop(PP_Instance instance) { |
228 dispatcher()->Send(new PpapiHostMsg_PPBFlash_QuitMessageLoop( | 235 dispatcher()->Send(new PpapiHostMsg_PPBFlash_QuitMessageLoop( |
229 API_ID_PPB_FLASH, instance)); | 236 API_ID_PPB_FLASH, instance)); |
230 } | 237 } |
231 | 238 |
232 double PPB_Flash_Proxy::GetLocalTimeZoneOffset(PP_Instance instance, | 239 double PPB_Flash_Proxy::GetLocalTimeZoneOffset(PP_Instance instance, |
233 PP_Time t) { | 240 PP_Time t) { |
234 static double s_local_offset = 0.0; | 241 static double s_cached_t = 0.0; |
| 242 static double s_cached_local_offset = 0.0; |
235 static int64 s_last_updated = std::numeric_limits<int64>::min(); | 243 static int64 s_last_updated = std::numeric_limits<int64>::min(); |
236 | 244 |
237 // Cache the local offset for ten seconds, since it's slow on XP and Linux. | 245 // Cache the local offset for ten seconds, since it's slow on XP and Linux. |
238 const int64 kMaxCachedLocalOffsetAgeInSeconds = 10; | 246 const int64 kMaxCachedLocalOffsetAgeInSeconds = 10; |
239 base::TimeTicks now = base::TimeTicks::Now(); | 247 base::TimeTicks now = base::TimeTicks::Now(); |
240 base::TimeTicks expiration = | 248 base::TimeTicks expiration = |
241 base::TimeTicks::FromInternalValue(s_last_updated) + | 249 base::TimeTicks::FromInternalValue(s_last_updated) + |
242 base::TimeDelta::FromSeconds(kMaxCachedLocalOffsetAgeInSeconds); | 250 base::TimeDelta::FromSeconds(kMaxCachedLocalOffsetAgeInSeconds); |
243 if (now < expiration) | 251 // Use cached offset if cache hasn't expired and |t| is in the same minute as |
244 return s_local_offset; | 252 // the time for the cached offset (assume offsets change on minute |
| 253 // boundaries). |
| 254 if (now < expiration && InSameMinute(t, s_cached_t)) |
| 255 return s_cached_local_offset; |
245 | 256 |
| 257 s_cached_t = t; |
246 s_last_updated = now.ToInternalValue(); | 258 s_last_updated = now.ToInternalValue(); |
247 // TODO(shess): Figure out why OSX needs the access, the sandbox | 259 // TODO(shess): Figure out why OSX needs the access, the sandbox |
248 // warmup should handle it. http://crbug.com/149006 | 260 // warmup should handle it. http://crbug.com/149006 |
249 #if defined(OS_LINUX) || defined(OS_MACOSX) | 261 #if defined(OS_LINUX) || defined(OS_MACOSX) |
250 // On Linux localtime needs access to the filesystem, which is prohibited | 262 // On Linux localtime needs access to the filesystem, which is prohibited |
251 // by the sandbox. It would be better to go directly to the browser process | 263 // by the sandbox. It would be better to go directly to the browser process |
252 // for this message rather than proxy it through some instance in a renderer. | 264 // for this message rather than proxy it through some instance in a renderer. |
253 dispatcher()->Send(new PpapiHostMsg_PPBFlash_GetLocalTimeZoneOffset( | 265 dispatcher()->Send(new PpapiHostMsg_PPBFlash_GetLocalTimeZoneOffset( |
254 API_ID_PPB_FLASH, instance, t, &s_local_offset)); | 266 API_ID_PPB_FLASH, instance, t, &s_cached_local_offset)); |
255 #else | 267 #else |
256 base::Time cur = PPTimeToTime(t); | 268 base::Time cur = PPTimeToTime(t); |
257 base::Time::Exploded exploded = { 0 }; | 269 base::Time::Exploded exploded = { 0 }; |
258 base::Time::Exploded utc_exploded = { 0 }; | 270 base::Time::Exploded utc_exploded = { 0 }; |
259 cur.LocalExplode(&exploded); | 271 cur.LocalExplode(&exploded); |
260 cur.UTCExplode(&utc_exploded); | 272 cur.UTCExplode(&utc_exploded); |
261 if (exploded.HasValidValues() && utc_exploded.HasValidValues()) { | 273 if (exploded.HasValidValues() && utc_exploded.HasValidValues()) { |
262 base::Time adj_time = base::Time::FromUTCExploded(exploded); | 274 base::Time adj_time = base::Time::FromUTCExploded(exploded); |
263 base::Time cur = base::Time::FromUTCExploded(utc_exploded); | 275 base::Time cur = base::Time::FromUTCExploded(utc_exploded); |
264 s_local_offset = (adj_time - cur).InSecondsF(); | 276 s_cached_local_offset = (adj_time - cur).InSecondsF(); |
265 } else { | 277 } else { |
266 s_local_offset = 0.0; | 278 s_cached_local_offset = 0.0; |
267 } | 279 } |
268 #endif | 280 #endif |
269 | 281 |
270 return s_local_offset; | 282 return s_cached_local_offset; |
271 } | 283 } |
272 | 284 |
273 PP_Bool PPB_Flash_Proxy::IsRectTopmost(PP_Instance instance, | 285 PP_Bool PPB_Flash_Proxy::IsRectTopmost(PP_Instance instance, |
274 const PP_Rect* rect) { | 286 const PP_Rect* rect) { |
275 PP_Bool result = PP_FALSE; | 287 PP_Bool result = PP_FALSE; |
276 dispatcher()->Send(new PpapiHostMsg_PPBFlash_IsRectTopmost( | 288 dispatcher()->Send(new PpapiHostMsg_PPBFlash_IsRectTopmost( |
277 API_ID_PPB_FLASH, instance, *rect, &result)); | 289 API_ID_PPB_FLASH, instance, *rect, &result)); |
278 return result; | 290 return result; |
279 } | 291 } |
280 | 292 |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 // It's rarely used enough that we just request this interface when needed. | 893 // It's rarely used enough that we just request this interface when needed. |
882 const PPB_Flash_Print_1_0* print_interface = | 894 const PPB_Flash_Print_1_0* print_interface = |
883 static_cast<const PPB_Flash_Print_1_0*>( | 895 static_cast<const PPB_Flash_Print_1_0*>( |
884 dispatcher()->local_get_interface()(PPB_FLASH_PRINT_INTERFACE_1_0)); | 896 dispatcher()->local_get_interface()(PPB_FLASH_PRINT_INTERFACE_1_0)); |
885 if (print_interface) | 897 if (print_interface) |
886 print_interface->InvokePrinting(instance); | 898 print_interface->InvokePrinting(instance); |
887 } | 899 } |
888 | 900 |
889 } // namespace proxy | 901 } // namespace proxy |
890 } // namespace ppapi | 902 } // namespace ppapi |
OLD | NEW |