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) { ...@@ -41,15 +41,8 @@ std::string GetWebStoreIdFromUrl(const GURL& url) {
return components[components.size() - 1]; 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 } // namespace
// DriveAppInfo struct implementation.
DriveAppInfo::DriveAppInfo() { DriveAppInfo::DriveAppInfo() {
} }
...@@ -73,28 +66,6 @@ DriveAppInfo::DriveAppInfo( ...@@ -73,28 +66,6 @@ DriveAppInfo::DriveAppInfo(
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) DriveAppRegistry::DriveAppRegistry(JobScheduler* scheduler)
: scheduler_(scheduler), : scheduler_(scheduler),
is_updating_(false), is_updating_(false),
...@@ -112,22 +83,20 @@ void DriveAppRegistry::GetAppsForFile( ...@@ -112,22 +83,20 @@ void DriveAppRegistry::GetAppsForFile(
ScopedVector<DriveAppInfo>* apps) const { ScopedVector<DriveAppInfo>* apps) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
SelectorAppList result_map; std::vector<DriveAppInfo*> matched_apps;
if (!file_extension.empty()) { if (!file_extension.empty()) {
const base::FilePath::StringType without_dot = file_extension.substr(1); 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()) 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. // Insert found Drive apps into |apps|, but skip duplicate results.
std::set<std::string> inserted_app_ids; std::set<std::string> inserted_app_ids;
for (SelectorAppList::const_iterator it = result_map.begin(); for (size_t i = 0; i < matched_apps.size(); ++i) {
it != result_map.end(); ++it) { if (inserted_app_ids.count(matched_apps[i]->app_id) == 0) {
if (inserted_app_ids.find(it->second->app_id) == inserted_app_ids.end()) { inserted_app_ids.insert(matched_apps[i]->app_id);
inserted_app_ids.insert(it->second->app_id); apps->push_back(new DriveAppInfo(*matched_apps[i]));
apps->push_back(it->second);
} }
} }
} }
...@@ -165,13 +134,17 @@ void DriveAppRegistry::UpdateAfterGetAppList( ...@@ -165,13 +134,17 @@ void DriveAppRegistry::UpdateAfterGetAppList(
void DriveAppRegistry::UpdateFromAppList( void DriveAppRegistry::UpdateFromAppList(
const google_apis::AppList& app_list) { const google_apis::AppList& app_list) {
url_to_name_map_.clear();
STLDeleteValues(&app_extension_map_); STLDeleteValues(&app_extension_map_);
STLDeleteValues(&app_mimetypes_map_); STLDeleteValues(&app_mimetypes_map_);
for (size_t i = 0; i < app_list.items().size(); ++i) { for (size_t i = 0; i < app_list.items().size(); ++i) {
const google_apis::AppResource& app = *app_list.items()[i]; const google_apis::AppResource& app = *app_list.items()[i];
if (app.product_url().is_empty()) if (app.product_url().is_empty())
continue; 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 app_icons;
google_apis::InstalledApp::IconList document_icons; google_apis::InstalledApp::IconList document_icons;
...@@ -186,12 +159,9 @@ void DriveAppRegistry::UpdateFromAppList( ...@@ -186,12 +159,9 @@ void DriveAppRegistry::UpdateFromAppList(
document_icons.push_back(std::make_pair(icon.icon_side_length(), document_icons.push_back(std::make_pair(icon.icon_side_length(),
icon.icon_url())); 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( AddAppSelectorList(web_store_id,
std::make_pair(app.product_url(), app.name())); app.name(),
AddAppSelectorList(app.product_url(),
app_icons, app_icons,
document_icons, document_icons,
app.object_type(), app.object_type(),
...@@ -199,7 +169,8 @@ void DriveAppRegistry::UpdateFromAppList( ...@@ -199,7 +169,8 @@ void DriveAppRegistry::UpdateFromAppList(
true, // primary true, // primary
app.primary_mimetypes(), app.primary_mimetypes(),
&app_mimetypes_map_); &app_mimetypes_map_);
AddAppSelectorList(app.product_url(), AddAppSelectorList(web_store_id,
app.name(),
app_icons, app_icons,
document_icons, document_icons,
app.object_type(), app.object_type(),
...@@ -207,7 +178,8 @@ void DriveAppRegistry::UpdateFromAppList( ...@@ -207,7 +178,8 @@ void DriveAppRegistry::UpdateFromAppList(
false, // primary false, // primary
app.secondary_mimetypes(), app.secondary_mimetypes(),
&app_mimetypes_map_); &app_mimetypes_map_);
AddAppSelectorList(app.product_url(), AddAppSelectorList(web_store_id,
app.name(),
app_icons, app_icons,
document_icons, document_icons,
app.object_type(), app.object_type(),
...@@ -215,7 +187,8 @@ void DriveAppRegistry::UpdateFromAppList( ...@@ -215,7 +187,8 @@ void DriveAppRegistry::UpdateFromAppList(
true, // primary true, // primary
app.primary_file_extensions(), app.primary_file_extensions(),
&app_extension_map_); &app_extension_map_);
AddAppSelectorList(app.product_url(), AddAppSelectorList(web_store_id,
app.name(),
app_icons, app_icons,
document_icons, document_icons,
app.object_type(), app.object_type(),
...@@ -228,7 +201,8 @@ void DriveAppRegistry::UpdateFromAppList( ...@@ -228,7 +201,8 @@ void DriveAppRegistry::UpdateFromAppList(
// static. // static.
void DriveAppRegistry::AddAppSelectorList( 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& app_icons,
const google_apis::InstalledApp::IconList& document_icons, const google_apis::InstalledApp::IconList& document_icons,
const std::string& object_type, const std::string& object_type,
...@@ -240,45 +214,23 @@ void DriveAppRegistry::AddAppSelectorList( ...@@ -240,45 +214,23 @@ void DriveAppRegistry::AddAppSelectorList(
it != selectors.end(); ++it) { it != selectors.end(); ++it) {
std::string* value = *it; std::string* value = *it;
map->insert(std::make_pair( map->insert(std::make_pair(
*value, new DriveAppFileSelector(product_link, *value, new DriveAppInfo(app_id,
app_icons, app_icons,
document_icons, document_icons,
object_type, web_store_id,
app_id, app_name,
is_primary_selector))); object_type,
is_primary_selector)));
} }
} }
void DriveAppRegistry::FindAppsForSelector( void DriveAppRegistry::FindAppsForSelector(
const std::string& file_selector, const std::string& file_selector,
const DriveAppFileSelectorMap& map, const DriveAppFileSelectorMap& map,
SelectorAppList* apps) const { std::vector<DriveAppInfo*>* matched_apps) const {
for (DriveAppFileSelectorMap::const_iterator it = map.find(file_selector); for (DriveAppFileSelectorMap::const_iterator it = map.find(file_selector);
it != map.end() && it->first == file_selector; ++it) { it != map.end() && it->first == file_selector; ++it) {
const DriveAppFileSelector* drive_app = it->second; matched_apps->push_back(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)));
} }
} }
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_APP_REGISTRY_H_ #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_APP_REGISTRY_H_
#include <map> #include <map>
#include <set>
#include <string> #include <string>
#include <vector>
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
...@@ -76,43 +76,10 @@ class DriveAppRegistry { ...@@ -76,43 +76,10 @@ class DriveAppRegistry {
void UpdateFromAppList(const google_apis::AppList& app_list); void UpdateFromAppList(const google_apis::AppList& app_list);
private: 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 // Defines mapping between file content type selectors (extensions, MIME
// types) and corresponding app. // types) and corresponding app.
typedef std::multimap<std::string, typedef std::multimap<std::string, DriveAppInfo*> DriveAppFileSelectorMap;
DriveAppFileSelector*> DriveAppFileSelectorMap;
// Helper map used for deduplication of selector matching results.
typedef std::map<const DriveAppFileSelector*,
DriveAppInfo*> SelectorAppList;
// Part of Update(). Runs upon the completion of fetching the Drive apps // Part of Update(). Runs upon the completion of fetching the Drive apps
// data from the server. // data from the server.
...@@ -122,7 +89,8 @@ class DriveAppRegistry { ...@@ -122,7 +89,8 @@ class DriveAppRegistry {
// Helper function for loading Drive application file |selectors| into // Helper function for loading Drive application file |selectors| into
// corresponding |map|. // corresponding |map|.
static void AddAppSelectorList( 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& app_icons,
const google_apis::InstalledApp::IconList& document_icons, const google_apis::InstalledApp::IconList& document_icons,
const std::string& object_type, const std::string& object_type,
...@@ -134,13 +102,10 @@ class DriveAppRegistry { ...@@ -134,13 +102,10 @@ class DriveAppRegistry {
// Finds matching |apps| from |map| based on provided file |selector|. // Finds matching |apps| from |map| based on provided file |selector|.
void FindAppsForSelector(const std::string& selector, void FindAppsForSelector(const std::string& selector,
const DriveAppFileSelectorMap& map, const DriveAppFileSelectorMap& map,
SelectorAppList* apps) const; std::vector<DriveAppInfo*>* matched_apps) const;
JobScheduler* scheduler_; 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. // Map of filename extension to application info.
DriveAppFileSelectorMap app_extension_map_; 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