OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h" | 5 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
15 #include "chrome/browser/google_apis/drive_api_parser.h" | 15 #include "chrome/browser/google_apis/drive_api_parser.h" |
16 | 16 |
17 using content::BrowserThread; | 17 using content::BrowserThread; |
18 | 18 |
19 namespace gdata { | 19 namespace drive { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // WebApp store URL prefix. | 23 // WebApp store URL prefix. |
24 const char kStoreProductUrl[] = "https://chrome.google.com/webstore/"; | 24 const char kStoreProductUrl[] = "https://chrome.google.com/webstore/"; |
25 | 25 |
26 // Extracts Web store id from its web store URL. | 26 // Extracts Web store id from its web store URL. |
27 std::string GetWebStoreIdFromUrl(const GURL& url) { | 27 std::string GetWebStoreIdFromUrl(const GURL& url) { |
28 if (!StartsWithASCII(url.spec(), kStoreProductUrl, false)) { | 28 if (!StartsWithASCII(url.spec(), kStoreProductUrl, false)) { |
29 LOG(WARNING) << "Unrecognized product URL " << url.spec(); | 29 LOG(WARNING) << "Unrecognized product URL " << url.spec(); |
30 return std::string(); | 30 return std::string(); |
31 } | 31 } |
32 | 32 |
33 FilePath path(url.path()); | 33 FilePath path(url.path()); |
34 std::vector<FilePath::StringType> components; | 34 std::vector<FilePath::StringType> components; |
35 path.GetComponents(&components); | 35 path.GetComponents(&components); |
36 DCHECK_LE(2U, components.size()); // Coming from kStoreProductUrl | 36 DCHECK_LE(2U, components.size()); // Coming from kStoreProductUrl |
37 | 37 |
38 // Return the last part of the path | 38 // Return the last part of the path |
39 return components[components.size() - 1]; | 39 return components[components.size() - 1]; |
40 } | 40 } |
41 | 41 |
42 // TODO(kochi): This is duplicate from gdata_wapi_parser.cc. | 42 // TODO(kochi): This is duplicate from gdata_wapi_parser.cc. |
43 bool SortBySize(const InstalledApp::IconList::value_type& a, | 43 bool SortBySize(const gdata::InstalledApp::IconList::value_type& a, |
44 const InstalledApp::IconList::value_type& b) { | 44 const gdata::InstalledApp::IconList::value_type& b) { |
45 return a.first < b.first; | 45 return a.first < b.first; |
46 } | 46 } |
47 | 47 |
48 } // namespace | 48 } // namespace |
49 | 49 |
50 // DriveWebAppInfo struct implementation. | 50 // DriveWebAppInfo struct implementation. |
51 | 51 |
52 DriveWebAppInfo::DriveWebAppInfo(const std::string& app_id, | 52 DriveWebAppInfo::DriveWebAppInfo( |
53 const InstalledApp::IconList& app_icons, | 53 const std::string& app_id, |
54 const InstalledApp::IconList& document_icons, | 54 const gdata::InstalledApp::IconList& app_icons, |
55 const std::string& web_store_id, | 55 const gdata::InstalledApp::IconList& document_icons, |
56 const string16& app_name, | 56 const std::string& web_store_id, |
57 const string16& object_type, | 57 const string16& app_name, |
58 bool is_primary_selector) | 58 const string16& object_type, |
| 59 bool is_primary_selector) |
59 : app_id(app_id), | 60 : app_id(app_id), |
60 app_icons(app_icons), | 61 app_icons(app_icons), |
61 document_icons(document_icons), | 62 document_icons(document_icons), |
62 web_store_id(web_store_id), | 63 web_store_id(web_store_id), |
63 app_name(app_name), | 64 app_name(app_name), |
64 object_type(object_type), | 65 object_type(object_type), |
65 is_primary_selector(is_primary_selector) { | 66 is_primary_selector(is_primary_selector) { |
66 } | 67 } |
67 | 68 |
68 DriveWebAppInfo::~DriveWebAppInfo() { | 69 DriveWebAppInfo::~DriveWebAppInfo() { |
69 } | 70 } |
70 | 71 |
71 // DriveFileSystem::WebAppFileSelector struct implementation. | 72 // DriveFileSystem::WebAppFileSelector struct implementation. |
72 | 73 |
73 DriveWebAppsRegistry::WebAppFileSelector::WebAppFileSelector( | 74 DriveWebAppsRegistry::WebAppFileSelector::WebAppFileSelector( |
74 const GURL& product_link, | 75 const GURL& product_link, |
75 const InstalledApp::IconList& app_icons, | 76 const gdata::InstalledApp::IconList& app_icons, |
76 const InstalledApp::IconList& document_icons, | 77 const gdata::InstalledApp::IconList& document_icons, |
77 const string16& object_type, | 78 const string16& object_type, |
78 const std::string& app_id, | 79 const std::string& app_id, |
79 bool is_primary_selector) | 80 bool is_primary_selector) |
80 : product_link(product_link), | 81 : product_link(product_link), |
81 app_icons(app_icons), | 82 app_icons(app_icons), |
82 document_icons(document_icons), | 83 document_icons(document_icons), |
83 object_type(object_type), | 84 object_type(object_type), |
84 app_id(app_id), | 85 app_id(app_id), |
85 is_primary_selector(is_primary_selector) { | 86 is_primary_selector(is_primary_selector) { |
86 } | 87 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 for (WebAppFileSelectorMap::iterator iter = webapp_extension_map_.begin(); | 138 for (WebAppFileSelectorMap::iterator iter = webapp_extension_map_.begin(); |
138 iter != webapp_extension_map_.end(); ++iter) { | 139 iter != webapp_extension_map_.end(); ++iter) { |
139 std::string id = GetWebStoreIdFromUrl(iter->second->product_link); | 140 std::string id = GetWebStoreIdFromUrl(iter->second->product_link); |
140 if (id == web_store_id) | 141 if (id == web_store_id) |
141 extensions.insert(iter->first); | 142 extensions.insert(iter->first); |
142 } | 143 } |
143 return extensions; | 144 return extensions; |
144 } | 145 } |
145 | 146 |
146 void DriveWebAppsRegistry::UpdateFromFeed( | 147 void DriveWebAppsRegistry::UpdateFromFeed( |
147 const AccountMetadataFeed& metadata) { | 148 const gdata::AccountMetadataFeed& metadata) { |
148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
149 | 150 |
150 url_to_name_map_.clear(); | 151 url_to_name_map_.clear(); |
151 STLDeleteValues(&webapp_extension_map_); | 152 STLDeleteValues(&webapp_extension_map_); |
152 STLDeleteValues(&webapp_mimetypes_map_); | 153 STLDeleteValues(&webapp_mimetypes_map_); |
153 for (ScopedVector<InstalledApp>::const_iterator it = | 154 for (ScopedVector<gdata::InstalledApp>::const_iterator it = |
154 metadata.installed_apps().begin(); | 155 metadata.installed_apps().begin(); |
155 it != metadata.installed_apps().end(); ++it) { | 156 it != metadata.installed_apps().end(); ++it) { |
156 const InstalledApp& app = **it; | 157 const gdata::InstalledApp& app = **it; |
157 GURL product_url = app.GetProductUrl(); | 158 GURL product_url = app.GetProductUrl(); |
158 if (product_url.is_empty()) | 159 if (product_url.is_empty()) |
159 continue; | 160 continue; |
160 | 161 |
161 InstalledApp::IconList app_icons = | 162 gdata::InstalledApp::IconList app_icons = |
162 app.GetIconsForCategory(AppIcon::ICON_APPLICATION); | 163 app.GetIconsForCategory(gdata::AppIcon::ICON_APPLICATION); |
163 InstalledApp::IconList document_icons = | 164 gdata::InstalledApp::IconList document_icons = |
164 app.GetIconsForCategory(AppIcon::ICON_DOCUMENT); | 165 app.GetIconsForCategory(gdata::AppIcon::ICON_DOCUMENT); |
165 | 166 |
166 if (VLOG_IS_ON(1)) { | 167 if (VLOG_IS_ON(1)) { |
167 std::vector<std::string> mime_types; | 168 std::vector<std::string> mime_types; |
168 for (size_t i = 0; app.primary_mimetypes().size(); ++i) | 169 for (size_t i = 0; app.primary_mimetypes().size(); ++i) |
169 mime_types.push_back(*app.primary_mimetypes()[i]); | 170 mime_types.push_back(*app.primary_mimetypes()[i]); |
170 for (size_t i = 0; app.secondary_mimetypes().size(); ++i) | 171 for (size_t i = 0; app.secondary_mimetypes().size(); ++i) |
171 mime_types.push_back(*app.secondary_mimetypes()[i]); | 172 mime_types.push_back(*app.secondary_mimetypes()[i]); |
172 | 173 |
173 std::vector<std::string> extensions; | 174 std::vector<std::string> extensions; |
174 for (size_t i = 0; app.primary_extensions().size(); ++i) | 175 for (size_t i = 0; app.primary_extensions().size(); ++i) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 app_icons, | 213 app_icons, |
213 document_icons, | 214 document_icons, |
214 app.object_type(), | 215 app.object_type(), |
215 app.app_id(), | 216 app.app_id(), |
216 false, // primary | 217 false, // primary |
217 app.secondary_extensions(), | 218 app.secondary_extensions(), |
218 &webapp_extension_map_); | 219 &webapp_extension_map_); |
219 } | 220 } |
220 } | 221 } |
221 | 222 |
222 void DriveWebAppsRegistry::UpdateFromApplicationList(const AppList& applist) { | 223 void DriveWebAppsRegistry::UpdateFromApplicationList( |
| 224 const gdata::AppList& applist) { |
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
224 | 226 |
225 url_to_name_map_.clear(); | 227 url_to_name_map_.clear(); |
226 STLDeleteValues(&webapp_extension_map_); | 228 STLDeleteValues(&webapp_extension_map_); |
227 STLDeleteValues(&webapp_mimetypes_map_); | 229 STLDeleteValues(&webapp_mimetypes_map_); |
228 for (size_t i = 0; i < applist.items().size(); ++i) { | 230 for (size_t i = 0; i < applist.items().size(); ++i) { |
229 const AppResource& app = *applist.items()[i]; | 231 const gdata::AppResource& app = *applist.items()[i]; |
230 if (app.product_url().is_empty()) | 232 if (app.product_url().is_empty()) |
231 continue; | 233 continue; |
232 | 234 |
233 InstalledApp::IconList app_icons; | 235 gdata::InstalledApp::IconList app_icons; |
234 InstalledApp::IconList document_icons; | 236 gdata::InstalledApp::IconList document_icons; |
235 for (size_t j = 0; j < app.icons().size(); ++j) { | 237 for (size_t j = 0; j < app.icons().size(); ++j) { |
236 const DriveAppIcon& icon = *app.icons()[j]; | 238 const gdata::DriveAppIcon& icon = *app.icons()[j]; |
237 if (icon.icon_url().is_empty()) | 239 if (icon.icon_url().is_empty()) |
238 continue; | 240 continue; |
239 if (icon.category() == DriveAppIcon::APPLICATION) | 241 if (icon.category() == gdata::DriveAppIcon::APPLICATION) |
240 app_icons.push_back(std::make_pair(icon.icon_side_length(), | 242 app_icons.push_back(std::make_pair(icon.icon_side_length(), |
241 icon.icon_url())); | 243 icon.icon_url())); |
242 if (icon.category() == DriveAppIcon::DOCUMENT) | 244 if (icon.category() == gdata::DriveAppIcon::DOCUMENT) |
243 document_icons.push_back(std::make_pair(icon.icon_side_length(), | 245 document_icons.push_back(std::make_pair(icon.icon_side_length(), |
244 icon.icon_url())); | 246 icon.icon_url())); |
245 } | 247 } |
246 std::sort(app_icons.begin(), app_icons.end(), SortBySize); | 248 std::sort(app_icons.begin(), app_icons.end(), SortBySize); |
247 std::sort(document_icons.begin(), document_icons.end(), SortBySize); | 249 std::sort(document_icons.begin(), document_icons.end(), SortBySize); |
248 | 250 |
249 url_to_name_map_.insert( | 251 url_to_name_map_.insert( |
250 std::make_pair(app.product_url(), UTF8ToUTF16(app.name()))); | 252 std::make_pair(app.product_url(), UTF8ToUTF16(app.name()))); |
251 AddAppSelectorList(app.product_url(), | 253 AddAppSelectorList(app.product_url(), |
252 app_icons, | 254 app_icons, |
(...skipping 26 matching lines...) Expand all Loading... |
279 app.application_id(), | 281 app.application_id(), |
280 false, // primary | 282 false, // primary |
281 app.secondary_file_extensions(), | 283 app.secondary_file_extensions(), |
282 &webapp_extension_map_); | 284 &webapp_extension_map_); |
283 } | 285 } |
284 } | 286 } |
285 | 287 |
286 // static. | 288 // static. |
287 void DriveWebAppsRegistry::AddAppSelectorList( | 289 void DriveWebAppsRegistry::AddAppSelectorList( |
288 const GURL& product_link, | 290 const GURL& product_link, |
289 const InstalledApp::IconList& app_icons, | 291 const gdata::InstalledApp::IconList& app_icons, |
290 const InstalledApp::IconList& document_icons, | 292 const gdata::InstalledApp::IconList& document_icons, |
291 const string16& object_type, | 293 const string16& object_type, |
292 const std::string& app_id, | 294 const std::string& app_id, |
293 bool is_primary_selector, | 295 bool is_primary_selector, |
294 const ScopedVector<std::string>& selectors, | 296 const ScopedVector<std::string>& selectors, |
295 WebAppFileSelectorMap* map) { | 297 WebAppFileSelectorMap* map) { |
296 for (ScopedVector<std::string>::const_iterator it = selectors.begin(); | 298 for (ScopedVector<std::string>::const_iterator it = selectors.begin(); |
297 it != selectors.end(); ++it) { | 299 it != selectors.end(); ++it) { |
298 std::string* value = *it; | 300 std::string* value = *it; |
299 map->insert(std::make_pair( | 301 map->insert(std::make_pair( |
300 *value, new WebAppFileSelector(product_link, | 302 *value, new WebAppFileSelector(product_link, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 new DriveWebAppInfo(web_app->app_id, | 334 new DriveWebAppInfo(web_app->app_id, |
333 web_app->app_icons, | 335 web_app->app_icons, |
334 web_app->document_icons, | 336 web_app->document_icons, |
335 web_store_id, | 337 web_store_id, |
336 product_iter->second, // app name. | 338 product_iter->second, // app name. |
337 web_app->object_type, | 339 web_app->object_type, |
338 web_app->is_primary_selector))); | 340 web_app->is_primary_selector))); |
339 } | 341 } |
340 } | 342 } |
341 | 343 |
342 } // namespace gdata | 344 } // namespace drive |
OLD | NEW |