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

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

Issue 15196003: Create task_manager namespace and wrap classes related to TaskManager with it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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_tab_contents_resource_provide r.h" 5 #include "chrome/browser/task_manager/tab_contents_resource_provider.h"
6 6
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/favicon/favicon_tab_helper.h" 9 #include "chrome/browser/favicon/favicon_tab_helper.h"
10 #include "chrome/browser/prerender/prerender_manager.h" 10 #include "chrome/browser/prerender/prerender_manager.h"
11 #include "chrome/browser/prerender/prerender_manager_factory.h" 11 #include "chrome/browser/prerender/prerender_manager_factory.h"
12 #include "chrome/browser/printing/background_printing_manager.h" 12 #include "chrome/browser/printing/background_printing_manager.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/tab_contents/tab_util.h" 15 #include "chrome/browser/tab_contents/tab_util.h"
16 #include "chrome/browser/task_manager/task_manager_render_resource.h" 16 #include "chrome/browser/task_manager/renderer_resource.h"
17 #include "chrome/browser/task_manager/task_manager_resource_util.h" 17 #include "chrome/browser/task_manager/task_manager_util.h"
18 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_finder.h" 19 #include "chrome/browser/ui/browser_finder.h"
20 #include "chrome/browser/ui/browser_instant_controller.h" 20 #include "chrome/browser/ui/browser_instant_controller.h"
21 #include "chrome/browser/ui/browser_iterator.h" 21 #include "chrome/browser/ui/browser_iterator.h"
22 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 22 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
23 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
24 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/render_process_host.h" 25 #include "content/public/browser/render_process_host.h"
26 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "extensions/common/constants.h" 27 #include "extensions/common/constants.h"
28 #include "grit/theme_resources.h" 28 #include "grit/theme_resources.h"
29 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/gfx/image/image_skia.h" 31 #include "ui/gfx/image/image_skia.h"
32 32
33 using content::WebContents; 33 using content::WebContents;
34 using extensions::Extension; 34 using extensions::Extension;
35 35
36
37 namespace { 36 namespace {
38 37
39 bool IsContentsPrerendering(WebContents* web_contents) { 38 bool IsContentsPrerendering(WebContents* web_contents) {
40 Profile* profile = 39 Profile* profile =
41 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 40 Profile::FromBrowserContext(web_contents->GetBrowserContext());
42 prerender::PrerenderManager* prerender_manager = 41 prerender::PrerenderManager* prerender_manager =
43 prerender::PrerenderManagerFactory::GetForProfile(profile); 42 prerender::PrerenderManagerFactory::GetForProfile(profile);
44 return prerender_manager && 43 return prerender_manager &&
45 prerender_manager->IsWebContentsPrerendering(web_contents, NULL); 44 prerender_manager->IsWebContentsPrerendering(web_contents, NULL);
46 } 45 }
(...skipping 11 matching lines...) Expand all
58 } 57 }
59 58
60 bool IsContentsBackgroundPrinted(WebContents* web_contents) { 59 bool IsContentsBackgroundPrinted(WebContents* web_contents) {
61 printing::BackgroundPrintingManager* printing_manager = 60 printing::BackgroundPrintingManager* printing_manager =
62 g_browser_process->background_printing_manager(); 61 g_browser_process->background_printing_manager();
63 return printing_manager->HasPrintPreviewDialog(web_contents); 62 return printing_manager->HasPrintPreviewDialog(web_contents);
64 } 63 }
65 64
66 } // namespace 65 } // namespace
67 66
67 namespace task_manager {
68
68 // Tracks a single tab contents, prerendered page, Instant page, or background 69 // Tracks a single tab contents, prerendered page, Instant page, or background
69 // printing page. 70 // printing page.
70 class TaskManagerTabContentsResource : public TaskManagerRendererResource { 71 class TabContentsResource : public RendererResource {
71 public: 72 public:
72 explicit TaskManagerTabContentsResource(content::WebContents* web_contents); 73 explicit TabContentsResource(content::WebContents* web_contents);
73 virtual ~TaskManagerTabContentsResource(); 74 virtual ~TabContentsResource();
74 75
75 // Called when the underlying web_contents has been committed and is no 76 // Called when the underlying web_contents has been committed and is no
76 // longer an Instant overlay. 77 // longer an Instant overlay.
77 void InstantCommitted(); 78 void InstantCommitted();
78 79
79 // TaskManager::Resource methods: 80 // TaskManager::Resource methods:
80 virtual Type GetType() const OVERRIDE; 81 virtual Type GetType() const OVERRIDE;
81 virtual string16 GetTitle() const OVERRIDE; 82 virtual string16 GetTitle() const OVERRIDE;
82 virtual string16 GetProfileName() const OVERRIDE; 83 virtual string16 GetProfileName() const OVERRIDE;
83 virtual gfx::ImageSkia GetIcon() const OVERRIDE; 84 virtual gfx::ImageSkia GetIcon() const OVERRIDE;
84 virtual content::WebContents* GetWebContents() const OVERRIDE; 85 virtual content::WebContents* GetWebContents() const OVERRIDE;
85 virtual const extensions::Extension* GetExtension() const OVERRIDE; 86 virtual const extensions::Extension* GetExtension() const OVERRIDE;
86 87
87 private: 88 private:
88 // Returns true if contains content rendered by an extension. 89 // Returns true if contains content rendered by an extension.
89 bool HostsExtension() const; 90 bool HostsExtension() const;
90 91
91 static gfx::ImageSkia* prerender_icon_; 92 static gfx::ImageSkia* prerender_icon_;
92 content::WebContents* web_contents_; 93 content::WebContents* web_contents_;
93 Profile* profile_; 94 Profile* profile_;
94 bool is_instant_overlay_; 95 bool is_instant_overlay_;
95 96
96 DISALLOW_COPY_AND_ASSIGN(TaskManagerTabContentsResource); 97 DISALLOW_COPY_AND_ASSIGN(TabContentsResource);
97 }; 98 };
98 99
99 gfx::ImageSkia* TaskManagerTabContentsResource::prerender_icon_ = NULL; 100 gfx::ImageSkia* TabContentsResource::prerender_icon_ = NULL;
100 101
101 TaskManagerTabContentsResource::TaskManagerTabContentsResource( 102 TabContentsResource::TabContentsResource(
102 WebContents* web_contents) 103 WebContents* web_contents)
103 : TaskManagerRendererResource( 104 : RendererResource(web_contents->GetRenderProcessHost()->GetHandle(),
104 web_contents->GetRenderProcessHost()->GetHandle(), 105 web_contents->GetRenderViewHost()),
105 web_contents->GetRenderViewHost()),
106 web_contents_(web_contents), 106 web_contents_(web_contents),
107 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), 107 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
108 is_instant_overlay_(IsContentsInstant(web_contents)) { 108 is_instant_overlay_(IsContentsInstant(web_contents)) {
109 if (!prerender_icon_) { 109 if (!prerender_icon_) {
110 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 110 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
111 prerender_icon_ = rb.GetImageSkiaNamed(IDR_PRERENDER); 111 prerender_icon_ = rb.GetImageSkiaNamed(IDR_PRERENDER);
112 } 112 }
113 } 113 }
114 114
115 TaskManagerTabContentsResource::~TaskManagerTabContentsResource() { 115 TabContentsResource::~TabContentsResource() {
116 } 116 }
117 117
118 void TaskManagerTabContentsResource::InstantCommitted() { 118 void TabContentsResource::InstantCommitted() {
119 DCHECK(is_instant_overlay_); 119 DCHECK(is_instant_overlay_);
120 is_instant_overlay_ = false; 120 is_instant_overlay_ = false;
121 } 121 }
122 122
123 bool TaskManagerTabContentsResource::HostsExtension() const { 123 bool TabContentsResource::HostsExtension() const {
124 return web_contents_->GetURL().SchemeIs(extensions::kExtensionScheme); 124 return web_contents_->GetURL().SchemeIs(extensions::kExtensionScheme);
125 } 125 }
126 126
127 TaskManager::Resource::Type TaskManagerTabContentsResource::GetType() const { 127 TaskManager::Resource::Type TabContentsResource::GetType() const {
128 return HostsExtension() ? EXTENSION : RENDERER; 128 return HostsExtension() ? EXTENSION : RENDERER;
129 } 129 }
130 130
131 string16 TaskManagerTabContentsResource::GetTitle() const { 131 string16 TabContentsResource::GetTitle() const {
132 // Fall back on the URL if there's no title. 132 // Fall back on the URL if there's no title.
133 GURL url = web_contents_->GetURL(); 133 GURL url = web_contents_->GetURL();
134 string16 tab_title = 134 string16 tab_title = util::GetTitleFromWebContents(web_contents_);
135 TaskManagerResourceUtil::GetTitleFromWebContents(web_contents_);
136 135
137 // Only classify as an app if the URL is an app and the tab is hosting an 136 // Only classify as an app if the URL is an app and the tab is hosting an
138 // extension process. (It's possible to be showing the URL from before it 137 // extension process. (It's possible to be showing the URL from before it
139 // was installed as an app.) 138 // was installed as an app.)
140 ExtensionService* extension_service = profile_->GetExtensionService(); 139 ExtensionService* extension_service = profile_->GetExtensionService();
141 extensions::ProcessMap* process_map = extension_service->process_map(); 140 extensions::ProcessMap* process_map = extension_service->process_map();
142 bool is_app = extension_service->IsInstalledApp(url) && 141 bool is_app = extension_service->IsInstalledApp(url) &&
143 process_map->Contains(web_contents_->GetRenderProcessHost()->GetID()); 142 process_map->Contains(web_contents_->GetRenderProcessHost()->GetID());
144 143
145 int message_id = TaskManagerResourceUtil::GetMessagePrefixID( 144 int message_id = util::GetMessagePrefixID(
146 is_app, 145 is_app,
147 HostsExtension(), 146 HostsExtension(),
148 profile_->IsOffTheRecord(), 147 profile_->IsOffTheRecord(),
149 IsContentsPrerendering(web_contents_), 148 IsContentsPrerendering(web_contents_),
150 is_instant_overlay_, 149 is_instant_overlay_,
151 false); // is_background 150 false); // is_background
152 return l10n_util::GetStringFUTF16(message_id, tab_title); 151 return l10n_util::GetStringFUTF16(message_id, tab_title);
153 } 152 }
154 153
155 string16 TaskManagerTabContentsResource::GetProfileName() const { 154 string16 TabContentsResource::GetProfileName() const {
156 return TaskManagerResourceUtil::GetProfileNameFromInfoCache(profile_); 155 return util::GetProfileNameFromInfoCache(profile_);
157 } 156 }
158 157
159 gfx::ImageSkia TaskManagerTabContentsResource::GetIcon() const { 158 gfx::ImageSkia TabContentsResource::GetIcon() const {
160 if (IsContentsPrerendering(web_contents_)) 159 if (IsContentsPrerendering(web_contents_))
161 return *prerender_icon_; 160 return *prerender_icon_;
162 return FaviconTabHelper::FromWebContents(web_contents_)-> 161 return FaviconTabHelper::FromWebContents(web_contents_)->
163 GetFavicon().AsImageSkia(); 162 GetFavicon().AsImageSkia();
164 } 163 }
165 164
166 WebContents* TaskManagerTabContentsResource::GetWebContents() const { 165 WebContents* TabContentsResource::GetWebContents() const {
167 return web_contents_; 166 return web_contents_;
168 } 167 }
169 168
170 const Extension* TaskManagerTabContentsResource::GetExtension() const { 169 const Extension* TabContentsResource::GetExtension() const {
171 if (HostsExtension()) { 170 if (HostsExtension()) {
172 ExtensionService* extension_service = profile_->GetExtensionService(); 171 ExtensionService* extension_service = profile_->GetExtensionService();
173 return extension_service->extensions()->GetByID( 172 return extension_service->extensions()->GetByID(
174 web_contents_->GetURL().host()); 173 web_contents_->GetURL().host());
175 } 174 }
176 175
177 return NULL; 176 return NULL;
178 } 177 }
179 178
180 //////////////////////////////////////////////////////////////////////////////// 179 ////////////////////////////////////////////////////////////////////////////////
181 // TaskManagerTabContentsResourceProvider class 180 // TabContentsResourceProvider class
182 //////////////////////////////////////////////////////////////////////////////// 181 ////////////////////////////////////////////////////////////////////////////////
183 182
184 TaskManagerTabContentsResourceProvider:: 183 TabContentsResourceProvider::
185 TaskManagerTabContentsResourceProvider(TaskManager* task_manager) 184 TabContentsResourceProvider(TaskManager* task_manager)
186 : updating_(false), 185 : updating_(false),
187 task_manager_(task_manager) { 186 task_manager_(task_manager) {
188 } 187 }
189 188
190 TaskManagerTabContentsResourceProvider:: 189 TabContentsResourceProvider::~TabContentsResourceProvider() {
191 ~TaskManagerTabContentsResourceProvider() {
192 } 190 }
193 191
194 TaskManager::Resource* TaskManagerTabContentsResourceProvider::GetResource( 192 TaskManager::Resource* TabContentsResourceProvider::GetResource(
195 int origin_pid, 193 int origin_pid,
196 int render_process_host_id, 194 int render_process_host_id,
197 int routing_id) { 195 int routing_id) {
198 WebContents* web_contents = 196 WebContents* web_contents =
199 tab_util::GetWebContentsByID(render_process_host_id, routing_id); 197 tab_util::GetWebContentsByID(render_process_host_id, routing_id);
200 if (!web_contents) // Not one of our resource. 198 if (!web_contents) // Not one of our resource.
201 return NULL; 199 return NULL;
202 200
203 // If an origin PID was specified then the request originated in a plugin 201 // If an origin PID was specified then the request originated in a plugin
204 // working on the WebContents's behalf, so ignore it. 202 // working on the WebContents's behalf, so ignore it.
205 if (origin_pid) 203 if (origin_pid)
206 return NULL; 204 return NULL;
207 205
208 std::map<WebContents*, TaskManagerTabContentsResource*>::iterator 206 std::map<WebContents*, TabContentsResource*>::iterator
209 res_iter = resources_.find(web_contents); 207 res_iter = resources_.find(web_contents);
210 if (res_iter == resources_.end()) { 208 if (res_iter == resources_.end()) {
211 // Can happen if the tab was closed while a network request was being 209 // Can happen if the tab was closed while a network request was being
212 // performed. 210 // performed.
213 return NULL; 211 return NULL;
214 } 212 }
215 return res_iter->second; 213 return res_iter->second;
216 } 214 }
217 215
218 void TaskManagerTabContentsResourceProvider::StartUpdating() { 216 void TabContentsResourceProvider::StartUpdating() {
219 DCHECK(!updating_); 217 DCHECK(!updating_);
220 updating_ = true; 218 updating_ = true;
221 219
222 // The contents that are tracked by this resource provider are those that 220 // The contents that are tracked by this resource provider are those that
223 // are tab contents (WebContents serving as a tab in a Browser), Instant 221 // are tab contents (WebContents serving as a tab in a Browser), Instant
224 // pages, prerender pages, and background printed pages. 222 // pages, prerender pages, and background printed pages.
225 223
226 // Add all the existing WebContentses. 224 // Add all the existing WebContentses.
227 for (TabContentsIterator iterator; !iterator.done(); iterator.Next()) 225 for (TabContentsIterator iterator; !iterator.done(); iterator.Next())
228 Add(*iterator); 226 Add(*iterator);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, 260 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
263 content::NotificationService::AllBrowserContextsAndSources()); 261 content::NotificationService::AllBrowserContextsAndSources());
264 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, 262 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
265 content::NotificationService::AllBrowserContextsAndSources()); 263 content::NotificationService::AllBrowserContextsAndSources());
266 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, 264 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
267 content::NotificationService::AllBrowserContextsAndSources()); 265 content::NotificationService::AllBrowserContextsAndSources());
268 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED, 266 registrar_.Add(this, chrome::NOTIFICATION_INSTANT_COMMITTED,
269 content::NotificationService::AllBrowserContextsAndSources()); 267 content::NotificationService::AllBrowserContextsAndSources());
270 } 268 }
271 269
272 void TaskManagerTabContentsResourceProvider::StopUpdating() { 270 void TabContentsResourceProvider::StopUpdating() {
273 DCHECK(updating_); 271 DCHECK(updating_);
274 updating_ = false; 272 updating_ = false;
275 273
276 // Then we unregister for notifications to get new web contents. 274 // Then we unregister for notifications to get new web contents.
277 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, 275 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
278 content::NotificationService::AllBrowserContextsAndSources()); 276 content::NotificationService::AllBrowserContextsAndSources());
279 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED, 277 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
280 content::NotificationService::AllBrowserContextsAndSources()); 278 content::NotificationService::AllBrowserContextsAndSources());
281 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, 279 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
282 content::NotificationService::AllBrowserContextsAndSources()); 280 content::NotificationService::AllBrowserContextsAndSources());
283 registrar_.Remove(this, chrome::NOTIFICATION_INSTANT_COMMITTED, 281 registrar_.Remove(this, chrome::NOTIFICATION_INSTANT_COMMITTED,
284 content::NotificationService::AllBrowserContextsAndSources()); 282 content::NotificationService::AllBrowserContextsAndSources());
285 283
286 // Delete all the resources. 284 // Delete all the resources.
287 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); 285 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end());
288 286
289 resources_.clear(); 287 resources_.clear();
290 } 288 }
291 289
292 void TaskManagerTabContentsResourceProvider::AddToTaskManager( 290 void TabContentsResourceProvider::AddToTaskManager(WebContents* web_contents) {
293 WebContents* web_contents) { 291 TabContentsResource* resource = new TabContentsResource(web_contents);
294 TaskManagerTabContentsResource* resource =
295 new TaskManagerTabContentsResource(web_contents);
296 resources_[web_contents] = resource; 292 resources_[web_contents] = resource;
297 task_manager_->AddResource(resource); 293 task_manager_->AddResource(resource);
298 } 294 }
299 295
300 void TaskManagerTabContentsResourceProvider::Add(WebContents* web_contents) { 296 void TabContentsResourceProvider::Add(WebContents* web_contents) {
301 if (!updating_) 297 if (!updating_)
302 return; 298 return;
303 299
304 // The contents that are tracked by this resource provider are those that 300 // The contents that are tracked by this resource provider are those that
305 // are tab contents (WebContents serving as a tab in a Browser), Instant 301 // are tab contents (WebContents serving as a tab in a Browser), Instant
306 // pages, prerender pages, and background printed pages. 302 // pages, prerender pages, and background printed pages.
307 if (!chrome::FindBrowserWithWebContents(web_contents) && 303 if (!chrome::FindBrowserWithWebContents(web_contents) &&
308 !IsContentsPrerendering(web_contents) && 304 !IsContentsPrerendering(web_contents) &&
309 !IsContentsInstant(web_contents) && 305 !IsContentsInstant(web_contents) &&
310 !IsContentsBackgroundPrinted(web_contents)) { 306 !IsContentsBackgroundPrinted(web_contents)) {
311 return; 307 return;
312 } 308 }
313 309
314 // Don't add dead tabs or tabs that haven't yet connected. 310 // Don't add dead tabs or tabs that haven't yet connected.
315 if (!web_contents->GetRenderProcessHost()->GetHandle() || 311 if (!web_contents->GetRenderProcessHost()->GetHandle() ||
316 !web_contents->WillNotifyDisconnection()) { 312 !web_contents->WillNotifyDisconnection()) {
317 return; 313 return;
318 } 314 }
319 315
320 if (resources_.count(web_contents)) { 316 if (resources_.count(web_contents)) {
321 // The case may happen that we have added a WebContents as part of the 317 // The case may happen that we have added a WebContents as part of the
322 // iteration performed during StartUpdating() call but the notification that 318 // iteration performed during StartUpdating() call but the notification that
323 // it has connected was not fired yet. So when the notification happens, we 319 // it has connected was not fired yet. So when the notification happens, we
324 // already know about this tab and just ignore it. 320 // already know about this tab and just ignore it.
325 return; 321 return;
326 } 322 }
327 AddToTaskManager(web_contents); 323 AddToTaskManager(web_contents);
328 } 324 }
329 325
330 void TaskManagerTabContentsResourceProvider::Remove(WebContents* web_contents) { 326 void TabContentsResourceProvider::Remove(WebContents* web_contents) {
331 if (!updating_) 327 if (!updating_)
332 return; 328 return;
333 std::map<WebContents*, TaskManagerTabContentsResource*>::iterator 329 std::map<WebContents*, TabContentsResource*>::iterator
334 iter = resources_.find(web_contents); 330 iter = resources_.find(web_contents);
335 if (iter == resources_.end()) { 331 if (iter == resources_.end()) {
336 // Since WebContents are destroyed asynchronously (see TabContentsCollector 332 // Since WebContents are destroyed asynchronously (see TabContentsCollector
337 // in navigation_controller.cc), we can be notified of a tab being removed 333 // in navigation_controller.cc), we can be notified of a tab being removed
338 // that we don't know. This can happen if the user closes a tab and quickly 334 // that we don't know. This can happen if the user closes a tab and quickly
339 // opens the task manager, before the tab is actually destroyed. 335 // opens the task manager, before the tab is actually destroyed.
340 return; 336 return;
341 } 337 }
342 338
343 // Remove the resource from the Task Manager. 339 // Remove the resource from the Task Manager.
344 TaskManagerTabContentsResource* resource = iter->second; 340 TabContentsResource* resource = iter->second;
345 task_manager_->RemoveResource(resource); 341 task_manager_->RemoveResource(resource);
346 // And from the provider. 342 // And from the provider.
347 resources_.erase(iter); 343 resources_.erase(iter);
348 // Finally, delete the resource. 344 // Finally, delete the resource.
349 delete resource; 345 delete resource;
350 } 346 }
351 347
352 void TaskManagerTabContentsResourceProvider::InstantCommitted( 348 void TabContentsResourceProvider::InstantCommitted(WebContents* web_contents) {
353 WebContents* web_contents) {
354 if (!updating_) 349 if (!updating_)
355 return; 350 return;
356 std::map<WebContents*, TaskManagerTabContentsResource*>::iterator 351 std::map<WebContents*, TabContentsResource*>::iterator
357 iter = resources_.find(web_contents); 352 iter = resources_.find(web_contents);
358 DCHECK(iter != resources_.end()); 353 DCHECK(iter != resources_.end());
359 if (iter != resources_.end()) 354 if (iter != resources_.end())
360 iter->second->InstantCommitted(); 355 iter->second->InstantCommitted();
361 } 356 }
362 357
363 void TaskManagerTabContentsResourceProvider::Observe( 358 void TabContentsResourceProvider::Observe(
364 int type, 359 int type,
365 const content::NotificationSource& source, 360 const content::NotificationSource& source,
366 const content::NotificationDetails& details) { 361 const content::NotificationDetails& details) {
367 WebContents* web_contents = content::Source<WebContents>(source).ptr(); 362 WebContents* web_contents = content::Source<WebContents>(source).ptr();
368 363
369 switch (type) { 364 switch (type) {
370 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: 365 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED:
371 Add(web_contents); 366 Add(web_contents);
372 break; 367 break;
373 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED: 368 case content::NOTIFICATION_WEB_CONTENTS_SWAPPED:
374 Remove(web_contents); 369 Remove(web_contents);
375 Add(web_contents); 370 Add(web_contents);
376 break; 371 break;
377 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: 372 case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED:
378 Remove(web_contents); 373 Remove(web_contents);
379 break; 374 break;
380 case chrome::NOTIFICATION_INSTANT_COMMITTED: 375 case chrome::NOTIFICATION_INSTANT_COMMITTED:
381 InstantCommitted(web_contents); 376 InstantCommitted(web_contents);
382 break; 377 break;
383 default: 378 default:
384 NOTREACHED() << "Unexpected notification."; 379 NOTREACHED() << "Unexpected notification.";
385 return; 380 return;
386 } 381 }
387 } 382 }
383
384 } // namespace task_manager
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/tab_contents_resource_provider.h ('k') | chrome/browser/task_manager/task_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698