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

Side by Side Diff: chrome/browser/task_manager/task_manager.cc

Issue 7043007: Kill URLRequestJobTracker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge. Created 9 years, 7 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
« no previous file with comments | « chrome/browser/task_manager/task_manager.h ('k') | chrome/browser/ui/views/about_ipc_dialog.cc » ('j') | 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) 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/browser/task_manager/task_manager.h" 5 #include "chrome/browser/task_manager/task_manager.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/i18n/number_formatting.h" 8 #include "base/i18n/number_formatting.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 16 matching lines...) Expand all
27 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
29 #include "content/browser/browser_thread.h" 29 #include "content/browser/browser_thread.h"
30 #include "content/browser/renderer_host/render_process_host.h" 30 #include "content/browser/renderer_host/render_process_host.h"
31 #include "content/browser/renderer_host/resource_dispatcher_host.h" 31 #include "content/browser/renderer_host/resource_dispatcher_host.h"
32 #include "content/browser/tab_contents/tab_contents.h" 32 #include "content/browser/tab_contents/tab_contents.h"
33 #include "content/common/result_codes.h" 33 #include "content/common/result_codes.h"
34 #include "grit/app_resources.h" 34 #include "grit/app_resources.h"
35 #include "grit/chromium_strings.h" 35 #include "grit/chromium_strings.h"
36 #include "grit/generated_resources.h" 36 #include "grit/generated_resources.h"
37 #include "net/url_request/url_request.h"
38 #include "net/url_request/url_request_job.h"
39 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
40 #include "ui/base/resource/resource_bundle.h" 38 #include "ui/base/resource/resource_bundle.h"
41 #include "unicode/coll.h" 39 #include "unicode/coll.h"
42 40
43 #if defined(OS_MACOSX) 41 #if defined(OS_MACOSX)
44 #include "chrome/browser/mach_broker_mac.h" 42 #include "chrome/browser/mach_broker_mac.h"
45 #endif 43 #endif
46 44
47 namespace { 45 namespace {
48 46
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 491
494 // If update_state_ is STOPPING, it means a task is still pending. Setting 492 // If update_state_ is STOPPING, it means a task is still pending. Setting
495 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()). 493 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()).
496 if (update_state_ == IDLE) { 494 if (update_state_ == IDLE) {
497 MessageLoop::current()->PostDelayedTask(FROM_HERE, 495 MessageLoop::current()->PostDelayedTask(FROM_HERE,
498 NewRunnableMethod(this, &TaskManagerModel::Refresh), 496 NewRunnableMethod(this, &TaskManagerModel::Refresh),
499 kUpdateTimeMs); 497 kUpdateTimeMs);
500 } 498 }
501 update_state_ = TASK_PENDING; 499 update_state_ = TASK_PENDING;
502 500
503 // Register jobs notifications so we can compute network usage (it must be
504 // done from the IO thread).
505 BrowserThread::PostTask(
506 BrowserThread::IO, FROM_HERE,
507 NewRunnableMethod(
508 this, &TaskManagerModel::RegisterForJobDoneNotifications));
509
510 // Notify resource providers that we are updating. 501 // Notify resource providers that we are updating.
511 for (ResourceProviderList::iterator iter = providers_.begin(); 502 for (ResourceProviderList::iterator iter = providers_.begin();
512 iter != providers_.end(); ++iter) { 503 iter != providers_.end(); ++iter) {
513 (*iter)->StartUpdating(); 504 (*iter)->StartUpdating();
514 } 505 }
515 } 506 }
516 507
517 void TaskManagerModel::StopUpdating() { 508 void TaskManagerModel::StopUpdating() {
518 // Don't actually stop updating until we have heard as many calls as those 509 // Don't actually stop updating until we have heard as many calls as those
519 // to StartUpdating. 510 // to StartUpdating.
520 update_requests_--; 511 update_requests_--;
521 if (update_requests_ > 0) 512 if (update_requests_ > 0)
522 return; 513 return;
523 // Make sure that update_requests_ cannot go negative. 514 // Make sure that update_requests_ cannot go negative.
524 CHECK_EQ(0, update_requests_); 515 CHECK_EQ(0, update_requests_);
525 DCHECK_EQ(TASK_PENDING, update_state_); 516 DCHECK_EQ(TASK_PENDING, update_state_);
526 update_state_ = STOPPING; 517 update_state_ = STOPPING;
527 518
528 // Notify resource providers that we are done updating. 519 // Notify resource providers that we are done updating.
529 for (ResourceProviderList::const_iterator iter = providers_.begin(); 520 for (ResourceProviderList::const_iterator iter = providers_.begin();
530 iter != providers_.end(); ++iter) { 521 iter != providers_.end(); ++iter) {
531 (*iter)->StopUpdating(); 522 (*iter)->StopUpdating();
532 } 523 }
533 524
534 // Unregister jobs notification (must be done from the IO thread).
535 BrowserThread::PostTask(
536 BrowserThread::IO, FROM_HERE,
537 NewRunnableMethod(
538 this, &TaskManagerModel::UnregisterForJobDoneNotifications));
539
540 // Must clear the resources before the next attempt to start updating. 525 // Must clear the resources before the next attempt to start updating.
541 Clear(); 526 Clear();
542 } 527 }
543 528
544 void TaskManagerModel::AddResourceProvider( 529 void TaskManagerModel::AddResourceProvider(
545 TaskManager::ResourceProvider* provider) { 530 TaskManager::ResourceProvider* provider) {
546 DCHECK(provider); 531 DCHECK(provider);
547 // AddRef matched with Release in destructor. 532 // AddRef matched with Release in destructor.
548 provider->AddRef(); 533 provider->AddRef();
549 providers_.push_back(provider); 534 providers_.push_back(provider);
550 } 535 }
551 536
552 void TaskManagerModel::RegisterForJobDoneNotifications() {
553 net::g_url_request_job_tracker.AddObserver(this);
554 }
555
556 void TaskManagerModel::UnregisterForJobDoneNotifications() {
557 net::g_url_request_job_tracker.RemoveObserver(this);
558 }
559
560 void TaskManagerModel::AddResource(TaskManager::Resource* resource) { 537 void TaskManagerModel::AddResource(TaskManager::Resource* resource) {
561 base::ProcessHandle process = resource->GetProcess(); 538 base::ProcessHandle process = resource->GetProcess();
562 539
563 ResourceList* group_entries = NULL; 540 ResourceList* group_entries = NULL;
564 GroupMap::const_iterator group_iter = group_map_.find(process); 541 GroupMap::const_iterator group_iter = group_map_.find(process);
565 int new_entry_index = 0; 542 int new_entry_index = 0;
566 if (group_iter == group_map_.end()) { 543 if (group_iter == group_map_.end()) {
567 group_entries = new ResourceList(); 544 group_entries = new ResourceList();
568 group_map_[process] = group_entries; 545 group_map_[process] = group_entries;
569 group_entries->push_back(resource); 546 group_entries->push_back(resource);
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 806
830 ResourceValueMap::const_iterator iter_res = 807 ResourceValueMap::const_iterator iter_res =
831 current_byte_count_map_.find(resource); 808 current_byte_count_map_.find(resource);
832 if (iter_res == current_byte_count_map_.end()) 809 if (iter_res == current_byte_count_map_.end())
833 current_byte_count_map_[resource] = param.byte_count; 810 current_byte_count_map_[resource] = param.byte_count;
834 else 811 else
835 current_byte_count_map_[resource] = iter_res->second + param.byte_count; 812 current_byte_count_map_[resource] = iter_res->second + param.byte_count;
836 } 813 }
837 814
838 815
839 // In order to retrieve the network usage, we register for net::URLRequestJob 816 void TaskManagerModel::NotifyBytesRead(const net::URLRequest& request,
840 // notifications. Every time we get notified some bytes were read we bump a 817 int byte_count) {
841 // counter of read bytes for the associated resource. When the timer ticks,
842 // we'll compute the actual network usage (see the Refresh method).
843 void TaskManagerModel::OnJobAdded(net::URLRequestJob* job) {
844 }
845
846 void TaskManagerModel::OnJobRemoved(net::URLRequestJob* job) {
847 }
848
849 void TaskManagerModel::OnJobDone(net::URLRequestJob* job,
850 const net::URLRequestStatus& status) {
851 }
852
853 void TaskManagerModel::OnJobRedirect(net::URLRequestJob* job,
854 const GURL& location,
855 int status_code) {
856 }
857
858 void TaskManagerModel::OnBytesRead(net::URLRequestJob* job, const char* buf,
859 int byte_count) {
860 // Only net::URLRequestJob instances created by the ResourceDispatcherHost 818 // Only net::URLRequestJob instances created by the ResourceDispatcherHost
861 // have a render view associated. All other jobs will have -1 returned for 819 // have a render view associated. All other jobs will have -1 returned for
862 // the render process child and routing ids - the jobs may still match a 820 // the render process child and routing ids - the jobs may still match a
863 // resource based on their origin id, otherwise BytesRead() will attribute 821 // resource based on their origin id, otherwise BytesRead() will attribute
864 // the activity to the Browser resource. 822 // the activity to the Browser resource.
865 int render_process_host_child_id = -1, routing_id = -1; 823 int render_process_host_child_id = -1, routing_id = -1;
866 ResourceDispatcherHost::RenderViewForRequest(job->request(), 824 ResourceDispatcherHost::RenderViewForRequest(&request,
867 &render_process_host_child_id, 825 &render_process_host_child_id,
868 &routing_id); 826 &routing_id);
869 827
870 // Get the origin PID of the request's originator. This will only be set for 828 // Get the origin PID of the request's originator. This will only be set for
871 // plugins - for renderer or browser initiated requests it will be zero. 829 // plugins - for renderer or browser initiated requests it will be zero.
872 int origin_pid = 830 int origin_pid = chrome_browser_net::GetOriginPIDForRequest(&request);
873 chrome_browser_net::GetOriginPIDForRequest(job->request());
874 831
875 // This happens in the IO thread, post it to the UI thread. 832 // This happens in the IO thread, post it to the UI thread.
876 BrowserThread::PostTask( 833 BrowserThread::PostTask(
877 BrowserThread::UI, FROM_HERE, 834 BrowserThread::UI, FROM_HERE,
878 NewRunnableMethod( 835 NewRunnableMethod(
879 this, 836 this,
880 &TaskManagerModel::BytesRead, 837 &TaskManagerModel::BytesRead,
881 BytesReadParam(origin_pid, 838 BytesReadParam(origin_pid,
882 render_process_host_child_id, 839 render_process_host_child_id,
883 routing_id, byte_count))); 840 routing_id, byte_count)));
884 } 841 }
885 842
886 bool TaskManagerModel::GetProcessMetricsForRow( 843 bool TaskManagerModel::GetProcessMetricsForRow(
887 int row, base::ProcessMetrics** proc_metrics) const { 844 int row, base::ProcessMetrics** proc_metrics) const {
888 DCHECK(row < ResourceCount()); 845 DCHECK(row < ResourceCount());
889 *proc_metrics = NULL; 846 *proc_metrics = NULL;
890 847
891 MetricsMap::const_iterator iter = 848 MetricsMap::const_iterator iter =
892 metrics_map_.find(resources_[row]->GetProcess()); 849 metrics_map_.find(resources_[row]->GetProcess());
893 if (iter == metrics_map_.end()) 850 if (iter == metrics_map_.end())
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 // Count the number of extensions with background pages (including 1002 // Count the number of extensions with background pages (including
1046 // incognito). 1003 // incognito).
1047 count += CountExtensionBackgroundPagesForProfile(profile); 1004 count += CountExtensionBackgroundPagesForProfile(profile);
1048 if (profile->HasOffTheRecordProfile()) { 1005 if (profile->HasOffTheRecordProfile()) {
1049 count += CountExtensionBackgroundPagesForProfile( 1006 count += CountExtensionBackgroundPagesForProfile(
1050 profile->GetOffTheRecordProfile()); 1007 profile->GetOffTheRecordProfile());
1051 } 1008 }
1052 } 1009 }
1053 return count; 1010 return count;
1054 } 1011 }
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/task_manager.h ('k') | chrome/browser/ui/views/about_ipc_dialog.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698