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

Side by Side Diff: chrome/renderer/extensions/extension_dispatcher.cc

Issue 8463019: Convert render thread idle delays from seconds to milliseconds. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/renderer/extensions/extension_dispatcher.h" 5 #include "chrome/renderer/extensions/extension_dispatcher.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/common/child_process_logging.h" 8 #include "chrome/common/child_process_logging.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
(...skipping 14 matching lines...) Expand all
25 #include "content/public/renderer/render_thread.h" 25 #include "content/public/renderer/render_thread.h"
26 #include "grit/renderer_resources.h" 26 #include "grit/renderer_resources.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
32 #include "v8/include/v8.h" 32 #include "v8/include/v8.h"
33 33
34 namespace { 34 namespace {
35 static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */; 35 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000 /* ms */;
jam 2011/11/11 18:10:10 nit, the "/* ms */" is redundant since Ms is in th
36 static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */; 36 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000 /* ms */;
37 } 37 }
38 38
39 using WebKit::WebDataSource; 39 using WebKit::WebDataSource;
40 using WebKit::WebFrame; 40 using WebKit::WebFrame;
41 using WebKit::WebSecurityPolicy; 41 using WebKit::WebSecurityPolicy;
42 using WebKit::WebString; 42 using WebKit::WebString;
43 using content::RenderThread; 43 using content::RenderThread;
44 44
45 ExtensionDispatcher::ExtensionDispatcher() 45 ExtensionDispatcher::ExtensionDispatcher()
46 : is_webkit_initialized_(false), 46 : is_webkit_initialized_(false),
47 webrequest_adblock_(false), 47 webrequest_adblock_(false),
48 webrequest_adblock_plus_(false), 48 webrequest_adblock_plus_(false),
49 webrequest_other_(false) { 49 webrequest_other_(false) {
50 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); 50 const CommandLine& command_line = *(CommandLine::ForCurrentProcess());
51 is_extension_process_ = 51 is_extension_process_ =
52 command_line.HasSwitch(switches::kExtensionProcess) || 52 command_line.HasSwitch(switches::kExtensionProcess) ||
53 command_line.HasSwitch(switches::kSingleProcess); 53 command_line.HasSwitch(switches::kSingleProcess);
54 54
55 if (is_extension_process_) { 55 if (is_extension_process_) {
56 RenderThread::Get()->SetIdleNotificationDelayInS( 56 RenderThread::Get()->SetIdleNotificationDelayInMs(
57 kInitialExtensionIdleHandlerDelayS); 57 kInitialExtensionIdleHandlerDelayMs);
58 } 58 }
59 59
60 user_script_slave_.reset(new UserScriptSlave(&extensions_)); 60 user_script_slave_.reset(new UserScriptSlave(&extensions_));
61 } 61 }
62 62
63 ExtensionDispatcher::~ExtensionDispatcher() { 63 ExtensionDispatcher::~ExtensionDispatcher() {
64 } 64 }
65 65
66 bool ExtensionDispatcher::OnControlMessageReceived( 66 bool ExtensionDispatcher::OnControlMessageReceived(
67 const IPC::Message& message) { 67 const IPC::Message& message) {
(...skipping 15 matching lines...) Expand all
83 IPC_END_MESSAGE_MAP() 83 IPC_END_MESSAGE_MAP()
84 84
85 return handled; 85 return handled;
86 } 86 }
87 87
88 void ExtensionDispatcher::WebKitInitialized() { 88 void ExtensionDispatcher::WebKitInitialized() {
89 // For extensions, we want to ensure we call the IdleHandler every so often, 89 // For extensions, we want to ensure we call the IdleHandler every so often,
90 // even if the extension keeps up activity. 90 // even if the extension keeps up activity.
91 if (is_extension_process_) { 91 if (is_extension_process_) {
92 forced_idle_timer_.Start(FROM_HERE, 92 forced_idle_timer_.Start(FROM_HERE,
93 base::TimeDelta::FromSeconds(kMaxExtensionIdleHandlerDelayS), 93 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs),
94 RenderThread::Get(), &RenderThread::IdleHandler); 94 RenderThread::Get(), &RenderThread::IdleHandler);
95 } 95 }
96 96
97 RegisterExtension(new AppBindings(this), false); 97 RegisterExtension(new AppBindings(this), false);
98 RegisterExtension(ChromeWebstoreExtension::Get(), false); 98 RegisterExtension(ChromeWebstoreExtension::Get(), false);
99 99
100 // Add v8 extensions related to chrome extensions. 100 // Add v8 extensions related to chrome extensions.
101 RegisterExtension(new ChromeV8Extension( 101 RegisterExtension(new ChromeV8Extension(
102 "extensions/json_schema.js", IDR_JSON_SCHEMA_JS, NULL), true); 102 "extensions/json_schema.js", IDR_JSON_SCHEMA_JS, NULL), true);
103 RegisterExtension(EventBindings::Get(this), true); 103 RegisterExtension(EventBindings::Get(this), true);
(...skipping 12 matching lines...) Expand all
116 InitOriginPermissions(extension); 116 InitOriginPermissions(extension);
117 } 117 }
118 118
119 is_webkit_initialized_ = true; 119 is_webkit_initialized_ = true;
120 } 120 }
121 121
122 void ExtensionDispatcher::IdleNotification() { 122 void ExtensionDispatcher::IdleNotification() {
123 if (is_extension_process_) { 123 if (is_extension_process_) {
124 // Dampen the forced delay as well if the extension stays idle for long 124 // Dampen the forced delay as well if the extension stays idle for long
125 // periods of time. 125 // periods of time.
126 int64 forced_delay_s = std::max(static_cast<int64>( 126 int64 forced_delay_ms = std::max(
127 RenderThread::Get()->GetIdleNotificationDelayInS()), 127 RenderThread::Get()->GetIdleNotificationDelayInMs(),
128 kMaxExtensionIdleHandlerDelayS); 128 kMaxExtensionIdleHandlerDelayMs);
129 forced_idle_timer_.Stop(); 129 forced_idle_timer_.Stop();
130 forced_idle_timer_.Start(FROM_HERE, 130 forced_idle_timer_.Start(FROM_HERE,
131 base::TimeDelta::FromSeconds(forced_delay_s), 131 base::TimeDelta::FromMilliseconds(forced_delay_ms),
132 RenderThread::Get(), &RenderThread::IdleHandler); 132 RenderThread::Get(), &RenderThread::IdleHandler);
133 } 133 }
134 } 134 }
135 135
136 void ExtensionDispatcher::OnSetFunctionNames( 136 void ExtensionDispatcher::OnSetFunctionNames(
137 const std::vector<std::string>& names) { 137 const std::vector<std::string>& names) {
138 function_names_.clear(); 138 function_names_.clear();
139 for (size_t i = 0; i < names.size(); ++i) 139 for (size_t i = 0; i < names.size(); ++i)
140 function_names_.insert(names[i]); 140 function_names_.insert(names[i]);
141 } 141 }
142 142
143 void ExtensionDispatcher::OnMessageInvoke(const std::string& extension_id, 143 void ExtensionDispatcher::OnMessageInvoke(const std::string& extension_id,
144 const std::string& function_name, 144 const std::string& function_name,
145 const ListValue& args, 145 const ListValue& args,
146 const GURL& event_url) { 146 const GURL& event_url) {
147 v8_context_set_.DispatchChromeHiddenMethod( 147 v8_context_set_.DispatchChromeHiddenMethod(
148 extension_id, function_name, args, NULL, event_url); 148 extension_id, function_name, args, NULL, event_url);
149 149
150 // Reset the idle handler each time there's any activity like event or message 150 // Reset the idle handler each time there's any activity like event or message
151 // dispatch, for which Invoke is the chokepoint. 151 // dispatch, for which Invoke is the chokepoint.
152 if (is_extension_process_) { 152 if (is_extension_process_) {
153 RenderThread::Get()->ScheduleIdleHandler( 153 RenderThread::Get()->ScheduleIdleHandler(
154 kInitialExtensionIdleHandlerDelayS); 154 kInitialExtensionIdleHandlerDelayMs);
155 } 155 }
156 156
157 // Tell the browser process that the event is dispatched and we're idle. 157 // Tell the browser process that the event is dispatched and we're idle.
158 if (CommandLine::ForCurrentProcess()->HasSwitch( 158 if (CommandLine::ForCurrentProcess()->HasSwitch(
159 switches::kEnableLazyBackgroundPages) && 159 switches::kEnableLazyBackgroundPages) &&
160 function_name == "Event.dispatchJSON") { // may always be true 160 function_name == "Event.dispatchJSON") { // may always be true
161 RenderThread::Get()->Send( 161 RenderThread::Get()->Send(
162 new ExtensionHostMsg_ExtensionEventAck(extension_id)); 162 new ExtensionHostMsg_ExtensionEventAck(extension_id));
163 CheckIdleStatus(extension_id); 163 CheckIdleStatus(extension_id);
164 } 164 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 const std::string& extension_id) { 292 const std::string& extension_id) {
293 active_application_ids_.insert(extension_id); 293 active_application_ids_.insert(extension_id);
294 } 294 }
295 295
296 void ExtensionDispatcher::OnActivateExtension( 296 void ExtensionDispatcher::OnActivateExtension(
297 const std::string& extension_id) { 297 const std::string& extension_id) {
298 active_extension_ids_.insert(extension_id); 298 active_extension_ids_.insert(extension_id);
299 299
300 // This is called when starting a new extension page, so start the idle 300 // This is called when starting a new extension page, so start the idle
301 // handler ticking. 301 // handler ticking.
302 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayS); 302 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs);
303 303
304 UpdateActiveExtensions(); 304 UpdateActiveExtensions();
305 305
306 const Extension* extension = extensions_.GetByID(extension_id); 306 const Extension* extension = extensions_.GetByID(extension_id);
307 if (!extension) 307 if (!extension)
308 return; 308 return;
309 309
310 if (is_webkit_initialized_) 310 if (is_webkit_initialized_)
311 InitOriginPermissions(extension); 311 InitOriginPermissions(extension);
312 } 312 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 407
408 RenderThread::Get()->RegisterExtension(extension); 408 RenderThread::Get()->RegisterExtension(extension);
409 } 409 }
410 410
411 void ExtensionDispatcher::OnUsingWebRequestAPI( 411 void ExtensionDispatcher::OnUsingWebRequestAPI(
412 bool adblock, bool adblock_plus, bool other) { 412 bool adblock, bool adblock_plus, bool other) {
413 webrequest_adblock_ = adblock; 413 webrequest_adblock_ = adblock;
414 webrequest_adblock_plus_ = adblock_plus; 414 webrequest_adblock_plus_ = adblock_plus;
415 webrequest_other_ = other; 415 webrequest_other_ = other;
416 } 416 }
OLDNEW
« no previous file with comments | « no previous file | content/public/renderer/render_thread.h » ('j') | content/renderer/render_thread_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698