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

Side by Side Diff: chrome/browser/extensions/api/processes/processes_api.cc

Issue 10915067: Moving extension_processes_api to api/processes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Attempt to fix linking on android Created 8 years, 3 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 | Annotate | Revision Log
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/extensions/extension_processes_api.h" 5 #include "chrome/browser/extensions/api/processes/processes_api.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 14
15 #include "chrome/browser/extensions/api/processes/processes_api_constants.h"
15 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 16 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
16 #include "chrome/browser/extensions/event_router.h" 17 #include "chrome/browser/extensions/event_router.h"
17 #include "chrome/browser/extensions/extension_function_util.h" 18 #include "chrome/browser/extensions/extension_function_util.h"
18 #include "chrome/browser/extensions/extension_processes_api_constants.h"
19 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/extensions/extension_tab_util.h" 20 #include "chrome/browser/extensions/extension_tab_util.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/task_manager/task_manager.h" 22 #include "chrome/browser/task_manager/task_manager.h"
23 #include "chrome/browser/ui/tab_contents/tab_contents.h" 23 #include "chrome/browser/ui/tab_contents/tab_contents.h"
24 #include "chrome/common/chrome_notification_types.h" 24 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/extensions/extension_error_utils.h" 25 #include "chrome/common/extensions/extension_error_utils.h"
26 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/notification_details.h" 27 #include "content/public/browser/notification_details.h"
28 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/notification_source.h" 29 #include "content/public/browser/notification_source.h"
30 #include "content/public/browser/notification_types.h" 30 #include "content/public/browser/notification_types.h"
31 #include "content/public/browser/render_process_host.h" 31 #include "content/public/browser/render_process_host.h"
32 #include "content/public/browser/render_view_host.h" 32 #include "content/public/browser/render_view_host.h"
33 #include "content/public/browser/render_widget_host.h" 33 #include "content/public/browser/render_widget_host.h"
34 #include "content/public/browser/web_contents.h" 34 #include "content/public/browser/web_contents.h"
35 #include "content/public/common/result_codes.h" 35 #include "content/public/common/result_codes.h"
36 36
37 namespace keys = extension_processes_api_constants; 37 namespace extensions {
38 namespace errors = extension_processes_api_constants; 38
39 namespace keys = processes_api_constants;
40 namespace errors = processes_api_constants;
39 41
40 namespace { 42 namespace {
41 43
42 #if defined(ENABLE_TASK_MANAGER) 44 #if defined(ENABLE_TASK_MANAGER)
43 45
44 DictionaryValue* CreateCacheData( 46 DictionaryValue* CreateCacheData(
45 const WebKit::WebCache::ResourceTypeStat& stat) { 47 const WebKit::WebCache::ResourceTypeStat& stat) {
46 48
47 DictionaryValue* cache = new DictionaryValue(); 49 DictionaryValue* cache = new DictionaryValue();
48 cache->SetDouble(keys::kCacheSize, static_cast<double>(stat.size)); 50 cache->SetDouble(keys::kCacheSize, static_cast<double>(stat.size));
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 size_t mem; 205 size_t mem;
204 int64 pr_mem = model->GetPrivateMemory(index, &mem) ? 206 int64 pr_mem = model->GetPrivateMemory(index, &mem) ?
205 static_cast<int64>(mem) : -1; 207 static_cast<int64>(mem) : -1;
206 result->SetDouble(keys::kPrivateMemoryKey, static_cast<double>(pr_mem)); 208 result->SetDouble(keys::kPrivateMemoryKey, static_cast<double>(pr_mem));
207 } 209 }
208 210
209 #endif // defined(ENABLE_TASK_MANAGER) 211 #endif // defined(ENABLE_TASK_MANAGER)
210 212
211 } // local namespace 213 } // local namespace
212 214
213 ExtensionProcessesEventRouter* ExtensionProcessesEventRouter::GetInstance() { 215 ProcessesEventRouter* ProcessesEventRouter::GetInstance() {
214 return Singleton<ExtensionProcessesEventRouter>::get(); 216 return Singleton<ProcessesEventRouter>::get();
215 } 217 }
216 218
217 ExtensionProcessesEventRouter::ExtensionProcessesEventRouter() 219 ProcessesEventRouter::ProcessesEventRouter()
218 : listeners_(0), 220 : listeners_(0),
219 task_manager_listening_(false) { 221 task_manager_listening_(false) {
220 #if defined(ENABLE_TASK_MANAGER) 222 #if defined(ENABLE_TASK_MANAGER)
221 model_ = TaskManager::GetInstance()->model(); 223 model_ = TaskManager::GetInstance()->model();
222 model_->AddObserver(this); 224 model_->AddObserver(this);
223 225
224 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_HANG, 226 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_HANG,
225 content::NotificationService::AllSources()); 227 content::NotificationService::AllSources());
226 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 228 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
227 content::NotificationService::AllSources()); 229 content::NotificationService::AllSources());
228 #endif // defined(ENABLE_TASK_MANAGER) 230 #endif // defined(ENABLE_TASK_MANAGER)
229 } 231 }
230 232
231 ExtensionProcessesEventRouter::~ExtensionProcessesEventRouter() { 233 ProcessesEventRouter::~ProcessesEventRouter() {
232 #if defined(ENABLE_TASK_MANAGER) 234 #if defined(ENABLE_TASK_MANAGER)
233 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_HANG, 235 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_HANG,
234 content::NotificationService::AllSources()); 236 content::NotificationService::AllSources());
235 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 237 registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
236 content::NotificationService::AllSources()); 238 content::NotificationService::AllSources());
237 239
238 if (task_manager_listening_) 240 if (task_manager_listening_)
239 model_->StopListening(); 241 model_->StopListening();
240 242
241 model_->RemoveObserver(this); 243 model_->RemoveObserver(this);
242 #endif // defined(ENABLE_TASK_MANAGER) 244 #endif // defined(ENABLE_TASK_MANAGER)
243 } 245 }
244 246
245 void ExtensionProcessesEventRouter::ObserveProfile(Profile* profile) { 247 void ProcessesEventRouter::ObserveProfile(Profile* profile) {
246 profiles_.insert(profile); 248 profiles_.insert(profile);
247 } 249 }
248 250
249 void ExtensionProcessesEventRouter::ListenerAdded() { 251 void ProcessesEventRouter::ListenerAdded() {
250 #if defined(ENABLE_TASK_MANAGER) 252 #if defined(ENABLE_TASK_MANAGER)
251 // The task manager has its own ref count to balance other callers of 253 // The task manager has its own ref count to balance other callers of
252 // StartUpdating/StopUpdating. 254 // StartUpdating/StopUpdating.
253 model_->StartUpdating(); 255 model_->StartUpdating();
254 #endif // defined(ENABLE_TASK_MANAGER) 256 #endif // defined(ENABLE_TASK_MANAGER)
255 ++listeners_; 257 ++listeners_;
256 } 258 }
257 259
258 void ExtensionProcessesEventRouter::ListenerRemoved() { 260 void ProcessesEventRouter::ListenerRemoved() {
259 DCHECK(listeners_ > 0); 261 DCHECK(listeners_ > 0);
260 --listeners_; 262 --listeners_;
261 #if defined(ENABLE_TASK_MANAGER) 263 #if defined(ENABLE_TASK_MANAGER)
262 // The task manager has its own ref count to balance other callers of 264 // The task manager has its own ref count to balance other callers of
263 // StartUpdating/StopUpdating. 265 // StartUpdating/StopUpdating.
264 model_->StopUpdating(); 266 model_->StopUpdating();
265 #endif // defined(ENABLE_TASK_MANAGER) 267 #endif // defined(ENABLE_TASK_MANAGER)
266 } 268 }
267 269
268 void ExtensionProcessesEventRouter::StartTaskManagerListening() { 270 void ProcessesEventRouter::StartTaskManagerListening() {
269 #if defined(ENABLE_TASK_MANAGER) 271 #if defined(ENABLE_TASK_MANAGER)
270 if (!task_manager_listening_) { 272 if (!task_manager_listening_) {
271 model_->StartListening(); 273 model_->StartListening();
272 task_manager_listening_ = true; 274 task_manager_listening_ = true;
273 } 275 }
274 #endif // defined(ENABLE_TASK_MANAGER) 276 #endif // defined(ENABLE_TASK_MANAGER)
275 } 277 }
276 278
277 void ExtensionProcessesEventRouter::Observe( 279 void ProcessesEventRouter::Observe(
278 int type, 280 int type,
279 const content::NotificationSource& source, 281 const content::NotificationSource& source,
280 const content::NotificationDetails& details) { 282 const content::NotificationDetails& details) {
281 283
282 switch (type) { 284 switch (type) {
283 case content::NOTIFICATION_RENDERER_PROCESS_HANG: 285 case content::NOTIFICATION_RENDERER_PROCESS_HANG:
284 ProcessHangEvent( 286 ProcessHangEvent(
285 content::Source<content::RenderWidgetHost>(source).ptr()); 287 content::Source<content::RenderWidgetHost>(source).ptr());
286 break; 288 break;
287 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: 289 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED:
288 ProcessClosedEvent( 290 ProcessClosedEvent(
289 content::Source<content::RenderProcessHost>(source).ptr(), 291 content::Source<content::RenderProcessHost>(source).ptr(),
290 content::Details<content::RenderProcessHost::RendererClosedDetails>( 292 content::Details<content::RenderProcessHost::RendererClosedDetails>(
291 details).ptr()); 293 details).ptr());
292 break; 294 break;
293 default: 295 default:
294 NOTREACHED() << "Unexpected observe of type " << type; 296 NOTREACHED() << "Unexpected observe of type " << type;
295 } 297 }
296 return; 298 return;
297 } 299 }
298 300
299 void ExtensionProcessesEventRouter::OnItemsAdded(int start, int length) { 301 void ProcessesEventRouter::OnItemsAdded(int start, int length) {
300 #if defined(ENABLE_TASK_MANAGER) 302 #if defined(ENABLE_TASK_MANAGER)
301 DCHECK_EQ(length, 1); 303 DCHECK_EQ(length, 1);
302 int index = start; 304 int index = start;
303 305
304 std::string event(keys::kOnCreated); 306 std::string event(keys::kOnCreated);
305 if (!HasEventListeners(event)) 307 if (!HasEventListeners(event))
306 return; 308 return;
307 309
308 // If the item being added is not the first one in the group, find the base 310 // If the item being added is not the first one in the group, find the base
309 // index and use it for retrieving the process data. 311 // index and use it for retrieving the process data.
310 if (!model_->IsResourceFirstInGroup(start)) { 312 if (!model_->IsResourceFirstInGroup(start)) {
311 index = model_->GetGroupIndexForResource(start); 313 index = model_->GetGroupIndexForResource(start);
312 } 314 }
313 315
314 scoped_ptr<ListValue> args(new ListValue()); 316 scoped_ptr<ListValue> args(new ListValue());
315 DictionaryValue* process = CreateProcessFromModel( 317 DictionaryValue* process = CreateProcessFromModel(
316 model_->GetUniqueChildProcessId(index), model_, index, false); 318 model_->GetUniqueChildProcessId(index), model_, index, false);
317 DCHECK(process != NULL); 319 DCHECK(process != NULL);
318 320
319 if (process == NULL) 321 if (process == NULL)
320 return; 322 return;
321 323
322 args->Append(process); 324 args->Append(process);
323 325
324 NotifyProfiles(keys::kOnCreated, args.Pass()); 326 NotifyProfiles(keys::kOnCreated, args.Pass());
325 #endif // defined(ENABLE_TASK_MANAGER) 327 #endif // defined(ENABLE_TASK_MANAGER)
326 } 328 }
327 329
328 void ExtensionProcessesEventRouter::OnItemsChanged(int start, int length) { 330 void ProcessesEventRouter::OnItemsChanged(int start, int length) {
329 #if defined(ENABLE_TASK_MANAGER) 331 #if defined(ENABLE_TASK_MANAGER)
330 // If we don't have any listeners, return immediately. 332 // If we don't have any listeners, return immediately.
331 if (listeners_ == 0) 333 if (listeners_ == 0)
332 return; 334 return;
333 335
334 if (!model_) 336 if (!model_)
335 return; 337 return;
336 338
337 // We need to know which type of onUpdated events to fire and whether to 339 // We need to know which type of onUpdated events to fire and whether to
338 // collect memory or not. 340 // collect memory or not.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 processes->Set(base::IntToString(id), it.GetCurrentValue()); 387 processes->Set(base::IntToString(id), it.GetCurrentValue());
386 } 388 }
387 389
388 scoped_ptr<ListValue> args(new ListValue()); 390 scoped_ptr<ListValue> args(new ListValue());
389 args->Append(processes); 391 args->Append(processes);
390 NotifyProfiles(keys::kOnUpdatedWithMemory, args.Pass()); 392 NotifyProfiles(keys::kOnUpdatedWithMemory, args.Pass());
391 } 393 }
392 #endif // defined(ENABLE_TASK_MANAGER) 394 #endif // defined(ENABLE_TASK_MANAGER)
393 } 395 }
394 396
395 void ExtensionProcessesEventRouter::OnItemsToBeRemoved(int start, int length) { 397 void ProcessesEventRouter::OnItemsToBeRemoved(int start, int length) {
396 #if defined(ENABLE_TASK_MANAGER) 398 #if defined(ENABLE_TASK_MANAGER)
397 DCHECK(length == 1); 399 DCHECK(length == 1);
398 400
399 // Process exit for renderer processes has the data about exit code and 401 // Process exit for renderer processes has the data about exit code and
400 // termination status, therefore we will rely on notifications and not on 402 // termination status, therefore we will rely on notifications and not on
401 // the Task Manager data. We do use the rest of this method for non-renderer 403 // the Task Manager data. We do use the rest of this method for non-renderer
402 // processes. 404 // processes.
403 if (model_->GetResourceType(start) == TaskManager::Resource::RENDERER) 405 if (model_->GetResourceType(start) == TaskManager::Resource::RENDERER)
404 return; 406 return;
405 407
406 // The callback function parameters. 408 // The callback function parameters.
407 scoped_ptr<ListValue> args(new ListValue()); 409 scoped_ptr<ListValue> args(new ListValue());
408 410
409 // First arg: The id of the process that was closed. 411 // First arg: The id of the process that was closed.
410 args->Append(Value::CreateIntegerValue( 412 args->Append(Value::CreateIntegerValue(
411 model_->GetUniqueChildProcessId(start))); 413 model_->GetUniqueChildProcessId(start)));
412 414
413 // Second arg: The exit type for the process. 415 // Second arg: The exit type for the process.
414 args->Append(Value::CreateIntegerValue(0)); 416 args->Append(Value::CreateIntegerValue(0));
415 417
416 // Third arg: The exit code for the process. 418 // Third arg: The exit code for the process.
417 args->Append(Value::CreateIntegerValue(0)); 419 args->Append(Value::CreateIntegerValue(0));
418 420
419 NotifyProfiles(keys::kOnExited, args.Pass()); 421 NotifyProfiles(keys::kOnExited, args.Pass());
420 #endif // defined(ENABLE_TASK_MANAGER) 422 #endif // defined(ENABLE_TASK_MANAGER)
421 } 423 }
422 424
423 void ExtensionProcessesEventRouter::ProcessHangEvent( 425 void ProcessesEventRouter::ProcessHangEvent(content::RenderWidgetHost* widget) {
424 content::RenderWidgetHost* widget) {
425 #if defined(ENABLE_TASK_MANAGER) 426 #if defined(ENABLE_TASK_MANAGER)
426 std::string event(keys::kOnUnresponsive); 427 std::string event(keys::kOnUnresponsive);
427 if (!HasEventListeners(event)) 428 if (!HasEventListeners(event))
428 return; 429 return;
429 430
430 DictionaryValue* process = NULL; 431 DictionaryValue* process = NULL;
431 int count = model_->ResourceCount(); 432 int count = model_->ResourceCount();
432 int id = widget->GetProcess()->GetID(); 433 int id = widget->GetProcess()->GetID();
433 434
434 for (int i = 0; i < count; ++i) { 435 for (int i = 0; i < count; ++i) {
435 if (model_->IsResourceFirstInGroup(i)) { 436 if (model_->IsResourceFirstInGroup(i)) {
436 if (id == model_->GetUniqueChildProcessId(i)) { 437 if (id == model_->GetUniqueChildProcessId(i)) {
437 process = CreateProcessFromModel(id, model_, i, false); 438 process = CreateProcessFromModel(id, model_, i, false);
438 break; 439 break;
439 } 440 }
440 } 441 }
441 } 442 }
442 443
443 DCHECK(process); 444 DCHECK(process);
444 if (process == NULL) 445 if (process == NULL)
445 return; 446 return;
446 447
447 scoped_ptr<ListValue> args(new ListValue()); 448 scoped_ptr<ListValue> args(new ListValue());
448 args->Append(process); 449 args->Append(process);
449 450
450 NotifyProfiles(keys::kOnUnresponsive, args.Pass()); 451 NotifyProfiles(keys::kOnUnresponsive, args.Pass());
451 #endif // defined(ENABLE_TASK_MANAGER) 452 #endif // defined(ENABLE_TASK_MANAGER)
452 } 453 }
453 454
454 void ExtensionProcessesEventRouter::ProcessClosedEvent( 455 void ProcessesEventRouter::ProcessClosedEvent(
455 content::RenderProcessHost* rph, 456 content::RenderProcessHost* rph,
456 content::RenderProcessHost::RendererClosedDetails* details) { 457 content::RenderProcessHost::RendererClosedDetails* details) {
457 #if defined(ENABLE_TASK_MANAGER) 458 #if defined(ENABLE_TASK_MANAGER)
458 // The callback function parameters. 459 // The callback function parameters.
459 scoped_ptr<ListValue> args(new ListValue()); 460 scoped_ptr<ListValue> args(new ListValue());
460 461
461 // First arg: The id of the process that was closed. 462 // First arg: The id of the process that was closed.
462 args->Append(Value::CreateIntegerValue(rph->GetID())); 463 args->Append(Value::CreateIntegerValue(rph->GetID()));
463 464
464 // Second arg: The exit type for the process. 465 // Second arg: The exit type for the process.
465 args->Append(Value::CreateIntegerValue(details->status)); 466 args->Append(Value::CreateIntegerValue(details->status));
466 467
467 // Third arg: The exit code for the process. 468 // Third arg: The exit code for the process.
468 args->Append(Value::CreateIntegerValue(details->exit_code)); 469 args->Append(Value::CreateIntegerValue(details->exit_code));
469 470
470 NotifyProfiles(keys::kOnExited, args.Pass()); 471 NotifyProfiles(keys::kOnExited, args.Pass());
471 #endif // defined(ENABLE_TASK_MANAGER) 472 #endif // defined(ENABLE_TASK_MANAGER)
472 } 473 }
473 474
474 void ExtensionProcessesEventRouter::DispatchEvent( 475 void ProcessesEventRouter::DispatchEvent(Profile* profile,
475 Profile* profile, 476 const char* event_name,
476 const char* event_name, 477 scoped_ptr<ListValue> event_args) {
477 scoped_ptr<ListValue> event_args) {
478 if (profile && profile->GetExtensionEventRouter()) { 478 if (profile && profile->GetExtensionEventRouter()) {
479 profile->GetExtensionEventRouter()->DispatchEventToRenderers( 479 profile->GetExtensionEventRouter()->DispatchEventToRenderers(
480 event_name, event_args.Pass(), NULL, GURL(), 480 event_name, event_args.Pass(), NULL, GURL(),
481 extensions::EventFilteringInfo()); 481 extensions::EventFilteringInfo());
482 } 482 }
483 } 483 }
484 484
485 void ExtensionProcessesEventRouter::NotifyProfiles( 485 void ProcessesEventRouter::NotifyProfiles(const char* event_name,
486 const char* event_name, 486 scoped_ptr<ListValue> event_args) {
487 scoped_ptr<ListValue> event_args) {
488 for (ProfileSet::iterator it = profiles_.begin(); 487 for (ProfileSet::iterator it = profiles_.begin();
489 it != profiles_.end(); it++) { 488 it != profiles_.end(); it++) {
490 Profile* profile = *it; 489 Profile* profile = *it;
491 scoped_ptr<ListValue> event_args_copy(event_args->DeepCopy()); 490 scoped_ptr<ListValue> event_args_copy(event_args->DeepCopy());
492 DispatchEvent(profile, event_name, event_args_copy.Pass()); 491 DispatchEvent(profile, event_name, event_args_copy.Pass());
493 } 492 }
494 } 493 }
495 494
496 // In order to determine whether there are any listeners for the event of 495 // In order to determine whether there are any listeners for the event of
497 // interest, we need to ask each profile whether it has one registered. 496 // interest, we need to ask each profile whether it has one registered.
498 // We only need to look for the profiles that have registered with the 497 // We only need to look for the profiles that have registered with the
499 // this extension API. 498 // this extension API.
500 bool ExtensionProcessesEventRouter::HasEventListeners(std::string& event_name) { 499 bool ProcessesEventRouter::HasEventListeners(std::string& event_name) {
501 for (ProfileSet::iterator it = profiles_.begin(); 500 for (ProfileSet::iterator it = profiles_.begin();
502 it != profiles_.end(); it++) { 501 it != profiles_.end(); it++) {
503 Profile* profile = *it; 502 Profile* profile = *it;
504 extensions::EventRouter* router = profile->GetExtensionEventRouter(); 503 extensions::EventRouter* router = profile->GetExtensionEventRouter();
505 if (!router) 504 if (!router)
506 continue; 505 continue;
507 506
508 if (router->HasEventListener(event_name)) 507 if (router->HasEventListener(event_name))
509 return true; 508 return true;
510 } 509 }
511 return false; 510 return false;
512 } 511 }
513 512
514 bool GetProcessIdForTabFunction::RunImpl() { 513 bool GetProcessIdForTabFunction::RunImpl() {
515 #if defined(ENABLE_TASK_MANAGER) 514 #if defined(ENABLE_TASK_MANAGER)
516 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id_)); 515 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id_));
517 516
518 // Add a reference, which is balanced in GetProcessIdForTab to keep the object 517 // Add a reference, which is balanced in GetProcessIdForTab to keep the object
519 // around and allow for the callback to be invoked. 518 // around and allow for the callback to be invoked.
520 AddRef(); 519 AddRef();
521 520
522 // If the task manager is already listening, just post a task to execute 521 // If the task manager is already listening, just post a task to execute
523 // which will invoke the callback once we have returned from this function. 522 // which will invoke the callback once we have returned from this function.
524 // Otherwise, wait for the notification that the task manager is done with 523 // Otherwise, wait for the notification that the task manager is done with
525 // the data gathering. 524 // the data gathering.
526 if (ExtensionProcessesEventRouter::GetInstance()-> 525 if (ProcessesEventRouter::GetInstance()->is_task_manager_listening()) {
527 is_task_manager_listening()) {
528 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 526 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
529 &GetProcessIdForTabFunction::GetProcessIdForTab, this)); 527 &GetProcessIdForTabFunction::GetProcessIdForTab, this));
530 } else { 528 } else {
531 registrar_.Add(this, 529 registrar_.Add(this,
532 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY, 530 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY,
533 content::NotificationService::AllSources()); 531 content::NotificationService::AllSources());
534 ExtensionProcessesEventRouter::GetInstance()-> 532 ProcessesEventRouter::GetInstance()->StartTaskManagerListening();
535 StartTaskManagerListening();
536 } 533 }
537 534
538 return true; 535 return true;
539 #else 536 #else
540 error_ = errors::kExtensionNotSupported; 537 error_ = errors::kExtensionNotSupported;
541 return false; 538 return false;
542 #endif // defined(ENABLE_TASK_MANAGER) 539 #endif // defined(ENABLE_TASK_MANAGER)
543 } 540 }
544 541
545 void GetProcessIdForTabFunction::Observe( 542 void GetProcessIdForTabFunction::Observe(
(...skipping 30 matching lines...) Expand all
576 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &process_id_)); 573 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &process_id_));
577 574
578 // Add a reference, which is balanced in TerminateProcess to keep the object 575 // Add a reference, which is balanced in TerminateProcess to keep the object
579 // around and allow for the callback to be invoked. 576 // around and allow for the callback to be invoked.
580 AddRef(); 577 AddRef();
581 578
582 // If the task manager is already listening, just post a task to execute 579 // If the task manager is already listening, just post a task to execute
583 // which will invoke the callback once we have returned from this function. 580 // which will invoke the callback once we have returned from this function.
584 // Otherwise, wait for the notification that the task manager is done with 581 // Otherwise, wait for the notification that the task manager is done with
585 // the data gathering. 582 // the data gathering.
586 if (ExtensionProcessesEventRouter::GetInstance()-> 583 if (ProcessesEventRouter::GetInstance()->is_task_manager_listening()) {
587 is_task_manager_listening()) {
588 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 584 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
589 &TerminateFunction::TerminateProcess, this)); 585 &TerminateFunction::TerminateProcess, this));
590 } else { 586 } else {
591 registrar_.Add(this, 587 registrar_.Add(this,
592 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY, 588 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY,
593 content::NotificationService::AllSources()); 589 content::NotificationService::AllSources());
594 ExtensionProcessesEventRouter::GetInstance()-> 590 ProcessesEventRouter::GetInstance()->StartTaskManagerListening();
595 StartTaskManagerListening();
596 } 591 }
597 592
598 return true; 593 return true;
599 #else 594 #else
600 error_ = errors::kExtensionNotSupported; 595 error_ = errors::kExtensionNotSupported;
601 return false; 596 return false;
602 #endif // defined(ENABLE_TASK_MANAGER) 597 #endif // defined(ENABLE_TASK_MANAGER)
603 } 598 }
604 599
605 void TerminateFunction::Observe( 600 void TerminateFunction::Observe(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 processes, &process_ids_)); 655 processes, &process_ids_));
661 656
662 // Add a reference, which is balanced in GatherProcessInfo to keep the object 657 // Add a reference, which is balanced in GatherProcessInfo to keep the object
663 // around and allow for the callback to be invoked. 658 // around and allow for the callback to be invoked.
664 AddRef(); 659 AddRef();
665 660
666 // If the task manager is already listening, just post a task to execute 661 // If the task manager is already listening, just post a task to execute
667 // which will invoke the callback once we have returned from this function. 662 // which will invoke the callback once we have returned from this function.
668 // Otherwise, wait for the notification that the task manager is done with 663 // Otherwise, wait for the notification that the task manager is done with
669 // the data gathering. 664 // the data gathering.
670 if (ExtensionProcessesEventRouter::GetInstance()-> 665 if (ProcessesEventRouter::GetInstance()->is_task_manager_listening()) {
671 is_task_manager_listening()) {
672 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( 666 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
673 &GetProcessInfoFunction::GatherProcessInfo, this)); 667 &GetProcessInfoFunction::GatherProcessInfo, this));
674 } else { 668 } else {
675 registrar_.Add(this, 669 registrar_.Add(this,
676 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY, 670 chrome::NOTIFICATION_TASK_MANAGER_CHILD_PROCESSES_DATA_READY,
677 content::NotificationService::AllSources()); 671 content::NotificationService::AllSources());
678 ExtensionProcessesEventRouter::GetInstance()-> 672 ProcessesEventRouter::GetInstance()->StartTaskManagerListening();
679 StartTaskManagerListening();
680 } 673 }
681 return true; 674 return true;
682 675
683 #else 676 #else
684 error_ = errors::kExtensionNotSupported; 677 error_ = errors::kExtensionNotSupported;
685 return false; 678 return false;
686 #endif // defined(ENABLE_TASK_MANAGER) 679 #endif // defined(ENABLE_TASK_MANAGER)
687 } 680 }
688 681
689 void GetProcessInfoFunction::Observe( 682 void GetProcessInfoFunction::Observe(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 DCHECK(process_ids_.size() == 0); 728 DCHECK(process_ids_.size() == 0);
736 } 729 }
737 730
738 SetResult(processes); 731 SetResult(processes);
739 SendResponse(true); 732 SendResponse(true);
740 733
741 // Balance the AddRef in the RunImpl. 734 // Balance the AddRef in the RunImpl.
742 Release(); 735 Release();
743 #endif // defined(ENABLE_TASK_MANAGER) 736 #endif // defined(ENABLE_TASK_MANAGER)
744 } 737 }
738
739 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698