Chromium Code Reviews| Index: chrome/browser/ui/views/apps/app_info_dialog/app_info_summary_panel.cc |
| diff --git a/chrome/browser/ui/views/apps/app_info_dialog/app_info_summary_panel.cc b/chrome/browser/ui/views/apps/app_info_dialog/app_info_summary_panel.cc |
| index 2a859598042be02216496cc25fdb66a8a85e956a..01be6050e69404d560a21d769af07319f35882d1 100644 |
| --- a/chrome/browser/ui/views/apps/app_info_dialog/app_info_summary_panel.cc |
| +++ b/chrome/browser/ui/views/apps/app_info_dialog/app_info_summary_panel.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/callback_forward.h" |
| #include "base/command_line.h" |
| +#include "base/file_util.h" |
| #include "base/i18n/time_formatting.h" |
| #include "base/logging.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -16,6 +17,7 @@ |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/extensions/extension_constants.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "extensions/browser/extension_prefs.h" |
| #include "extensions/browser/extension_system.h" |
| #include "extensions/common/extension.h" |
| @@ -23,6 +25,7 @@ |
| #include "grit/generated_resources.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/models/combobox_model.h" |
| +#include "ui/base/text/bytes_formatting.h" |
| #include "ui/views/controls/combobox/combobox.h" |
| #include "ui/views/controls/label.h" |
| #include "ui/views/layout/box_layout.h" |
| @@ -124,19 +127,41 @@ base::string16 LaunchOptionsComboboxModel::GetItemAt(int index) { |
| return launch_type_messages_[index]; |
| } |
| +// A buffer for storing the App's size while it's being calculated. |
| +class AppSizeBuffer : public base::RefCountedThreadSafe<AppSizeBuffer> { |
| + public: |
| + void SetAppSize(int64 app_size) { app_size_ = app_size; } |
| + int64 GetAppSize() { return app_size_; } |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<AppSizeBuffer>; |
| + virtual ~AppSizeBuffer() {} |
| + |
| + int64 app_size_; |
| +}; |
| + |
| +// Calculates the size of the given path and saves it to the provided buffer. |
| +void CalculateAppSize(const base::FilePath& path, |
| + scoped_refptr<AppSizeBuffer> app_size_in_bytes) { |
| + app_size_in_bytes->SetAppSize(base::ComputeDirectorySize(path)); |
| +} |
| + |
| AppInfoSummaryPanel::AppInfoSummaryPanel(Profile* profile, |
| const extensions::Extension* app) |
| : AppInfoPanel(profile, app), |
| description_heading_(NULL), |
| description_label_(NULL), |
| details_heading_(NULL), |
| + size_title_(NULL), |
| + size_value_(NULL), |
| version_title_(NULL), |
| version_value_(NULL), |
| installed_time_title_(NULL), |
| installed_time_value_(NULL), |
| last_run_time_title_(NULL), |
| last_run_time_value_(NULL), |
| - launch_options_combobox_(NULL) { |
| + launch_options_combobox_(NULL), |
| + weak_ptr_factory_(this) { |
| // Create UI elements. |
| CreateDescriptionControl(); |
| CreateDetailsControl(); |
| @@ -180,6 +205,19 @@ void AppInfoSummaryPanel::CreateDescriptionControl() { |
| } |
| void AppInfoSummaryPanel::CreateDetailsControl() { |
| + // The size doesn't make sense for component apps. |
| + if (app_->location() != extensions::Manifest::COMPONENT) { |
| + size_title_ = new views::Label( |
| + l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_SIZE_LABEL)); |
| + size_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + |
| + size_value_ = new views::Label( |
| + l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_SIZE_LOADING_LABEL)); |
| + size_value_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + |
| + StartCalculatingAppSize(); |
| + } |
| + |
| // The version doesn't make sense for bookmark apps. |
| if (!app_->from_bookmark()) { |
| // Display 'Version: Built-in' for component apps. |
| @@ -273,6 +311,10 @@ void AppInfoSummaryPanel::LayoutDetailsControl() { |
| details_stack->AddChildView( |
| CreateKeyValueField(last_run_time_title_, last_run_time_value_)); |
| + if (size_title_ && size_value_) |
| + details_stack->AddChildView( |
| + CreateKeyValueField(size_title_, size_value_)); |
| + |
| views::View* vertical_stack = CreateVerticalStack(); |
| vertical_stack->AddChildView(details_heading_); |
| vertical_stack->AddChildView(details_stack); |
| @@ -289,6 +331,22 @@ void AppInfoSummaryPanel::OnPerformAction(views::Combobox* combobox) { |
| } |
| } |
| +void AppInfoSummaryPanel::StartCalculatingAppSize() { |
| + scoped_refptr<AppSizeBuffer> app_size_in_bytes = new AppSizeBuffer(); |
| + 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
|
| + content::BrowserThread::FILE, |
| + FROM_HERE, |
| + base::Bind(&CalculateAppSize, app_->path(), app_size_in_bytes), |
| + base::Bind(&AppInfoSummaryPanel::OnAppSizeCalculated, |
| + AsWeakPtr(), |
| + app_size_in_bytes)); |
| +} |
| + |
| +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.
|
| + scoped_refptr<AppSizeBuffer> app_size_in_bytes) { |
| + size_value_->SetText(ui::FormatBytes(app_size_in_bytes->GetAppSize())); |
| +} |
| + |
| base::Time AppInfoSummaryPanel::GetInstalledTime() const { |
| return extensions::ExtensionPrefs::Get(profile_)->GetInstallTime(app_->id()); |
| } |