OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/views/apps/app_info_dialog/app_info_summary_panel.h" | 5 #include "chrome/browser/ui/views/apps/app_info_dialog/app_info_summary_panel.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/file_util.h" | |
11 #include "base/i18n/time_formatting.h" | 12 #include "base/i18n/time_formatting.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/extensions/launch_util.h" | 16 #include "chrome/browser/extensions/launch_util.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
20 #include "content/public/browser/browser_thread.h" | |
19 #include "extensions/browser/extension_prefs.h" | 21 #include "extensions/browser/extension_prefs.h" |
20 #include "extensions/browser/extension_system.h" | 22 #include "extensions/browser/extension_system.h" |
21 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
22 #include "extensions/common/manifest.h" | 24 #include "extensions/common/manifest.h" |
23 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
24 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/models/combobox_model.h" | 27 #include "ui/base/models/combobox_model.h" |
28 #include "ui/base/text/bytes_formatting.h" | |
26 #include "ui/views/controls/combobox/combobox.h" | 29 #include "ui/views/controls/combobox/combobox.h" |
27 #include "ui/views/controls/label.h" | 30 #include "ui/views/controls/label.h" |
28 #include "ui/views/layout/box_layout.h" | 31 #include "ui/views/layout/box_layout.h" |
29 #include "ui/views/layout/layout_constants.h" | 32 #include "ui/views/layout/layout_constants.h" |
30 #include "ui/views/view.h" | 33 #include "ui/views/view.h" |
31 #include "ui/views/widget/widget.h" | 34 #include "ui/views/widget/widget.h" |
32 | 35 |
33 // A model for a combobox selecting the launch options for a hosted app. | 36 // A model for a combobox selecting the launch options for a hosted app. |
34 // Displays different options depending on the host OS. | 37 // Displays different options depending on the host OS. |
35 class LaunchOptionsComboboxModel : public ui::ComboboxModel { | 38 class LaunchOptionsComboboxModel : public ui::ComboboxModel { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 } | 120 } |
118 | 121 |
119 int LaunchOptionsComboboxModel::GetItemCount() const { | 122 int LaunchOptionsComboboxModel::GetItemCount() const { |
120 return launch_types_.size(); | 123 return launch_types_.size(); |
121 } | 124 } |
122 | 125 |
123 base::string16 LaunchOptionsComboboxModel::GetItemAt(int index) { | 126 base::string16 LaunchOptionsComboboxModel::GetItemAt(int index) { |
124 return launch_type_messages_[index]; | 127 return launch_type_messages_[index]; |
125 } | 128 } |
126 | 129 |
130 // A buffer for storing the App's size while it's being calculated. | |
131 class AppSizeBuffer : public base::RefCountedThreadSafe<AppSizeBuffer> { | |
132 public: | |
133 void SetAppSize(int64 app_size) { app_size_ = app_size; } | |
134 int64 GetAppSize() { return app_size_; } | |
135 | |
136 private: | |
137 friend class base::RefCountedThreadSafe<AppSizeBuffer>; | |
138 virtual ~AppSizeBuffer() {} | |
139 | |
140 int64 app_size_; | |
141 }; | |
142 | |
143 // Calculates the size of the given path and saves it to the provided buffer. | |
144 void CalculateAppSize(const base::FilePath& path, | |
145 scoped_refptr<AppSizeBuffer> app_size_in_bytes) { | |
146 app_size_in_bytes->SetAppSize(base::ComputeDirectorySize(path)); | |
147 } | |
148 | |
127 AppInfoSummaryPanel::AppInfoSummaryPanel(Profile* profile, | 149 AppInfoSummaryPanel::AppInfoSummaryPanel(Profile* profile, |
128 const extensions::Extension* app) | 150 const extensions::Extension* app) |
129 : AppInfoPanel(profile, app), | 151 : AppInfoPanel(profile, app), |
130 description_heading_(NULL), | 152 description_heading_(NULL), |
131 description_label_(NULL), | 153 description_label_(NULL), |
132 details_heading_(NULL), | 154 details_heading_(NULL), |
155 size_title_(NULL), | |
156 size_value_(NULL), | |
133 version_title_(NULL), | 157 version_title_(NULL), |
134 version_value_(NULL), | 158 version_value_(NULL), |
135 installed_time_title_(NULL), | 159 installed_time_title_(NULL), |
136 installed_time_value_(NULL), | 160 installed_time_value_(NULL), |
137 last_run_time_title_(NULL), | 161 last_run_time_title_(NULL), |
138 last_run_time_value_(NULL), | 162 last_run_time_value_(NULL), |
139 launch_options_combobox_(NULL) { | 163 launch_options_combobox_(NULL), |
164 weak_ptr_factory_(this) { | |
140 // Create UI elements. | 165 // Create UI elements. |
141 CreateDescriptionControl(); | 166 CreateDescriptionControl(); |
142 CreateDetailsControl(); | 167 CreateDetailsControl(); |
143 CreateLaunchOptionControl(); | 168 CreateLaunchOptionControl(); |
144 | 169 |
145 // Layout elements. | 170 // Layout elements. |
146 SetLayoutManager( | 171 SetLayoutManager( |
147 new views::BoxLayout(views::BoxLayout::kVertical, | 172 new views::BoxLayout(views::BoxLayout::kVertical, |
148 0, | 173 0, |
149 0, | 174 0, |
(...skipping 23 matching lines...) Expand all Loading... | |
173 | 198 |
174 description_heading_ = CreateHeading( | 199 description_heading_ = CreateHeading( |
175 l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_DESCRIPTION_TITLE)); | 200 l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_DESCRIPTION_TITLE)); |
176 description_label_ = new views::Label(text); | 201 description_label_ = new views::Label(text); |
177 description_label_->SetMultiLine(true); | 202 description_label_->SetMultiLine(true); |
178 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 203 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
179 } | 204 } |
180 } | 205 } |
181 | 206 |
182 void AppInfoSummaryPanel::CreateDetailsControl() { | 207 void AppInfoSummaryPanel::CreateDetailsControl() { |
208 // The size doesn't make sense for component apps. | |
209 if (app_->location() != extensions::Manifest::COMPONENT) { | |
210 size_title_ = new views::Label( | |
211 l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_SIZE_LABEL)); | |
212 size_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
213 | |
214 size_value_ = new views::Label( | |
215 l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_SIZE_LOADING_LABEL)); | |
216 size_value_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
217 | |
218 StartCalculatingAppSize(); | |
219 } | |
220 | |
183 // The version doesn't make sense for bookmark apps. | 221 // The version doesn't make sense for bookmark apps. |
184 if (!app_->from_bookmark()) { | 222 if (!app_->from_bookmark()) { |
185 // Display 'Version: Built-in' for component apps. | 223 // Display 'Version: Built-in' for component apps. |
186 base::string16 version_str = base::ASCIIToUTF16(app_->VersionString()); | 224 base::string16 version_str = base::ASCIIToUTF16(app_->VersionString()); |
187 if (app_->location() == extensions::Manifest::COMPONENT) | 225 if (app_->location() == extensions::Manifest::COMPONENT) |
188 version_str = l10n_util::GetStringUTF16( | 226 version_str = l10n_util::GetStringUTF16( |
189 IDS_APPLICATION_INFO_VERSION_BUILT_IN_LABEL); | 227 IDS_APPLICATION_INFO_VERSION_BUILT_IN_LABEL); |
190 | 228 |
191 version_title_ = new views::Label( | 229 version_title_ = new views::Label( |
192 l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_VERSION_LABEL)); | 230 l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_VERSION_LABEL)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 CreateKeyValueField(version_title_, version_value_)); | 304 CreateKeyValueField(version_title_, version_value_)); |
267 | 305 |
268 if (installed_time_title_ && installed_time_value_) | 306 if (installed_time_title_ && installed_time_value_) |
269 details_stack->AddChildView( | 307 details_stack->AddChildView( |
270 CreateKeyValueField(installed_time_title_, installed_time_value_)); | 308 CreateKeyValueField(installed_time_title_, installed_time_value_)); |
271 | 309 |
272 if (last_run_time_title_ && last_run_time_value_) | 310 if (last_run_time_title_ && last_run_time_value_) |
273 details_stack->AddChildView( | 311 details_stack->AddChildView( |
274 CreateKeyValueField(last_run_time_title_, last_run_time_value_)); | 312 CreateKeyValueField(last_run_time_title_, last_run_time_value_)); |
275 | 313 |
314 if (size_title_ && size_value_) | |
315 details_stack->AddChildView( | |
316 CreateKeyValueField(size_title_, size_value_)); | |
317 | |
276 views::View* vertical_stack = CreateVerticalStack(); | 318 views::View* vertical_stack = CreateVerticalStack(); |
277 vertical_stack->AddChildView(details_heading_); | 319 vertical_stack->AddChildView(details_heading_); |
278 vertical_stack->AddChildView(details_stack); | 320 vertical_stack->AddChildView(details_stack); |
279 AddChildView(vertical_stack); | 321 AddChildView(vertical_stack); |
280 } | 322 } |
281 } | 323 } |
282 | 324 |
283 void AppInfoSummaryPanel::OnPerformAction(views::Combobox* combobox) { | 325 void AppInfoSummaryPanel::OnPerformAction(views::Combobox* combobox) { |
284 if (combobox == launch_options_combobox_) { | 326 if (combobox == launch_options_combobox_) { |
285 SetLaunchType(launch_options_combobox_model_->GetLaunchTypeAtIndex( | 327 SetLaunchType(launch_options_combobox_model_->GetLaunchTypeAtIndex( |
286 launch_options_combobox_->selected_index())); | 328 launch_options_combobox_->selected_index())); |
287 } else { | 329 } else { |
288 NOTREACHED(); | 330 NOTREACHED(); |
289 } | 331 } |
290 } | 332 } |
291 | 333 |
334 void AppInfoSummaryPanel::StartCalculatingAppSize() { | |
335 scoped_refptr<AppSizeBuffer> app_size_in_bytes = new AppSizeBuffer(); | |
336 content::BrowserThread::PostTaskAndReply( | |
tapted
2014/07/31 00:42:04
I think you want PostTaskAndReplyWithResult. Also
sashab
2014/07/31 05:00:46
Nice! Saves so much code. Strange how there are di
| |
337 content::BrowserThread::FILE, | |
338 FROM_HERE, | |
339 base::Bind(&CalculateAppSize, app_->path(), app_size_in_bytes), | |
340 base::Bind(&AppInfoSummaryPanel::OnAppSizeCalculated, | |
341 AsWeakPtr(), | |
342 app_size_in_bytes)); | |
343 } | |
344 | |
345 void AppInfoSummaryPanel::OnAppSizeCalculated( | |
tapted
2014/07/31 00:42:04
Then this can just take an an int64 argument
sashab
2014/07/31 05:00:46
Yup, done.
| |
346 scoped_refptr<AppSizeBuffer> app_size_in_bytes) { | |
347 size_value_->SetText(ui::FormatBytes(app_size_in_bytes->GetAppSize())); | |
348 } | |
349 | |
292 base::Time AppInfoSummaryPanel::GetInstalledTime() const { | 350 base::Time AppInfoSummaryPanel::GetInstalledTime() const { |
293 return extensions::ExtensionPrefs::Get(profile_)->GetInstallTime(app_->id()); | 351 return extensions::ExtensionPrefs::Get(profile_)->GetInstallTime(app_->id()); |
294 } | 352 } |
295 | 353 |
296 base::Time AppInfoSummaryPanel::GetLastLaunchedTime() const { | 354 base::Time AppInfoSummaryPanel::GetLastLaunchedTime() const { |
297 return extensions::ExtensionPrefs::Get(profile_) | 355 return extensions::ExtensionPrefs::Get(profile_) |
298 ->GetLastLaunchTime(app_->id()); | 356 ->GetLastLaunchTime(app_->id()); |
299 } | 357 } |
300 | 358 |
301 extensions::LaunchType AppInfoSummaryPanel::GetLaunchType() const { | 359 extensions::LaunchType AppInfoSummaryPanel::GetLaunchType() const { |
302 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile_), | 360 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile_), |
303 app_); | 361 app_); |
304 } | 362 } |
305 | 363 |
306 void AppInfoSummaryPanel::SetLaunchType( | 364 void AppInfoSummaryPanel::SetLaunchType( |
307 extensions::LaunchType launch_type) const { | 365 extensions::LaunchType launch_type) const { |
308 DCHECK(CanSetLaunchType()); | 366 DCHECK(CanSetLaunchType()); |
309 ExtensionService* service = | 367 ExtensionService* service = |
310 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 368 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
311 extensions::SetLaunchType(service, app_->id(), launch_type); | 369 extensions::SetLaunchType(service, app_->id(), launch_type); |
312 } | 370 } |
313 | 371 |
314 bool AppInfoSummaryPanel::CanSetLaunchType() const { | 372 bool AppInfoSummaryPanel::CanSetLaunchType() const { |
315 // V2 apps don't have a launch type, and neither does the Chrome app. | 373 // V2 apps don't have a launch type, and neither does the Chrome app. |
316 return app_->id() != extension_misc::kChromeAppId && !app_->is_platform_app(); | 374 return app_->id() != extension_misc::kChromeAppId && !app_->is_platform_app(); |
317 } | 375 } |
OLD | NEW |