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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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/task_manager/task_manager.h" 5 #include "chrome/browser/task_manager/task_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/i18n/number_formatting.h" 9 #include "base/i18n/number_formatting.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 // action the first time. 1014 // action the first time.
1015 update_requests_++; 1015 update_requests_++;
1016 if (update_requests_ > 1) 1016 if (update_requests_ > 1)
1017 return; 1017 return;
1018 DCHECK_EQ(1, update_requests_); 1018 DCHECK_EQ(1, update_requests_);
1019 DCHECK_NE(TASK_PENDING, update_state_); 1019 DCHECK_NE(TASK_PENDING, update_state_);
1020 1020
1021 // If update_state_ is STOPPING, it means a task is still pending. Setting 1021 // If update_state_ is STOPPING, it means a task is still pending. Setting
1022 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()). 1022 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()).
1023 if (update_state_ == IDLE) { 1023 if (update_state_ == IDLE) {
1024 MessageLoop::current()->PostTask( 1024 base::MessageLoop::current()->PostTask(
1025 FROM_HERE, 1025 FROM_HERE, base::Bind(&TaskManagerModel::RefreshCallback, this));
1026 base::Bind(&TaskManagerModel::RefreshCallback, this));
1027 } 1026 }
1028 update_state_ = TASK_PENDING; 1027 update_state_ = TASK_PENDING;
1029 1028
1030 // Notify resource providers that we are updating. 1029 // Notify resource providers that we are updating.
1031 StartListening(); 1030 StartListening();
1032 1031
1033 if (!resources_.empty()) { 1032 if (!resources_.empty()) {
1034 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, 1033 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_,
1035 OnReadyPeriodicalUpdate()); 1034 OnReadyPeriodicalUpdate());
1036 } 1035 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 if (info) 1169 if (info)
1171 info->GetAssociatedRenderView(&render_process_host_child_id, &routing_id); 1170 info->GetAssociatedRenderView(&render_process_host_child_id, &routing_id);
1172 1171
1173 // Get the origin PID of the request's originator. This will only be set for 1172 // Get the origin PID of the request's originator. This will only be set for
1174 // plugins - for renderer or browser initiated requests it will be zero. 1173 // plugins - for renderer or browser initiated requests it will be zero.
1175 int origin_pid = 0; 1174 int origin_pid = 0;
1176 if (info) 1175 if (info)
1177 origin_pid = info->GetOriginPID(); 1176 origin_pid = info->GetOriginPID();
1178 1177
1179 if (bytes_read_buffer_.empty()) { 1178 if (bytes_read_buffer_.empty()) {
1180 MessageLoop::current()->PostDelayedTask( 1179 base::MessageLoop::current()->PostDelayedTask(
1181 FROM_HERE, 1180 FROM_HERE,
1182 base::Bind(&TaskManagerModel::NotifyMultipleBytesRead, this), 1181 base::Bind(&TaskManagerModel::NotifyMultipleBytesRead, this),
1183 base::TimeDelta::FromSeconds(1)); 1182 base::TimeDelta::FromSeconds(1));
1184 } 1183 }
1185 1184
1186 bytes_read_buffer_.push_back( 1185 bytes_read_buffer_.push_back(
1187 BytesReadParam(origin_pid, render_process_host_child_id, 1186 BytesReadParam(origin_pid, render_process_host_child_id,
1188 routing_id, byte_count)); 1187 routing_id, byte_count));
1189 } 1188 }
1190 1189
1191 TaskManagerModel::~TaskManagerModel() { 1190 TaskManagerModel::~TaskManagerModel() {
1192 } 1191 }
1193 1192
1194 void TaskManagerModel::RefreshCallback() { 1193 void TaskManagerModel::RefreshCallback() {
1195 DCHECK_NE(IDLE, update_state_); 1194 DCHECK_NE(IDLE, update_state_);
1196 1195
1197 if (update_state_ == STOPPING) { 1196 if (update_state_ == STOPPING) {
1198 // We have been asked to stop. 1197 // We have been asked to stop.
1199 update_state_ = IDLE; 1198 update_state_ = IDLE;
1200 return; 1199 return;
1201 } 1200 }
1202 1201
1203 Refresh(); 1202 Refresh();
1204 1203
1205 // Schedule the next update. 1204 // Schedule the next update.
1206 MessageLoop::current()->PostDelayedTask( 1205 base::MessageLoop::current()->PostDelayedTask(
1207 FROM_HERE, 1206 FROM_HERE,
1208 base::Bind(&TaskManagerModel::RefreshCallback, this), 1207 base::Bind(&TaskManagerModel::RefreshCallback, this),
1209 base::TimeDelta::FromMilliseconds(kUpdateTimeMs)); 1208 base::TimeDelta::FromMilliseconds(kUpdateTimeMs));
1210 } 1209 }
1211 1210
1212 void TaskManagerModel::Refresh() { 1211 void TaskManagerModel::Refresh() {
1213 goat_salt_ = base::RandUint64(); 1212 goat_salt_ = base::RandUint64();
1214 1213
1215 per_resource_cache_.clear(); 1214 per_resource_cache_.clear();
1216 per_process_cache_.clear(); 1215 per_process_cache_.clear();
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 } 1578 }
1580 return count; 1579 return count;
1581 } 1580 }
1582 1581
1583 TaskManager::TaskManager() 1582 TaskManager::TaskManager()
1584 : ALLOW_THIS_IN_INITIALIZER_LIST(model_(new TaskManagerModel(this))) { 1583 : ALLOW_THIS_IN_INITIALIZER_LIST(model_(new TaskManagerModel(this))) {
1585 } 1584 }
1586 1585
1587 TaskManager::~TaskManager() { 1586 TaskManager::~TaskManager() {
1588 } 1587 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698