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

Side by Side Diff: chrome/browser/renderer_host/pepper/pepper_flash_browser_host.cc

Issue 2388313004: Flash: Use better APIs for preventing sleep (Closed)
Patch Set: Use DelayTimer Created 4 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
« no previous file with comments | « chrome/browser/renderer_host/pepper/pepper_flash_browser_host.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/renderer_host/pepper/pepper_flash_browser_host.h" 5 #include "chrome/browser/renderer_host/pepper/pepper_flash_browser_host.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/browser/content_settings/cookie_settings_factory.h" 9 #include "chrome/browser/content_settings/cookie_settings_factory.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "components/content_settings/core/browser/cookie_settings.h" 11 #include "components/content_settings/core/browser/cookie_settings.h"
12 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_ppapi_host.h" 13 #include "content/public/browser/browser_ppapi_host.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/render_process_host.h" 15 #include "content/public/browser/render_process_host.h"
16 #include "device/power_save_blocker/power_save_blocker.h"
16 #include "ipc/ipc_message_macros.h" 17 #include "ipc/ipc_message_macros.h"
17 #include "ppapi/c/pp_errors.h" 18 #include "ppapi/c/pp_errors.h"
18 #include "ppapi/c/private/ppb_flash.h" 19 #include "ppapi/c/private/ppb_flash.h"
19 #include "ppapi/host/dispatch_host_message.h" 20 #include "ppapi/host/dispatch_host_message.h"
20 #include "ppapi/proxy/ppapi_messages.h" 21 #include "ppapi/proxy/ppapi_messages.h"
21 #include "ppapi/proxy/resource_message_params.h" 22 #include "ppapi/proxy/resource_message_params.h"
22 #include "ppapi/shared_impl/time_conversion.h" 23 #include "ppapi/shared_impl/time_conversion.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 25
25 #if defined(OS_WIN) 26 #if defined(OS_WIN)
(...skipping 24 matching lines...) Expand all
50 return NULL; 51 return NULL;
51 } 52 }
52 53
53 } // namespace 54 } // namespace
54 55
55 PepperFlashBrowserHost::PepperFlashBrowserHost(BrowserPpapiHost* host, 56 PepperFlashBrowserHost::PepperFlashBrowserHost(BrowserPpapiHost* host,
56 PP_Instance instance, 57 PP_Instance instance,
57 PP_Resource resource) 58 PP_Resource resource)
58 : ResourceHost(host->GetPpapiHost(), instance, resource), 59 : ResourceHost(host->GetPpapiHost(), instance, resource),
59 host_(host), 60 host_(host),
61 delay_timer_(FROM_HERE, base::TimeDelta::FromSeconds(45), this,
62 &PepperFlashBrowserHost::OnDelayTimerFired),
60 weak_factory_(this) { 63 weak_factory_(this) {
61 int unused; 64 int unused;
62 host->GetRenderFrameIDsForInstance(instance, &render_process_id_, &unused); 65 host->GetRenderFrameIDsForInstance(instance, &render_process_id_, &unused);
63 } 66 }
64 67
65 PepperFlashBrowserHost::~PepperFlashBrowserHost() {} 68 PepperFlashBrowserHost::~PepperFlashBrowserHost() {}
66 69
67 int32_t PepperFlashBrowserHost::OnResourceMessageReceived( 70 int32_t PepperFlashBrowserHost::OnResourceMessageReceived(
68 const IPC::Message& msg, 71 const IPC::Message& msg,
69 ppapi::host::HostMessageContext* context) { 72 ppapi::host::HostMessageContext* context) {
70 PPAPI_BEGIN_MESSAGE_MAP(PepperFlashBrowserHost, msg) 73 PPAPI_BEGIN_MESSAGE_MAP(PepperFlashBrowserHost, msg)
71 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_UpdateActivity, 74 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_UpdateActivity,
72 OnUpdateActivity) 75 OnUpdateActivity)
73 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_GetLocalTimeZoneOffset, 76 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_GetLocalTimeZoneOffset,
74 OnGetLocalTimeZoneOffset) 77 OnGetLocalTimeZoneOffset)
75 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( 78 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
76 PpapiHostMsg_Flash_GetLocalDataRestrictions, OnGetLocalDataRestrictions) 79 PpapiHostMsg_Flash_GetLocalDataRestrictions, OnGetLocalDataRestrictions)
77 PPAPI_END_MESSAGE_MAP() 80 PPAPI_END_MESSAGE_MAP()
78 return PP_ERROR_FAILED; 81 return PP_ERROR_FAILED;
79 } 82 }
80 83
84 void PepperFlashBrowserHost::OnDelayTimerFired() {
85 power_save_blocker_.reset();
86 }
87
81 int32_t PepperFlashBrowserHost::OnUpdateActivity( 88 int32_t PepperFlashBrowserHost::OnUpdateActivity(
82 ppapi::host::HostMessageContext* host_context) { 89 ppapi::host::HostMessageContext* host_context) {
83 #if defined(OS_WIN) 90 if (!power_save_blocker_) {
84 // Reading then writing back the same value to the screensaver timeout system 91 power_save_blocker_.reset(new device::PowerSaveBlocker(
85 // setting resets the countdown which prevents the screensaver from turning 92 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
86 // on "for a while". As long as the plugin pings us with this message faster 93 device::PowerSaveBlocker::kReasonOther, "Requested By PepperFlash",
87 // than the screensaver timeout, it won't go on. 94 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI),
88 int value = 0; 95 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)));
89 if (SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &value, 0)) 96 }
90 SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, value, NULL, 0); 97 // There is no specification for how long OnUpdateActivity should prevent the
91 #elif defined(OS_MACOSX) 98 // screen from going to sleep. Empirically, twitch.tv calls this method every
92 UpdateSystemActivity(OverallAct); 99 // 10 seconds. Be conservative and allow 45 seconds (set in |delay_timer_|'s
93 #else 100 // ctor) before deleting the block.
94 // TODO(brettw) implement this for other platforms. 101 delay_timer_.Reset();
95 #endif
96 return PP_OK; 102 return PP_OK;
97 } 103 }
98 104
99 int32_t PepperFlashBrowserHost::OnGetLocalTimeZoneOffset( 105 int32_t PepperFlashBrowserHost::OnGetLocalTimeZoneOffset(
100 ppapi::host::HostMessageContext* host_context, 106 ppapi::host::HostMessageContext* host_context,
101 const base::Time& t) { 107 const base::Time& t) {
102 // The reason for this processing being in the browser process is that on 108 // The reason for this processing being in the browser process is that on
103 // Linux, the localtime calls require filesystem access prohibited by the 109 // Linux, the localtime calls require filesystem access prohibited by the
104 // sandbox. 110 // sandbox.
105 host_context->reply_msg = PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply( 111 host_context->reply_msg = PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 restrictions = PP_FLASHLSORESTRICTIONS_BLOCK; 163 restrictions = PP_FLASHLSORESTRICTIONS_BLOCK;
158 else if (cookie_settings_->IsCookieSessionOnly(plugin_url)) 164 else if (cookie_settings_->IsCookieSessionOnly(plugin_url))
159 restrictions = PP_FLASHLSORESTRICTIONS_IN_MEMORY; 165 restrictions = PP_FLASHLSORESTRICTIONS_IN_MEMORY;
160 } 166 }
161 SendReply(reply_context, 167 SendReply(reply_context,
162 PpapiPluginMsg_Flash_GetLocalDataRestrictionsReply( 168 PpapiPluginMsg_Flash_GetLocalDataRestrictionsReply(
163 static_cast<int32_t>(restrictions))); 169 static_cast<int32_t>(restrictions)));
164 } 170 }
165 171
166 } // namespace chrome 172 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/pepper/pepper_flash_browser_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698