| 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/task_manager_worker_resource_provider.h" | 5 #include "chrome/browser/task_manager/worker_resource_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include <vector> |
| 8 #include "base/bind_helpers.h" | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/string16.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_process.h" | |
| 12 #include "chrome/browser/devtools/devtools_window.h" | 12 #include "chrome/browser/devtools/devtools_window.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/common/chrome_process_type.h" | 14 #include "chrome/common/chrome_process_type.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/child_process_data.h" | 16 #include "content/public/browser/child_process_data.h" |
| 17 #include "content/public/browser/devtools_agent_host.h" | 17 #include "content/public/browser/devtools_agent_host.h" |
| 18 #include "content/public/browser/worker_service.h" | 18 #include "content/public/browser/worker_service.h" |
| 19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 20 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
| 24 | 24 |
| 25 using content::BrowserThread; | 25 using content::BrowserThread; |
| 26 using content::DevToolsAgentHost; | 26 using content::DevToolsAgentHost; |
| 27 using content::WorkerService; | 27 using content::WorkerService; |
| 28 | 28 |
| 29 namespace task_manager { |
| 30 |
| 29 // Objects of this class are created on the IO thread and then passed to the UI | 31 // Objects of this class are created on the IO thread and then passed to the UI |
| 30 // thread where they are passed to the task manager. All methods must be called | 32 // thread where they are passed to the task manager. All methods must be called |
| 31 // only on the UI thread. Destructor may be called on any thread. | 33 // only on the UI thread. Destructor may be called on any thread. |
| 32 class TaskManagerSharedWorkerResource : public TaskManager::Resource { | 34 class SharedWorkerResource : public TaskManager::Resource { |
| 33 public: | 35 public: |
| 34 TaskManagerSharedWorkerResource(const GURL& url, | 36 SharedWorkerResource(const GURL& url, |
| 35 const string16& name, | 37 const string16& name, |
| 36 int process_id, | 38 int process_id, |
| 37 int routing_id, | 39 int routing_id, |
| 38 base::ProcessHandle process_handle); | 40 base::ProcessHandle process_handle); |
| 39 virtual ~TaskManagerSharedWorkerResource(); | 41 virtual ~SharedWorkerResource(); |
| 40 | 42 |
| 41 bool Matches(int process_id, int routing_id) const; | 43 bool Matches(int process_id, int routing_id) const; |
| 42 | 44 |
| 43 void UpdateProcessHandle(base::ProcessHandle handle); | 45 void UpdateProcessHandle(base::ProcessHandle handle); |
| 44 base::ProcessHandle handle() const { return handle_; } | 46 base::ProcessHandle handle() const { return handle_; } |
| 45 int process_id() const { return process_id_; } | 47 int process_id() const { return process_id_; } |
| 46 | 48 |
| 47 private: | 49 private: |
| 48 // TaskManager::Resource methods: | 50 // TaskManager::Resource methods: |
| 49 virtual string16 GetTitle() const OVERRIDE; | 51 virtual string16 GetTitle() const OVERRIDE; |
| 50 virtual string16 GetProfileName() const OVERRIDE; | 52 virtual string16 GetProfileName() const OVERRIDE; |
| 51 virtual gfx::ImageSkia GetIcon() const OVERRIDE; | 53 virtual gfx::ImageSkia GetIcon() const OVERRIDE; |
| 52 virtual base::ProcessHandle GetProcess() const OVERRIDE; | 54 virtual base::ProcessHandle GetProcess() const OVERRIDE; |
| 53 virtual int GetUniqueChildProcessId() const OVERRIDE; | 55 virtual int GetUniqueChildProcessId() const OVERRIDE; |
| 54 virtual Type GetType() const OVERRIDE; | 56 virtual Type GetType() const OVERRIDE; |
| 55 virtual bool CanInspect() const OVERRIDE; | 57 virtual bool CanInspect() const OVERRIDE; |
| 56 virtual void Inspect() const OVERRIDE; | 58 virtual void Inspect() const OVERRIDE; |
| 57 | 59 |
| 58 virtual bool SupportNetworkUsage() const OVERRIDE; | 60 virtual bool SupportNetworkUsage() const OVERRIDE; |
| 59 virtual void SetSupportNetworkUsage() OVERRIDE; | 61 virtual void SetSupportNetworkUsage() OVERRIDE; |
| 60 | 62 |
| 61 int process_id_; | 63 int process_id_; |
| 62 int routing_id_; | 64 int routing_id_; |
| 63 string16 title_; | 65 string16 title_; |
| 64 base::ProcessHandle handle_; | 66 base::ProcessHandle handle_; |
| 65 | 67 |
| 66 static gfx::ImageSkia* default_icon_; | 68 static gfx::ImageSkia* default_icon_; |
| 67 | 69 |
| 68 DISALLOW_COPY_AND_ASSIGN(TaskManagerSharedWorkerResource); | 70 DISALLOW_COPY_AND_ASSIGN(SharedWorkerResource); |
| 69 }; | 71 }; |
| 70 | 72 |
| 71 gfx::ImageSkia* TaskManagerSharedWorkerResource::default_icon_ = NULL; | 73 gfx::ImageSkia* SharedWorkerResource::default_icon_ = NULL; |
| 72 | 74 |
| 73 TaskManagerSharedWorkerResource::TaskManagerSharedWorkerResource( | 75 SharedWorkerResource::SharedWorkerResource( |
| 74 const GURL& url, | 76 const GURL& url, |
| 75 const string16& name, | 77 const string16& name, |
| 76 int process_id, | 78 int process_id, |
| 77 int routing_id, | 79 int routing_id, |
| 78 base::ProcessHandle process_handle) | 80 base::ProcessHandle process_handle) |
| 79 : process_id_(process_id), | 81 : process_id_(process_id), |
| 80 routing_id_(routing_id), | 82 routing_id_(routing_id), |
| 81 handle_(process_handle) { | 83 handle_(process_handle) { |
| 82 title_ = UTF8ToUTF16(url.spec()); | 84 title_ = UTF8ToUTF16(url.spec()); |
| 83 if (!name.empty()) | 85 if (!name.empty()) |
| 84 title_ += ASCIIToUTF16(" (") + name + ASCIIToUTF16(")"); | 86 title_ += ASCIIToUTF16(" (") + name + ASCIIToUTF16(")"); |
| 85 } | 87 } |
| 86 | 88 |
| 87 TaskManagerSharedWorkerResource::~TaskManagerSharedWorkerResource() { | 89 SharedWorkerResource::~SharedWorkerResource() { |
| 88 } | 90 } |
| 89 | 91 |
| 90 bool TaskManagerSharedWorkerResource::Matches(int process_id, | 92 bool SharedWorkerResource::Matches(int process_id, |
| 91 int routing_id) const { | 93 int routing_id) const { |
| 92 return process_id_ == process_id && routing_id_ == routing_id; | 94 return process_id_ == process_id && routing_id_ == routing_id; |
| 93 } | 95 } |
| 94 | 96 |
| 95 void TaskManagerSharedWorkerResource::UpdateProcessHandle( | 97 void SharedWorkerResource::UpdateProcessHandle(base::ProcessHandle handle) { |
| 96 base::ProcessHandle handle) { | |
| 97 handle_ = handle; | 98 handle_ = handle; |
| 98 } | 99 } |
| 99 | 100 |
| 100 string16 TaskManagerSharedWorkerResource::GetTitle() const { | 101 string16 SharedWorkerResource::GetTitle() const { |
| 101 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_WORKER_PREFIX, title_); | 102 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_WORKER_PREFIX, title_); |
| 102 } | 103 } |
| 103 | 104 |
| 104 string16 TaskManagerSharedWorkerResource::GetProfileName() const { | 105 string16 SharedWorkerResource::GetProfileName() const { |
| 105 return string16(); | 106 return string16(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 gfx::ImageSkia TaskManagerSharedWorkerResource::GetIcon() const { | 109 gfx::ImageSkia SharedWorkerResource::GetIcon() const { |
| 109 if (!default_icon_) { | 110 if (!default_icon_) { |
| 110 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 111 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 111 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); | 112 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); |
| 112 // TODO(jabdelmalek): use different icon for web workers. | 113 // TODO(jabdelmalek): use different icon for web workers. |
| 113 } | 114 } |
| 114 return *default_icon_; | 115 return *default_icon_; |
| 115 } | 116 } |
| 116 | 117 |
| 117 base::ProcessHandle TaskManagerSharedWorkerResource::GetProcess() const { | 118 base::ProcessHandle SharedWorkerResource::GetProcess() const { |
| 118 return handle_; | 119 return handle_; |
| 119 } | 120 } |
| 120 | 121 |
| 121 int TaskManagerSharedWorkerResource::GetUniqueChildProcessId() const { | 122 int SharedWorkerResource::GetUniqueChildProcessId() const { |
| 122 return process_id_; | 123 return process_id_; |
| 123 } | 124 } |
| 124 | 125 |
| 125 TaskManager::Resource::Type TaskManagerSharedWorkerResource::GetType() const { | 126 TaskManager::Resource::Type SharedWorkerResource::GetType() const { |
| 126 return WORKER; | 127 return WORKER; |
| 127 } | 128 } |
| 128 | 129 |
| 129 bool TaskManagerSharedWorkerResource::CanInspect() const { | 130 bool SharedWorkerResource::CanInspect() const { |
| 130 return true; | 131 return true; |
| 131 } | 132 } |
| 132 | 133 |
| 133 void TaskManagerSharedWorkerResource::Inspect() const { | 134 void SharedWorkerResource::Inspect() const { |
| 134 // TODO(yurys): would be better to get profile from one of the tabs connected | 135 // TODO(yurys): would be better to get profile from one of the tabs connected |
| 135 // to the worker. | 136 // to the worker. |
| 136 Profile* profile = ProfileManager::GetLastUsedProfile(); | 137 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 137 if (!profile) | 138 if (!profile) |
| 138 return; | 139 return; |
| 139 scoped_refptr<DevToolsAgentHost> agent_host( | 140 scoped_refptr<DevToolsAgentHost> agent_host( |
| 140 DevToolsAgentHost::GetForWorker(process_id_, routing_id_)); | 141 DevToolsAgentHost::GetForWorker(process_id_, routing_id_)); |
| 141 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); | 142 DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host); |
| 142 } | 143 } |
| 143 | 144 |
| 144 bool TaskManagerSharedWorkerResource::SupportNetworkUsage() const { | 145 bool SharedWorkerResource::SupportNetworkUsage() const { |
| 145 return false; | 146 return false; |
| 146 } | 147 } |
| 147 | 148 |
| 148 void TaskManagerSharedWorkerResource::SetSupportNetworkUsage() { | 149 void SharedWorkerResource::SetSupportNetworkUsage() { |
| 149 } | 150 } |
| 150 | 151 |
| 151 | 152 |
| 152 // This class is needed to ensure that all resources in WorkerResourceList are | 153 // This class is needed to ensure that all resources in WorkerResourceList are |
| 153 // deleted if corresponding task is posted to but not executed on the UI | 154 // deleted if corresponding task is posted to but not executed on the UI |
| 154 // thread. | 155 // thread. |
| 155 class TaskManagerWorkerResourceProvider::WorkerResourceListHolder { | 156 class WorkerResourceProvider::WorkerResourceListHolder { |
| 156 public: | 157 public: |
| 157 WorkerResourceListHolder() { | 158 WorkerResourceListHolder() { |
| 158 } | 159 } |
| 159 | 160 |
| 160 ~WorkerResourceListHolder() { | 161 ~WorkerResourceListHolder() { |
| 161 STLDeleteElements(&resources_); | 162 STLDeleteElements(&resources_); |
| 162 } | 163 } |
| 163 | 164 |
| 164 WorkerResourceList* resources() { | 165 WorkerResourceList* resources() { |
| 165 return &resources_; | 166 return &resources_; |
| 166 } | 167 } |
| 167 | 168 |
| 168 private: | 169 private: |
| 169 WorkerResourceList resources_; | 170 WorkerResourceList resources_; |
| 170 }; | 171 }; |
| 171 | 172 |
| 172 | 173 |
| 173 TaskManagerWorkerResourceProvider:: | 174 WorkerResourceProvider:: |
| 174 TaskManagerWorkerResourceProvider(TaskManager* task_manager) | 175 WorkerResourceProvider(TaskManager* task_manager) |
| 175 : updating_(false), | 176 : updating_(false), |
| 176 task_manager_(task_manager) { | 177 task_manager_(task_manager) { |
| 177 } | 178 } |
| 178 | 179 |
| 179 TaskManagerWorkerResourceProvider::~TaskManagerWorkerResourceProvider() { | 180 WorkerResourceProvider::~WorkerResourceProvider() { |
| 180 DeleteAllResources(); | 181 DeleteAllResources(); |
| 181 } | 182 } |
| 182 | 183 |
| 183 TaskManager::Resource* TaskManagerWorkerResourceProvider::GetResource( | 184 TaskManager::Resource* WorkerResourceProvider::GetResource( |
| 184 int origin_pid, | 185 int origin_pid, |
| 185 int render_process_host_id, | 186 int render_process_host_id, |
| 186 int routing_id) { | 187 int routing_id) { |
| 187 return NULL; | 188 return NULL; |
| 188 } | 189 } |
| 189 | 190 |
| 190 void TaskManagerWorkerResourceProvider::StartUpdating() { | 191 void WorkerResourceProvider::StartUpdating() { |
| 191 DCHECK(!updating_); | 192 DCHECK(!updating_); |
| 192 updating_ = true; | 193 updating_ = true; |
| 193 // Get existing workers. | 194 // Get existing workers. |
| 194 BrowserThread::PostTask( | 195 BrowserThread::PostTask( |
| 195 BrowserThread::IO, FROM_HERE, base::Bind( | 196 BrowserThread::IO, FROM_HERE, base::Bind( |
| 196 &TaskManagerWorkerResourceProvider::StartObservingWorkers, | 197 &WorkerResourceProvider::StartObservingWorkers, |
| 197 this)); | 198 this)); |
| 198 | 199 |
| 199 BrowserChildProcessObserver::Add(this); | 200 BrowserChildProcessObserver::Add(this); |
| 200 } | 201 } |
| 201 | 202 |
| 202 void TaskManagerWorkerResourceProvider::StopUpdating() { | 203 void WorkerResourceProvider::StopUpdating() { |
| 203 DCHECK(updating_); | 204 DCHECK(updating_); |
| 204 updating_ = false; | 205 updating_ = false; |
| 205 launching_workers_.clear(); | 206 launching_workers_.clear(); |
| 206 DeleteAllResources(); | 207 DeleteAllResources(); |
| 207 BrowserThread::PostTask( | 208 BrowserThread::PostTask( |
| 208 BrowserThread::IO, FROM_HERE, base::Bind( | 209 BrowserThread::IO, FROM_HERE, base::Bind( |
| 209 &TaskManagerWorkerResourceProvider::StopObservingWorkers, | 210 &WorkerResourceProvider::StopObservingWorkers, |
| 210 this)); | 211 this)); |
| 211 | 212 |
| 212 BrowserChildProcessObserver::Remove(this); | 213 BrowserChildProcessObserver::Remove(this); |
| 213 } | 214 } |
| 214 | 215 |
| 215 void TaskManagerWorkerResourceProvider::BrowserChildProcessHostConnected( | 216 void WorkerResourceProvider::BrowserChildProcessHostConnected( |
| 216 const content::ChildProcessData& data) { | 217 const content::ChildProcessData& data) { |
| 217 DCHECK(updating_); | 218 DCHECK(updating_); |
| 218 | 219 |
| 219 if (data.process_type != content::PROCESS_TYPE_WORKER) | 220 if (data.process_type != content::PROCESS_TYPE_WORKER) |
| 220 return; | 221 return; |
| 221 | 222 |
| 222 ProcessIdToWorkerResources::iterator it(launching_workers_.find(data.id)); | 223 ProcessIdToWorkerResources::iterator it(launching_workers_.find(data.id)); |
| 223 if (it == launching_workers_.end()) | 224 if (it == launching_workers_.end()) |
| 224 return; | 225 return; |
| 225 WorkerResourceList& resources = it->second; | 226 WorkerResourceList& resources = it->second; |
| 226 for (WorkerResourceList::iterator r = resources.begin(); | 227 for (WorkerResourceList::iterator r = resources.begin(); |
| 227 r != resources.end(); ++r) { | 228 r != resources.end(); ++r) { |
| 228 (*r)->UpdateProcessHandle(data.handle); | 229 (*r)->UpdateProcessHandle(data.handle); |
| 229 task_manager_->AddResource(*r); | 230 task_manager_->AddResource(*r); |
| 230 } | 231 } |
| 231 launching_workers_.erase(it); | 232 launching_workers_.erase(it); |
| 232 } | 233 } |
| 233 | 234 |
| 234 void TaskManagerWorkerResourceProvider::BrowserChildProcessHostDisconnected( | 235 void WorkerResourceProvider::BrowserChildProcessHostDisconnected( |
| 235 const content::ChildProcessData& data) { | 236 const content::ChildProcessData& data) { |
| 236 DCHECK(updating_); | 237 DCHECK(updating_); |
| 237 | 238 |
| 238 if (data.process_type != content::PROCESS_TYPE_WORKER) | 239 if (data.process_type != content::PROCESS_TYPE_WORKER) |
| 239 return; | 240 return; |
| 240 | 241 |
| 241 // Worker process may be destroyed before WorkerMsg_TerminateWorkerContex | 242 // Worker process may be destroyed before WorkerMsg_TerminateWorkerContex |
| 242 // message is handled and WorkerDestroyed is fired. In this case we won't | 243 // message is handled and WorkerDestroyed is fired. In this case we won't |
| 243 // get WorkerDestroyed notification and have to clear resources for such | 244 // get WorkerDestroyed notification and have to clear resources for such |
| 244 // workers here when the worker process has been destroyed. | 245 // workers here when the worker process has been destroyed. |
| 245 for (WorkerResourceList::iterator it = resources_.begin(); | 246 for (WorkerResourceList::iterator it = resources_.begin(); |
| 246 it != resources_.end();) { | 247 it != resources_.end();) { |
| 247 if ((*it)->process_id() == data.id) { | 248 if ((*it)->process_id() == data.id) { |
| 248 task_manager_->RemoveResource(*it); | 249 task_manager_->RemoveResource(*it); |
| 249 delete *it; | 250 delete *it; |
| 250 it = resources_.erase(it); | 251 it = resources_.erase(it); |
| 251 } else { | 252 } else { |
| 252 ++it; | 253 ++it; |
| 253 } | 254 } |
| 254 } | 255 } |
| 255 DCHECK(!ContainsKey(launching_workers_, data.id)); | 256 DCHECK(!ContainsKey(launching_workers_, data.id)); |
| 256 } | 257 } |
| 257 | 258 |
| 258 void TaskManagerWorkerResourceProvider::WorkerCreated( | 259 void WorkerResourceProvider::WorkerCreated( |
| 259 const GURL& url, | 260 const GURL& url, |
| 260 const string16& name, | 261 const string16& name, |
| 261 int process_id, | 262 int process_id, |
| 262 int route_id) { | 263 int route_id) { |
| 263 TaskManagerSharedWorkerResource* resource = | 264 SharedWorkerResource* resource = new SharedWorkerResource( |
| 264 new TaskManagerSharedWorkerResource( | 265 url, name, process_id, route_id, base::kNullProcessHandle); |
| 265 url, name, process_id, route_id, base::kNullProcessHandle); | |
| 266 BrowserThread::PostTask( | 266 BrowserThread::PostTask( |
| 267 BrowserThread::UI, FROM_HERE, | 267 BrowserThread::UI, FROM_HERE, |
| 268 base::Bind(&TaskManagerWorkerResourceProvider::NotifyWorkerCreated, | 268 base::Bind(&WorkerResourceProvider::NotifyWorkerCreated, |
| 269 this, base::Owned(new WorkerResourceHolder(resource)))); | 269 this, base::Owned(new WorkerResourceHolder(resource)))); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void TaskManagerWorkerResourceProvider::WorkerDestroyed(int process_id, | 272 void WorkerResourceProvider::WorkerDestroyed(int process_id, int route_id) { |
| 273 int route_id) { | |
| 274 BrowserThread::PostTask( | 273 BrowserThread::PostTask( |
| 275 BrowserThread::UI, FROM_HERE, base::Bind( | 274 BrowserThread::UI, FROM_HERE, base::Bind( |
| 276 &TaskManagerWorkerResourceProvider::NotifyWorkerDestroyed, | 275 &WorkerResourceProvider::NotifyWorkerDestroyed, |
| 277 this, process_id, route_id)); | 276 this, process_id, route_id)); |
| 278 } | 277 } |
| 279 | 278 |
| 280 void TaskManagerWorkerResourceProvider::NotifyWorkerCreated( | 279 void WorkerResourceProvider::NotifyWorkerCreated( |
| 281 WorkerResourceHolder* resource_holder) { | 280 WorkerResourceHolder* resource_holder) { |
| 282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 283 if (!updating_) | 282 if (!updating_) |
| 284 return; | 283 return; |
| 285 AddResource(resource_holder->release()); | 284 AddResource(resource_holder->release()); |
| 286 } | 285 } |
| 287 | 286 |
| 288 void TaskManagerWorkerResourceProvider::NotifyWorkerDestroyed( | 287 void WorkerResourceProvider::NotifyWorkerDestroyed( |
| 289 int process_id, int routing_id) { | 288 int process_id, int routing_id) { |
| 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 291 if (!updating_) | 290 if (!updating_) |
| 292 return; | 291 return; |
| 293 for (WorkerResourceList::iterator it = resources_.begin(); | 292 for (WorkerResourceList::iterator it = resources_.begin(); |
| 294 it !=resources_.end(); ++it) { | 293 it !=resources_.end(); ++it) { |
| 295 if ((*it)->Matches(process_id, routing_id)) { | 294 if ((*it)->Matches(process_id, routing_id)) { |
| 296 task_manager_->RemoveResource(*it); | 295 task_manager_->RemoveResource(*it); |
| 297 delete *it; | 296 delete *it; |
| 298 resources_.erase(it); | 297 resources_.erase(it); |
| 299 return; | 298 return; |
| 300 } | 299 } |
| 301 } | 300 } |
| 302 } | 301 } |
| 303 | 302 |
| 304 void TaskManagerWorkerResourceProvider::StartObservingWorkers() { | 303 void WorkerResourceProvider::StartObservingWorkers() { |
| 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 306 | 305 |
| 307 scoped_ptr<WorkerResourceListHolder> holder(new WorkerResourceListHolder); | 306 scoped_ptr<WorkerResourceListHolder> holder(new WorkerResourceListHolder); |
| 308 std::vector<WorkerService::WorkerInfo> worker_info = | 307 std::vector<WorkerService::WorkerInfo> worker_info = |
| 309 WorkerService::GetInstance()->GetWorkers(); | 308 WorkerService::GetInstance()->GetWorkers(); |
| 310 | 309 |
| 311 for (size_t i = 0; i < worker_info.size(); ++i) { | 310 for (size_t i = 0; i < worker_info.size(); ++i) { |
| 312 holder->resources()->push_back(new TaskManagerSharedWorkerResource( | 311 holder->resources()->push_back(new SharedWorkerResource( |
| 313 worker_info[i].url, worker_info[i].name, worker_info[i].process_id, | 312 worker_info[i].url, worker_info[i].name, worker_info[i].process_id, |
| 314 worker_info[i].route_id, worker_info[i].handle)); | 313 worker_info[i].route_id, worker_info[i].handle)); |
| 315 } | 314 } |
| 316 | 315 |
| 317 BrowserThread::PostTask( | 316 BrowserThread::PostTask( |
| 318 BrowserThread::UI, FROM_HERE, | 317 BrowserThread::UI, FROM_HERE, |
| 319 base::Bind( | 318 base::Bind( |
| 320 &TaskManagerWorkerResourceProvider::AddWorkerResourceList, | 319 &WorkerResourceProvider::AddWorkerResourceList, |
| 321 this, base::Owned(holder.release()))); | 320 this, base::Owned(holder.release()))); |
| 322 | 321 |
| 323 WorkerService::GetInstance()->AddObserver(this); | 322 WorkerService::GetInstance()->AddObserver(this); |
| 324 } | 323 } |
| 325 | 324 |
| 326 void TaskManagerWorkerResourceProvider::StopObservingWorkers() { | 325 void WorkerResourceProvider::StopObservingWorkers() { |
| 327 WorkerService::GetInstance()->RemoveObserver(this); | 326 WorkerService::GetInstance()->RemoveObserver(this); |
| 328 } | 327 } |
| 329 | 328 |
| 330 void TaskManagerWorkerResourceProvider::AddWorkerResourceList( | 329 void WorkerResourceProvider::AddWorkerResourceList( |
| 331 WorkerResourceListHolder* resource_list_holder) { | 330 WorkerResourceListHolder* resource_list_holder) { |
| 332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 333 if (!updating_) | 332 if (!updating_) |
| 334 return; | 333 return; |
| 335 WorkerResourceList* resources = resource_list_holder->resources(); | 334 WorkerResourceList* resources = resource_list_holder->resources(); |
| 336 for (WorkerResourceList::iterator it = resources->begin(); | 335 for (WorkerResourceList::iterator it = resources->begin(); |
| 337 it !=resources->end(); ++it) { | 336 it !=resources->end(); ++it) { |
| 338 AddResource(*it); | 337 AddResource(*it); |
| 339 } | 338 } |
| 340 resources->clear(); | 339 resources->clear(); |
| 341 } | 340 } |
| 342 | 341 |
| 343 void TaskManagerWorkerResourceProvider::AddResource( | 342 void WorkerResourceProvider::AddResource(SharedWorkerResource* resource) { |
| 344 TaskManagerSharedWorkerResource* resource) { | |
| 345 DCHECK(updating_); | 343 DCHECK(updating_); |
| 346 resources_.push_back(resource); | 344 resources_.push_back(resource); |
| 347 if (resource->handle() == base::kNullProcessHandle) { | 345 if (resource->handle() == base::kNullProcessHandle) { |
| 348 int process_id = resource->process_id(); | 346 int process_id = resource->process_id(); |
| 349 launching_workers_[process_id].push_back(resource); | 347 launching_workers_[process_id].push_back(resource); |
| 350 } else { | 348 } else { |
| 351 task_manager_->AddResource(resource); | 349 task_manager_->AddResource(resource); |
| 352 } | 350 } |
| 353 } | 351 } |
| 354 | 352 |
| 355 void TaskManagerWorkerResourceProvider::DeleteAllResources() { | 353 void WorkerResourceProvider::DeleteAllResources() { |
| 356 STLDeleteElements(&resources_); | 354 STLDeleteElements(&resources_); |
| 357 } | 355 } |
| 356 |
| 357 } // namespace task_manager |
| OLD | NEW |