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

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: rebase again Created 7 years, 6 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/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/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_registry_simple.h"
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 // action the first time. 1070 // action the first time.
1071 update_requests_++; 1071 update_requests_++;
1072 if (update_requests_ > 1) 1072 if (update_requests_ > 1)
1073 return; 1073 return;
1074 DCHECK_EQ(1, update_requests_); 1074 DCHECK_EQ(1, update_requests_);
1075 DCHECK_NE(TASK_PENDING, update_state_); 1075 DCHECK_NE(TASK_PENDING, update_state_);
1076 1076
1077 // If update_state_ is STOPPING, it means a task is still pending. Setting 1077 // If update_state_ is STOPPING, it means a task is still pending. Setting
1078 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()). 1078 // it to TASK_PENDING ensures the tasks keep being posted (by Refresh()).
1079 if (update_state_ == IDLE) { 1079 if (update_state_ == IDLE) {
1080 MessageLoop::current()->PostTask( 1080 base::MessageLoop::current()->PostTask(
1081 FROM_HERE, 1081 FROM_HERE,
1082 base::Bind(&TaskManagerModel::RefreshCallback, this)); 1082 base::Bind(&TaskManagerModel::RefreshCallback, this));
1083 } 1083 }
1084 update_state_ = TASK_PENDING; 1084 update_state_ = TASK_PENDING;
1085 1085
1086 // Notify resource providers that we are updating. 1086 // Notify resource providers that we are updating.
1087 StartListening(); 1087 StartListening();
1088 1088
1089 if (!resources_.empty()) { 1089 if (!resources_.empty()) {
1090 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_, 1090 FOR_EACH_OBSERVER(TaskManagerModelObserver, observer_list_,
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 if (info) 1226 if (info)
1227 info->GetAssociatedRenderView(&render_process_host_child_id, &routing_id); 1227 info->GetAssociatedRenderView(&render_process_host_child_id, &routing_id);
1228 1228
1229 // Get the origin PID of the request's originator. This will only be set for 1229 // Get the origin PID of the request's originator. This will only be set for
1230 // plugins - for renderer or browser initiated requests it will be zero. 1230 // plugins - for renderer or browser initiated requests it will be zero.
1231 int origin_pid = 0; 1231 int origin_pid = 0;
1232 if (info) 1232 if (info)
1233 origin_pid = info->GetOriginPID(); 1233 origin_pid = info->GetOriginPID();
1234 1234
1235 if (bytes_read_buffer_.empty()) { 1235 if (bytes_read_buffer_.empty()) {
1236 MessageLoop::current()->PostDelayedTask( 1236 base::MessageLoop::current()->PostDelayedTask(
1237 FROM_HERE, 1237 FROM_HERE,
1238 base::Bind(&TaskManagerModel::NotifyMultipleBytesRead, this), 1238 base::Bind(&TaskManagerModel::NotifyMultipleBytesRead, this),
1239 base::TimeDelta::FromSeconds(1)); 1239 base::TimeDelta::FromSeconds(1));
1240 } 1240 }
1241 1241
1242 bytes_read_buffer_.push_back( 1242 bytes_read_buffer_.push_back(
1243 BytesReadParam(origin_pid, render_process_host_child_id, 1243 BytesReadParam(origin_pid, render_process_host_child_id,
1244 routing_id, byte_count)); 1244 routing_id, byte_count));
1245 } 1245 }
1246 1246
1247 TaskManagerModel::~TaskManagerModel() { 1247 TaskManagerModel::~TaskManagerModel() {
1248 } 1248 }
1249 1249
1250 void TaskManagerModel::RefreshCallback() { 1250 void TaskManagerModel::RefreshCallback() {
1251 DCHECK_NE(IDLE, update_state_); 1251 DCHECK_NE(IDLE, update_state_);
1252 1252
1253 if (update_state_ == STOPPING) { 1253 if (update_state_ == STOPPING) {
1254 // We have been asked to stop. 1254 // We have been asked to stop.
1255 update_state_ = IDLE; 1255 update_state_ = IDLE;
1256 return; 1256 return;
1257 } 1257 }
1258 1258
1259 Refresh(); 1259 Refresh();
1260 1260
1261 // Schedule the next update. 1261 // Schedule the next update.
1262 MessageLoop::current()->PostDelayedTask( 1262 base::MessageLoop::current()->PostDelayedTask(
1263 FROM_HERE, 1263 FROM_HERE,
1264 base::Bind(&TaskManagerModel::RefreshCallback, this), 1264 base::Bind(&TaskManagerModel::RefreshCallback, this),
1265 base::TimeDelta::FromMilliseconds(kUpdateTimeMs)); 1265 base::TimeDelta::FromMilliseconds(kUpdateTimeMs));
1266 } 1266 }
1267 1267
1268 void TaskManagerModel::Refresh() { 1268 void TaskManagerModel::Refresh() {
1269 goat_salt_ = base::RandUint64(); 1269 goat_salt_ = base::RandUint64();
1270 1270
1271 per_resource_cache_.clear(); 1271 per_resource_cache_.clear();
1272 per_process_cache_.clear(); 1272 per_process_cache_.clear();
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 } 1577 }
1578 return count; 1578 return count;
1579 } 1579 }
1580 1580
1581 TaskManager::TaskManager() 1581 TaskManager::TaskManager()
1582 : model_(new TaskManagerModel(this)) { 1582 : model_(new TaskManagerModel(this)) {
1583 } 1583 }
1584 1584
1585 TaskManager::~TaskManager() { 1585 TaskManager::~TaskManager() {
1586 } 1586 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698