Chromium Code Reviews| Index: chrome/browser/chromeos/gdata/drive_webapps_registry.cc |
| diff --git a/chrome/browser/chromeos/gdata/drive_webapps_registry.cc b/chrome/browser/chromeos/gdata/drive_webapps_registry.cc |
| index 1b0e051bbdb7e05c9a2cd77975031828e2c02af3..91085eb6fe92af43fd9a0ce5695ca7fb7ea74009 100644 |
| --- a/chrome/browser/chromeos/gdata/drive_webapps_registry.cc |
| +++ b/chrome/browser/chromeos/gdata/drive_webapps_registry.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/string_util.h" |
| #include "base/utf_string_conversions.h" |
| +#include "chrome/browser/chromeos/gdata/drive_api_parser.h" |
| #include "content/public/browser/browser_thread.h" |
| using content::BrowserThread; |
| @@ -33,6 +34,12 @@ std::string GetWebStoreIdFromUrl(const GURL& url) { |
| return components[components.size() - 1]; |
| } |
| +// TODO(kochi): This is duplicate from gdata_wapi_parser.cc. |
| +bool SortBySize(const InstalledApp::IconList::value_type& a, |
| + const InstalledApp::IconList::value_type& b) { |
| + return a.first < b.first; |
| +} |
| + |
| } // namespace |
| // DriveWebAppInfo struct implementation. |
| @@ -126,58 +133,123 @@ std::set<std::string> DriveWebAppsRegistry::GetExtensionsForWebStoreApp( |
| return extensions; |
| } |
| -void DriveWebAppsRegistry::UpdateFromFeed(AccountMetadataFeed* metadata) { |
| +void DriveWebAppsRegistry::UpdateFromFeed( |
| + const AccountMetadataFeed& metadata) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| url_to_name_map_.clear(); |
| STLDeleteValues(&webapp_extension_map_); |
| STLDeleteValues(&webapp_mimetypes_map_); |
| for (ScopedVector<InstalledApp>::const_iterator it = |
| - metadata->installed_apps().begin(); |
| - it != metadata->installed_apps().end(); ++it) { |
| - const InstalledApp* app = *it; |
| - GURL product_url = app->GetProductUrl(); |
| + metadata.installed_apps().begin(); |
| + it != metadata.installed_apps().end(); ++it) { |
| + const InstalledApp& app = **it; |
| + GURL product_url = app.GetProductUrl(); |
| if (product_url.is_empty()) |
| continue; |
| InstalledApp::IconList app_icons = |
| - app->GetIconsForCategory(AppIcon::APPLICATION); |
| + app.GetIconsForCategory(AppIcon::APPLICATION); |
| InstalledApp::IconList document_icons = |
| - app->GetIconsForCategory(AppIcon::DOCUMENT); |
| + app.GetIconsForCategory(AppIcon::DOCUMENT); |
| url_to_name_map_.insert( |
| - std::make_pair(product_url, app->app_name())); |
| + std::make_pair(product_url, app.app_name())); |
| AddAppSelectorList(product_url, |
| app_icons, |
| document_icons, |
| - app->object_type(), |
| - app->app_id(), |
| + app.object_type(), |
| + app.app_id(), |
| true, // primary |
| - app->primary_mimetypes(), |
| + app.primary_mimetypes(), |
| &webapp_mimetypes_map_); |
| AddAppSelectorList(product_url, |
| app_icons, |
| document_icons, |
| - app->object_type(), |
| - app->app_id(), |
| + app.object_type(), |
| + app.app_id(), |
| false, // primary |
| - app->secondary_mimetypes(), |
| + app.secondary_mimetypes(), |
| &webapp_mimetypes_map_); |
| AddAppSelectorList(product_url, |
| app_icons, |
| document_icons, |
| - app->object_type(), |
| - app->app_id(), |
| + app.object_type(), |
| + app.app_id(), |
| true, // primary |
| - app->primary_extensions(), |
| + app.primary_extensions(), |
| &webapp_extension_map_); |
| AddAppSelectorList(product_url, |
| app_icons, |
| document_icons, |
| - app->object_type(), |
| - app->app_id(), |
| + app.object_type(), |
| + app.app_id(), |
| + false, // primary |
| + app.secondary_extensions(), |
| + &webapp_extension_map_); |
| + } |
| +} |
| + |
| +void DriveWebAppsRegistry::UpdateFromApplicationList(const AppList& applist) { |
|
satorux1
2012/08/13 17:14:48
Can you write a unit test for this? We have one fo
kochi
2012/08/14 09:21:11
Done.
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + url_to_name_map_.clear(); |
| + STLDeleteValues(&webapp_extension_map_); |
| + STLDeleteValues(&webapp_mimetypes_map_); |
| + for (size_t i = 0; i < applist.items().size(); ++i) { |
| + const AppResource& app = *applist.items()[i]; |
| + if (app.product_url().is_empty()) |
| + continue; |
| + |
| + InstalledApp::IconList app_icons; |
| + InstalledApp::IconList document_icons; |
| + for (size_t j = 0; j < app.icons().size(); ++j) { |
| + const DriveAppIcon& icon = *app.icons()[j]; |
| + if (icon.icon_url().is_empty()) |
| + continue; |
| + if (icon.category() == DriveAppIcon::APPLICATION) |
| + app_icons.push_back(std::make_pair(icon.icon_side_length(), |
| + icon.icon_url())); |
| + if (icon.category() == DriveAppIcon::DOCUMENT) |
| + document_icons.push_back(std::make_pair(icon.icon_side_length(), |
| + icon.icon_url())); |
| + } |
| + std::sort(app_icons.begin(), app_icons.end(), SortBySize); |
| + std::sort(document_icons.begin(), document_icons.end(), SortBySize); |
| + |
| + url_to_name_map_.insert( |
| + std::make_pair(app.product_url(), UTF8ToUTF16(app.name()))); |
| + AddAppSelectorList(app.product_url(), |
| + app_icons, |
| + document_icons, |
| + UTF8ToUTF16(app.object_type()), |
| + app.application_id(), |
| + true, // primary |
| + app.primary_mimetypes(), |
| + &webapp_mimetypes_map_); |
| + AddAppSelectorList(app.product_url(), |
| + app_icons, |
| + document_icons, |
| + UTF8ToUTF16(app.object_type()), |
| + app.application_id(), |
| + false, // primary |
| + app.secondary_mimetypes(), |
| + &webapp_mimetypes_map_); |
| + AddAppSelectorList(app.product_url(), |
| + app_icons, |
| + document_icons, |
| + UTF8ToUTF16(app.object_type()), |
| + app.application_id(), |
| + true, // primary |
| + app.primary_file_extensions(), |
| + &webapp_extension_map_); |
| + AddAppSelectorList(app.product_url(), |
| + app_icons, |
| + document_icons, |
| + UTF8ToUTF16(app.object_type()), |
| + app.application_id(), |
| false, // primary |
| - app->secondary_extensions(), |
| + app.secondary_file_extensions(), |
| &webapp_extension_map_); |
| } |
| } |