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

Unified Diff: chrome/browser/chromeos/gdata/drive_webapps_registry.cc

Issue 10829276: Get web application list using Drive V2 API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unittest compile. Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
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..f201e00719135f8e6b8539673cf115d9d420d536 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,7 +133,8 @@ 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();
@@ -182,6 +190,72 @@ void DriveWebAppsRegistry::UpdateFromFeed(AccountMetadataFeed* metadata) {
}
}
+void DriveWebAppsRegistry::UpdateFromApplicationList(const AppList* applist) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ url_to_name_map_.clear();
+ STLDeleteValues(&webapp_extension_map_);
+ STLDeleteValues(&webapp_mimetypes_map_);
+ for (ScopedVector<AppResource>::const_iterator it = applist->items().begin();
+ it != applist->items().end(); ++it) {
satorux1 2012/08/10 17:26:02 matter of taste, but the following is more concise
kochi 2012/08/13 09:12:24 Done. The same is done for UpdateFeed().
+ const AppResource* app = *it;
satorux1 2012/08/10 17:26:02 maybe const AppResource& app = *applist->items()[
kochi 2012/08/13 09:12:24 Done. The same is done for UpdateFeed().
+ if (app->product_url().is_empty())
+ continue;
+
+ InstalledApp::IconList app_icons;
+ InstalledApp::IconList document_icons;
+ for (ScopedVector<DriveAppIcon>::const_iterator it = app->icons().begin();
satorux1 2012/08/10 17:26:02 |it| is already used in the outer loop. please use
kochi 2012/08/13 09:12:24 This |it| removed in favor of size_t loop.
+ it != app->icons().end(); ++it) {
+ DriveAppIcon* icon = *it;
satorux1 2012/08/10 17:26:02 const reference?
kochi 2012/08/13 09:12:24 Done.
+ 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_file_extensions(),
+ &webapp_extension_map_);
+ }
+}
+
// static.
void DriveWebAppsRegistry::AddAppSelectorList(
const GURL& product_link,

Powered by Google App Engine
This is Rietveld 408576698