Commit f3dfbfd2 authored by kinaba@chromium.org's avatar kinaba@chromium.org

Remove drive::DriveAppRegistry::DriveAppFileSelector.

The struct was used for keeping the app list internally in DriveAppRegistry,
but the information it holds is identical to its public cousin: DriveAppInfo.

BUG=284951

Review URL: https://chromiumcodereview.appspot.com/23608007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221210 0039d316-1c4b-4281-b951-d872f2087c98
parent 1e727638
......@@ -41,15 +41,8 @@ std::string GetWebStoreIdFromUrl(const GURL& url) {
return components[components.size() - 1];
}
bool SortBySize(const google_apis::InstalledApp::IconList::value_type& a,
const google_apis::InstalledApp::IconList::value_type& b) {
return a.first < b.first;
}
} // namespace
// DriveAppInfo struct implementation.
DriveAppInfo::DriveAppInfo() {
}
......@@ -73,28 +66,6 @@ DriveAppInfo::DriveAppInfo(
DriveAppInfo::~DriveAppInfo() {
}
// FileSystem::DriveAppFileSelector struct implementation.
DriveAppRegistry::DriveAppFileSelector::DriveAppFileSelector(
const GURL& product_link,
const google_apis::InstalledApp::IconList& app_icons,
const google_apis::InstalledApp::IconList& document_icons,
const std::string& object_type,
const std::string& app_id,
bool is_primary_selector)
: product_link(product_link),
app_icons(app_icons),
document_icons(document_icons),
object_type(object_type),
app_id(app_id),
is_primary_selector(is_primary_selector) {
}
DriveAppRegistry::DriveAppFileSelector::~DriveAppFileSelector() {
}
// DriveAppRegistry implementation.
DriveAppRegistry::DriveAppRegistry(JobScheduler* scheduler)
: scheduler_(scheduler),
is_updating_(false),
......@@ -112,22 +83,20 @@ void DriveAppRegistry::GetAppsForFile(
ScopedVector<DriveAppInfo>* apps) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
SelectorAppList result_map;
std::vector<DriveAppInfo*> matched_apps;
if (!file_extension.empty()) {
const base::FilePath::StringType without_dot = file_extension.substr(1);
FindAppsForSelector(without_dot, app_extension_map_, &result_map);
FindAppsForSelector(without_dot, app_extension_map_, &matched_apps);
}
if (!mime_type.empty())
FindAppsForSelector(mime_type, app_mimetypes_map_, &result_map);
FindAppsForSelector(mime_type, app_mimetypes_map_, &matched_apps);
// Insert found Drive apps into |apps|, but skip duplicate results.
std::set<std::string> inserted_app_ids;
for (SelectorAppList::const_iterator it = result_map.begin();
it != result_map.end(); ++it) {
if (inserted_app_ids.find(it->second->app_id) == inserted_app_ids.end()) {
inserted_app_ids.insert(it->second->app_id);
apps->push_back(it->second);
for (size_t i = 0; i < matched_apps.size(); ++i) {
if (inserted_app_ids.count(matched_apps[i]->app_id) == 0) {
inserted_app_ids.insert(matched_apps[i]->app_id);
apps->push_back(new DriveAppInfo(*matched_apps[i]));
}
}
}
......@@ -165,13 +134,17 @@ void DriveAppRegistry::UpdateAfterGetAppList(
void DriveAppRegistry::UpdateFromAppList(
const google_apis::AppList& app_list) {
url_to_name_map_.clear();
STLDeleteValues(&app_extension_map_);
STLDeleteValues(&app_mimetypes_map_);
for (size_t i = 0; i < app_list.items().size(); ++i) {
const google_apis::AppResource& app = *app_list.items()[i];
if (app.product_url().is_empty())
continue;
std::string web_store_id = GetWebStoreIdFromUrl(app.product_url());
if (web_store_id.empty())
continue;
google_apis::InstalledApp::IconList app_icons;
google_apis::InstalledApp::IconList document_icons;
......@@ -186,12 +159,9 @@ void DriveAppRegistry::UpdateFromAppList(
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(), app.name()));
AddAppSelectorList(app.product_url(),
AddAppSelectorList(web_store_id,
app.name(),
app_icons,
document_icons,
app.object_type(),
......@@ -199,7 +169,8 @@ void DriveAppRegistry::UpdateFromAppList(
true, // primary
app.primary_mimetypes(),
&app_mimetypes_map_);
AddAppSelectorList(app.product_url(),
AddAppSelectorList(web_store_id,
app.name(),
app_icons,
document_icons,
app.object_type(),
......@@ -207,7 +178,8 @@ void DriveAppRegistry::UpdateFromAppList(
false, // primary
app.secondary_mimetypes(),
&app_mimetypes_map_);
AddAppSelectorList(app.product_url(),
AddAppSelectorList(web_store_id,
app.name(),
app_icons,
document_icons,
app.object_type(),
......@@ -215,7 +187,8 @@ void DriveAppRegistry::UpdateFromAppList(
true, // primary
app.primary_file_extensions(),
&app_extension_map_);
AddAppSelectorList(app.product_url(),
AddAppSelectorList(web_store_id,
app.name(),
app_icons,
document_icons,
app.object_type(),
......@@ -228,7 +201,8 @@ void DriveAppRegistry::UpdateFromAppList(
// static.
void DriveAppRegistry::AddAppSelectorList(
const GURL& product_link,
const std::string& web_store_id,
const std::string& app_name,
const google_apis::InstalledApp::IconList& app_icons,
const google_apis::InstalledApp::IconList& document_icons,
const std::string& object_type,
......@@ -240,11 +214,12 @@ void DriveAppRegistry::AddAppSelectorList(
it != selectors.end(); ++it) {
std::string* value = *it;
map->insert(std::make_pair(
*value, new DriveAppFileSelector(product_link,
*value, new DriveAppInfo(app_id,
app_icons,
document_icons,
web_store_id,
app_name,
object_type,
app_id,
is_primary_selector)));
}
}
......@@ -252,33 +227,10 @@ void DriveAppRegistry::AddAppSelectorList(
void DriveAppRegistry::FindAppsForSelector(
const std::string& file_selector,
const DriveAppFileSelectorMap& map,
SelectorAppList* apps) const {
std::vector<DriveAppInfo*>* matched_apps) const {
for (DriveAppFileSelectorMap::const_iterator it = map.find(file_selector);
it != map.end() && it->first == file_selector; ++it) {
const DriveAppFileSelector* drive_app = it->second;
std::map<GURL, std::string>::const_iterator product_iter =
url_to_name_map_.find(drive_app->product_link);
if (product_iter == url_to_name_map_.end()) {
NOTREACHED();
continue;
}
std::string web_store_id = GetWebStoreIdFromUrl(drive_app->product_link);
if (web_store_id.empty())
continue;
if (apps->find(drive_app) != apps->end())
continue;
apps->insert(std::make_pair(
drive_app,
new DriveAppInfo(drive_app->app_id,
drive_app->app_icons,
drive_app->document_icons,
web_store_id,
product_iter->second, // app name
drive_app->object_type,
drive_app->is_primary_selector)));
matched_apps->push_back(it->second);
}
}
......
......@@ -6,8 +6,8 @@
#define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_APP_REGISTRY_H_
#include <map>
#include <set>
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
......@@ -76,43 +76,10 @@ class DriveAppRegistry {
void UpdateFromAppList(const google_apis::AppList& app_list);
private:
// Defines application details that are associated with a given
// file extension or content mimetype.
struct DriveAppFileSelector {
DriveAppFileSelector(
const GURL& product_link,
const google_apis::InstalledApp::IconList& app_icons,
const google_apis::InstalledApp::IconList& document_icons,
const std::string& object_type,
const std::string& app_id,
bool is_primary_selector);
~DriveAppFileSelector();
// Product link to the webstore.
GURL product_link;
// Drive application icon URLs for this app, paired with their size (length
// of a side in pixels).
google_apis::InstalledApp::IconList app_icons;
// Drive document icon URLs for this app, paired with their size (length of
// a side in pixels).
google_apis::InstalledApp::IconList document_icons;
// Object (file) type description.
std::string object_type;
// Drive app id
std::string app_id;
// True if the selector is the default one. The default selector should
// trigger on file double-click events. Non-default selectors only show up
// in "Open with..." pop-up menu.
bool is_primary_selector;
};
// Defines mapping between file content type selectors (extensions, MIME
// types) and corresponding app.
typedef std::multimap<std::string,
DriveAppFileSelector*> DriveAppFileSelectorMap;
// Helper map used for deduplication of selector matching results.
typedef std::map<const DriveAppFileSelector*,
DriveAppInfo*> SelectorAppList;
typedef std::multimap<std::string, DriveAppInfo*> DriveAppFileSelectorMap;
// Part of Update(). Runs upon the completion of fetching the Drive apps
// data from the server.
......@@ -122,7 +89,8 @@ class DriveAppRegistry {
// Helper function for loading Drive application file |selectors| into
// corresponding |map|.
static void AddAppSelectorList(
const GURL& product_link,
const std::string& web_store_id,
const std::string& app_name,
const google_apis::InstalledApp::IconList& app_icons,
const google_apis::InstalledApp::IconList& document_icons,
const std::string& object_type,
......@@ -134,13 +102,10 @@ class DriveAppRegistry {
// Finds matching |apps| from |map| based on provided file |selector|.
void FindAppsForSelector(const std::string& selector,
const DriveAppFileSelectorMap& map,
SelectorAppList* apps) const;
std::vector<DriveAppInfo*>* matched_apps) const;
JobScheduler* scheduler_;
// Map of web store product URL to application name.
std::map<GURL, std::string> url_to_name_map_;
// Map of filename extension to application info.
DriveAppFileSelectorMap app_extension_map_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment