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/panel_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_panel_resource_provider.h" 5 #include "chrome/browser/task_manager/panel_resource_provider.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/task_manager/task_manager_render_resource.h" 10 #include "chrome/browser/task_manager/renderer_resource.h"
11 #include "chrome/browser/task_manager/task_manager_resource_util.h" 11 #include "chrome/browser/task_manager/task_manager_util.h"
12 #include "chrome/browser/ui/panels/panel.h" 12 #include "chrome/browser/ui/panels/panel.h"
13 #include "chrome/browser/ui/panels/panel_manager.h" 13 #include "chrome/browser/ui/panels/panel_manager.h"
14 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
16 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/render_view_host.h" 18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "extensions/browser/view_type_utils.h" 20 #include "extensions/browser/view_type_utils.h"
21 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
22 22
23 using content::RenderProcessHost; 23 using content::RenderProcessHost;
24 using content::RenderViewHost; 24 using content::RenderViewHost;
25 using content::WebContents; 25 using content::WebContents;
26 using extensions::Extension; 26 using extensions::Extension;
27 27
28 class TaskManagerPanelResource : public TaskManagerRendererResource { 28 namespace task_manager {
29
30 class PanelResource : public RendererResource {
29 public: 31 public:
30 explicit TaskManagerPanelResource(Panel* panel); 32 explicit PanelResource(Panel* panel);
31 virtual ~TaskManagerPanelResource(); 33 virtual ~PanelResource();
32 34
33 // TaskManager::Resource methods: 35 // TaskManager::Resource methods:
34 virtual Type GetType() const OVERRIDE; 36 virtual Type GetType() const OVERRIDE;
35 virtual string16 GetTitle() const OVERRIDE; 37 virtual string16 GetTitle() const OVERRIDE;
36 virtual string16 GetProfileName() const OVERRIDE; 38 virtual string16 GetProfileName() const OVERRIDE;
37 virtual gfx::ImageSkia GetIcon() const OVERRIDE; 39 virtual gfx::ImageSkia GetIcon() const OVERRIDE;
38 virtual content::WebContents* GetWebContents() const OVERRIDE; 40 virtual content::WebContents* GetWebContents() const OVERRIDE;
39 virtual const extensions::Extension* GetExtension() const OVERRIDE; 41 virtual const extensions::Extension* GetExtension() const OVERRIDE;
40 42
41 private: 43 private:
42 Panel* panel_; 44 Panel* panel_;
43 // Determines prefix for title reflecting whether extensions are apps 45 // Determines prefix for title reflecting whether extensions are apps
44 // or in incognito mode. 46 // or in incognito mode.
45 int message_prefix_id_; 47 int message_prefix_id_;
46 48
47 DISALLOW_COPY_AND_ASSIGN(TaskManagerPanelResource); 49 DISALLOW_COPY_AND_ASSIGN(PanelResource);
48 }; 50 };
49 51
50 TaskManagerPanelResource::TaskManagerPanelResource(Panel* panel) 52 PanelResource::PanelResource(Panel* panel)
51 : TaskManagerRendererResource( 53 : RendererResource(
52 panel->GetWebContents()->GetRenderProcessHost()->GetHandle(), 54 panel->GetWebContents()->GetRenderProcessHost()->GetHandle(),
53 panel->GetWebContents()->GetRenderViewHost()), 55 panel->GetWebContents()->GetRenderViewHost()),
54 panel_(panel) { 56 panel_(panel) {
55 message_prefix_id_ = TaskManagerResourceUtil::GetMessagePrefixID( 57 message_prefix_id_ = util::GetMessagePrefixID(
56 GetExtension()->is_app(), 58 GetExtension()->is_app(),
57 true, // is_extension 59 true, // is_extension
58 panel->profile()->IsOffTheRecord(), 60 panel->profile()->IsOffTheRecord(),
59 false, // is_prerender 61 false, // is_prerender
60 false, // is_instant_overlay 62 false, // is_instant_overlay
61 false); // is_background 63 false); // is_background
62 } 64 }
63 65
64 TaskManagerPanelResource::~TaskManagerPanelResource() { 66 PanelResource::~PanelResource() {
65 } 67 }
66 68
67 TaskManager::Resource::Type TaskManagerPanelResource::GetType() const { 69 TaskManager::Resource::Type PanelResource::GetType() const {
68 return EXTENSION; 70 return EXTENSION;
69 } 71 }
70 72
71 string16 TaskManagerPanelResource::GetTitle() const { 73 string16 PanelResource::GetTitle() const {
72 string16 title = panel_->GetWindowTitle(); 74 string16 title = panel_->GetWindowTitle();
73 // Since the title will be concatenated with an IDS_TASK_MANAGER_* prefix 75 // Since the title will be concatenated with an IDS_TASK_MANAGER_* prefix
74 // we need to explicitly set the title to be LTR format if there is no 76 // we need to explicitly set the title to be LTR format if there is no
75 // strong RTL charater in it. Otherwise, if the task manager prefix is an 77 // strong RTL charater in it. Otherwise, if the task manager prefix is an
76 // RTL word, the concatenated result might be wrong. For example, 78 // RTL word, the concatenated result might be wrong. For example,
77 // a page whose title is "Yahoo! Mail: The best web-based Email!", without 79 // a page whose title is "Yahoo! Mail: The best web-based Email!", without
78 // setting it explicitly as LTR format, the concatenated result will be 80 // setting it explicitly as LTR format, the concatenated result will be
79 // "!Yahoo! Mail: The best web-based Email :PPA", in which the capital 81 // "!Yahoo! Mail: The best web-based Email :PPA", in which the capital
80 // letters "PPA" stands for the Hebrew word for "app". 82 // letters "PPA" stands for the Hebrew word for "app".
81 base::i18n::AdjustStringForLocaleDirection(&title); 83 base::i18n::AdjustStringForLocaleDirection(&title);
82 84
83 return l10n_util::GetStringFUTF16(message_prefix_id_, title); 85 return l10n_util::GetStringFUTF16(message_prefix_id_, title);
84 } 86 }
85 87
86 string16 TaskManagerPanelResource::GetProfileName() const { 88 string16 PanelResource::GetProfileName() const {
87 return TaskManagerResourceUtil::GetProfileNameFromInfoCache( 89 return util::GetProfileNameFromInfoCache(panel_->profile());
88 panel_->profile());
89 } 90 }
90 91
91 gfx::ImageSkia TaskManagerPanelResource::GetIcon() const { 92 gfx::ImageSkia PanelResource::GetIcon() const {
92 gfx::Image icon = panel_->GetCurrentPageIcon(); 93 gfx::Image icon = panel_->GetCurrentPageIcon();
93 return icon.IsEmpty() ? gfx::ImageSkia() : *icon.ToImageSkia(); 94 return icon.IsEmpty() ? gfx::ImageSkia() : *icon.ToImageSkia();
94 } 95 }
95 96
96 WebContents* TaskManagerPanelResource::GetWebContents() const { 97 WebContents* PanelResource::GetWebContents() const {
97 return panel_->GetWebContents(); 98 return panel_->GetWebContents();
98 } 99 }
99 100
100 const Extension* TaskManagerPanelResource::GetExtension() const { 101 const Extension* PanelResource::GetExtension() const {
101 ExtensionService* extension_service = 102 ExtensionService* extension_service =
102 panel_->profile()->GetExtensionService(); 103 panel_->profile()->GetExtensionService();
103 return extension_service->extensions()->GetByID(panel_->extension_id()); 104 return extension_service->extensions()->GetByID(panel_->extension_id());
104 } 105 }
105 106
106 //////////////////////////////////////////////////////////////////////////////// 107 ////////////////////////////////////////////////////////////////////////////////
107 // TaskManagerPanelResourceProvider class 108 // PanelResourceProvider class
108 //////////////////////////////////////////////////////////////////////////////// 109 ////////////////////////////////////////////////////////////////////////////////
109 110
110 TaskManagerPanelResourceProvider::TaskManagerPanelResourceProvider( 111 PanelResourceProvider::PanelResourceProvider(TaskManager* task_manager)
111 TaskManager* task_manager)
112 : updating_(false), 112 : updating_(false),
113 task_manager_(task_manager) { 113 task_manager_(task_manager) {
114 } 114 }
115 115
116 TaskManagerPanelResourceProvider::~TaskManagerPanelResourceProvider() { 116 PanelResourceProvider::~PanelResourceProvider() {
117 } 117 }
118 118
119 TaskManager::Resource* TaskManagerPanelResourceProvider::GetResource( 119 TaskManager::Resource* PanelResourceProvider::GetResource(
120 int origin_pid, 120 int origin_pid,
121 int render_process_host_id, 121 int render_process_host_id,
122 int routing_id) { 122 int routing_id) {
123 // If an origin PID was specified, the request is from a plugin, not the 123 // If an origin PID was specified, the request is from a plugin, not the
124 // render view host process 124 // render view host process
125 if (origin_pid) 125 if (origin_pid)
126 return NULL; 126 return NULL;
127 127
128 for (PanelResourceMap::iterator i = resources_.begin(); 128 for (PanelResourceMap::iterator i = resources_.begin();
129 i != resources_.end(); ++i) { 129 i != resources_.end(); ++i) {
130 WebContents* contents = i->first->GetWebContents(); 130 WebContents* contents = i->first->GetWebContents();
131 if (contents && 131 if (contents &&
132 contents->GetRenderProcessHost()->GetID() == render_process_host_id && 132 contents->GetRenderProcessHost()->GetID() == render_process_host_id &&
133 contents->GetRenderViewHost()->GetRoutingID() == routing_id) { 133 contents->GetRenderViewHost()->GetRoutingID() == routing_id) {
134 return i->second; 134 return i->second;
135 } 135 }
136 } 136 }
137 137
138 // Can happen if the panel went away while a network request was being 138 // Can happen if the panel went away while a network request was being
139 // performed. 139 // performed.
140 return NULL; 140 return NULL;
141 } 141 }
142 142
143 void TaskManagerPanelResourceProvider::StartUpdating() { 143 void PanelResourceProvider::StartUpdating() {
144 DCHECK(!updating_); 144 DCHECK(!updating_);
145 updating_ = true; 145 updating_ = true;
146 146
147 // Add all the Panels. 147 // Add all the Panels.
148 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); 148 std::vector<Panel*> panels = PanelManager::GetInstance()->panels();
149 for (size_t i = 0; i < panels.size(); ++i) 149 for (size_t i = 0; i < panels.size(); ++i)
150 Add(panels[i]); 150 Add(panels[i]);
151 151
152 // Then we register for notifications to get new and remove closed panels. 152 // Then we register for notifications to get new and remove closed panels.
153 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, 153 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
154 content::NotificationService::AllSources()); 154 content::NotificationService::AllSources());
155 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, 155 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
156 content::NotificationService::AllSources()); 156 content::NotificationService::AllSources());
157 } 157 }
158 158
159 void TaskManagerPanelResourceProvider::StopUpdating() { 159 void PanelResourceProvider::StopUpdating() {
160 DCHECK(updating_); 160 DCHECK(updating_);
161 updating_ = false; 161 updating_ = false;
162 162
163 // Unregister for notifications about new/removed panels. 163 // Unregister for notifications about new/removed panels.
164 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED, 164 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
165 content::NotificationService::AllSources()); 165 content::NotificationService::AllSources());
166 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, 166 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
167 content::NotificationService::AllSources()); 167 content::NotificationService::AllSources());
168 168
169 // Delete all the resources. 169 // Delete all the resources.
170 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end()); 170 STLDeleteContainerPairSecondPointers(resources_.begin(), resources_.end());
171 resources_.clear(); 171 resources_.clear();
172 } 172 }
173 173
174 void TaskManagerPanelResourceProvider::Add(Panel* panel) { 174 void PanelResourceProvider::Add(Panel* panel) {
175 if (!updating_) 175 if (!updating_)
176 return; 176 return;
177 177
178 PanelResourceMap::const_iterator iter = resources_.find(panel); 178 PanelResourceMap::const_iterator iter = resources_.find(panel);
179 if (iter != resources_.end()) 179 if (iter != resources_.end())
180 return; 180 return;
181 181
182 TaskManagerPanelResource* resource = new TaskManagerPanelResource(panel); 182 PanelResource* resource = new PanelResource(panel);
183 resources_[panel] = resource; 183 resources_[panel] = resource;
184 task_manager_->AddResource(resource); 184 task_manager_->AddResource(resource);
185 } 185 }
186 186
187 void TaskManagerPanelResourceProvider::Remove(Panel* panel) { 187 void PanelResourceProvider::Remove(Panel* panel) {
188 if (!updating_) 188 if (!updating_)
189 return; 189 return;
190 190
191 PanelResourceMap::iterator iter = resources_.find(panel); 191 PanelResourceMap::iterator iter = resources_.find(panel);
192 if (iter == resources_.end()) 192 if (iter == resources_.end())
193 return; 193 return;
194 194
195 TaskManagerPanelResource* resource = iter->second; 195 PanelResource* resource = iter->second;
196 task_manager_->RemoveResource(resource); 196 task_manager_->RemoveResource(resource);
197 resources_.erase(iter); 197 resources_.erase(iter);
198 delete resource; 198 delete resource;
199 } 199 }
200 200
201 void TaskManagerPanelResourceProvider::Observe(int type, 201 void PanelResourceProvider::Observe(int type,
202 const content::NotificationSource& source, 202 const content::NotificationSource& source,
203 const content::NotificationDetails& details) { 203 const content::NotificationDetails& details) {
204 WebContents* web_contents = content::Source<WebContents>(source).ptr(); 204 WebContents* web_contents = content::Source<WebContents>(source).ptr();
205 if (extensions::GetViewType(web_contents) != extensions::VIEW_TYPE_PANEL) 205 if (extensions::GetViewType(web_contents) != extensions::VIEW_TYPE_PANEL)
206 return; 206 return;
207 207
208 switch (type) { 208 switch (type) {
209 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED: 209 case content::NOTIFICATION_WEB_CONTENTS_CONNECTED:
210 { 210 {
211 std::vector<Panel*>panels = PanelManager::GetInstance()->panels(); 211 std::vector<Panel*>panels = PanelManager::GetInstance()->panels();
(...skipping 16 matching lines...) Expand all
228 break; 228 break;
229 } 229 }
230 } 230 }
231 break; 231 break;
232 } 232 }
233 default: 233 default:
234 NOTREACHED() << "Unexpected notificiation."; 234 NOTREACHED() << "Unexpected notificiation.";
235 break; 235 break;
236 } 236 }
237 } 237 }
238
239 } // namespace task_manager
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/panel_resource_provider.h ('k') | chrome/browser/task_manager/renderer_resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698