| OLD | NEW |
| 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/notification_resource_provider.h" | 5 #include "chrome/browser/task_manager/notification_resource_provider.h" |
| 6 | 6 |
| 7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/devtools/devtools_window.h" | 10 #include "chrome/browser/devtools/devtools_window.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 RemoveFromTaskManager(content::Source<BalloonHost>(source).ptr()); | 198 RemoveFromTaskManager(content::Source<BalloonHost>(source).ptr()); |
| 199 break; | 199 break; |
| 200 default: | 200 default: |
| 201 NOTREACHED() << "Unexpected notification."; | 201 NOTREACHED() << "Unexpected notification."; |
| 202 return; | 202 return; |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 | 205 |
| 206 void NotificationResourceProvider::AddToTaskManager( | 206 void NotificationResourceProvider::AddToTaskManager( |
| 207 BalloonHost* balloon_host) { | 207 BalloonHost* balloon_host) { |
| 208 // The resource may already be tracked, if the task manager was opened |
| 209 // while the BalloonHost was waiting to connect. |
| 210 if (resources_.count(balloon_host)) |
| 211 return; |
| 208 NotificationResource* resource = new NotificationResource(balloon_host); | 212 NotificationResource* resource = new NotificationResource(balloon_host); |
| 209 DCHECK(resources_.find(balloon_host) == resources_.end()); | |
| 210 resources_[balloon_host] = resource; | 213 resources_[balloon_host] = resource; |
| 211 task_manager_->AddResource(resource); | 214 task_manager_->AddResource(resource); |
| 212 } | 215 } |
| 213 | 216 |
| 214 void NotificationResourceProvider::RemoveFromTaskManager( | 217 void NotificationResourceProvider::RemoveFromTaskManager( |
| 215 BalloonHost* balloon_host) { | 218 BalloonHost* balloon_host) { |
| 216 if (!updating_) | 219 if (!updating_) |
| 217 return; | 220 return; |
| 218 std::map<BalloonHost*, NotificationResource*>::iterator iter = | 221 std::map<BalloonHost*, NotificationResource*>::iterator iter = |
| 219 resources_.find(balloon_host); | 222 resources_.find(balloon_host); |
| 220 if (iter == resources_.end()) | 223 if (iter == resources_.end()) |
| 221 return; | 224 return; |
| 222 | 225 |
| 223 // Remove the resource from the Task Manager. | 226 // Remove the resource from the Task Manager. |
| 224 NotificationResource* resource = iter->second; | 227 NotificationResource* resource = iter->second; |
| 225 task_manager_->RemoveResource(resource); | 228 task_manager_->RemoveResource(resource); |
| 226 | 229 |
| 227 // Remove it from the map. | 230 // Remove it from the map. |
| 228 resources_.erase(iter); | 231 resources_.erase(iter); |
| 229 | 232 |
| 230 // Finally, delete the resource. | 233 // Finally, delete the resource. |
| 231 delete resource; | 234 delete resource; |
| 232 } | 235 } |
| 233 | 236 |
| 234 } // namespace task_manager | 237 } // namespace task_manager |
| OLD | NEW |