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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/gdata/drive_webapps_registry.h" 5 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/chromeos/gdata/drive_api_parser.h"
9 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
10 11
11 using content::BrowserThread; 12 using content::BrowserThread;
12 13
13 namespace gdata { 14 namespace gdata {
14 15
15 namespace { 16 namespace {
16 17
17 // WebApp store URL prefix. 18 // WebApp store URL prefix.
18 const char kStoreProductUrl[] = "https://chrome.google.com/webstore/"; 19 const char kStoreProductUrl[] = "https://chrome.google.com/webstore/";
19 20
20 // Extracts Web store id from its web store URL. 21 // Extracts Web store id from its web store URL.
21 std::string GetWebStoreIdFromUrl(const GURL& url) { 22 std::string GetWebStoreIdFromUrl(const GURL& url) {
22 if (!StartsWithASCII(url.spec(), kStoreProductUrl, false)) { 23 if (!StartsWithASCII(url.spec(), kStoreProductUrl, false)) {
23 LOG(WARNING) << "Unrecognized product URL " << url.spec(); 24 LOG(WARNING) << "Unrecognized product URL " << url.spec();
24 return std::string(); 25 return std::string();
25 } 26 }
26 27
27 FilePath path(url.path()); 28 FilePath path(url.path());
28 std::vector<FilePath::StringType> components; 29 std::vector<FilePath::StringType> components;
29 path.GetComponents(&components); 30 path.GetComponents(&components);
30 DCHECK_LE(2U, components.size()); // Coming from kStoreProductUrl 31 DCHECK_LE(2U, components.size()); // Coming from kStoreProductUrl
31 32
32 // Return the last part of the path 33 // Return the last part of the path
33 return components[components.size() - 1]; 34 return components[components.size() - 1];
34 } 35 }
35 36
37 // TODO(kochi): This is duplicate from gdata_wapi_parser.cc.
38 bool SortBySize(const InstalledApp::IconList::value_type& a,
39 const InstalledApp::IconList::value_type& b) {
40 return a.first < b.first;
41 }
42
36 } // namespace 43 } // namespace
37 44
38 // DriveWebAppInfo struct implementation. 45 // DriveWebAppInfo struct implementation.
39 46
40 DriveWebAppInfo::DriveWebAppInfo(const std::string& app_id, 47 DriveWebAppInfo::DriveWebAppInfo(const std::string& app_id,
41 const InstalledApp::IconList& app_icons, 48 const InstalledApp::IconList& app_icons,
42 const InstalledApp::IconList& document_icons, 49 const InstalledApp::IconList& document_icons,
43 const std::string& web_store_id, 50 const std::string& web_store_id,
44 const string16& app_name, 51 const string16& app_name,
45 const string16& object_type, 52 const string16& object_type,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // web_store_id. 126 // web_store_id.
120 for (WebAppFileSelectorMap::iterator iter = webapp_extension_map_.begin(); 127 for (WebAppFileSelectorMap::iterator iter = webapp_extension_map_.begin();
121 iter != webapp_extension_map_.end(); ++iter) { 128 iter != webapp_extension_map_.end(); ++iter) {
122 std::string id = GetWebStoreIdFromUrl(iter->second->product_link); 129 std::string id = GetWebStoreIdFromUrl(iter->second->product_link);
123 if (id == web_store_id) 130 if (id == web_store_id)
124 extensions.insert(iter->first); 131 extensions.insert(iter->first);
125 } 132 }
126 return extensions; 133 return extensions;
127 } 134 }
128 135
129 void DriveWebAppsRegistry::UpdateFromFeed(AccountMetadataFeed* metadata) { 136 void DriveWebAppsRegistry::UpdateFromFeed(
137 const AccountMetadataFeed* metadata) {
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
131 139
132 url_to_name_map_.clear(); 140 url_to_name_map_.clear();
133 STLDeleteValues(&webapp_extension_map_); 141 STLDeleteValues(&webapp_extension_map_);
134 STLDeleteValues(&webapp_mimetypes_map_); 142 STLDeleteValues(&webapp_mimetypes_map_);
135 for (ScopedVector<InstalledApp>::const_iterator it = 143 for (ScopedVector<InstalledApp>::const_iterator it =
136 metadata->installed_apps().begin(); 144 metadata->installed_apps().begin();
137 it != metadata->installed_apps().end(); ++it) { 145 it != metadata->installed_apps().end(); ++it) {
138 const InstalledApp* app = *it; 146 const InstalledApp* app = *it;
139 GURL product_url = app->GetProductUrl(); 147 GURL product_url = app->GetProductUrl();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 app_icons, 183 app_icons,
176 document_icons, 184 document_icons,
177 app->object_type(), 185 app->object_type(),
178 app->app_id(), 186 app->app_id(),
179 false, // primary 187 false, // primary
180 app->secondary_extensions(), 188 app->secondary_extensions(),
181 &webapp_extension_map_); 189 &webapp_extension_map_);
182 } 190 }
183 } 191 }
184 192
193 void DriveWebAppsRegistry::UpdateFromApplicationList(const AppList* applist) {
194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
195
196 url_to_name_map_.clear();
197 STLDeleteValues(&webapp_extension_map_);
198 STLDeleteValues(&webapp_mimetypes_map_);
199 for (ScopedVector<AppResource>::const_iterator it = applist->items().begin();
200 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().
201 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().
202 if (app->product_url().is_empty())
203 continue;
204
205 InstalledApp::IconList app_icons;
206 InstalledApp::IconList document_icons;
207 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.
208 it != app->icons().end(); ++it) {
209 DriveAppIcon* icon = *it;
satorux1 2012/08/10 17:26:02 const reference?
kochi 2012/08/13 09:12:24 Done.
210 if (icon->icon_url().is_empty())
211 continue;
212 if (icon->category() == DriveAppIcon::APPLICATION)
213 app_icons.push_back(std::make_pair(icon->icon_side_length(),
214 icon->icon_url()));
215 if (icon->category() == DriveAppIcon::DOCUMENT)
216 document_icons.push_back(std::make_pair(icon->icon_side_length(),
217 icon->icon_url()));
218 }
219 std::sort(app_icons.begin(), app_icons.end(), SortBySize);
220 std::sort(document_icons.begin(), document_icons.end(), SortBySize);
221
222 url_to_name_map_.insert(
223 std::make_pair(app->product_url(), UTF8ToUTF16(app->name())));
224 AddAppSelectorList(app->product_url(),
225 app_icons,
226 document_icons,
227 UTF8ToUTF16(app->object_type()),
228 app->application_id(),
229 true, // primary
230 app->primary_mimetypes(),
231 &webapp_mimetypes_map_);
232 AddAppSelectorList(app->product_url(),
233 app_icons,
234 document_icons,
235 UTF8ToUTF16(app->object_type()),
236 app->application_id(),
237 false, // primary
238 app->secondary_mimetypes(),
239 &webapp_mimetypes_map_);
240 AddAppSelectorList(app->product_url(),
241 app_icons,
242 document_icons,
243 UTF8ToUTF16(app->object_type()),
244 app->application_id(),
245 true, // primary
246 app->primary_file_extensions(),
247 &webapp_extension_map_);
248 AddAppSelectorList(app->product_url(),
249 app_icons,
250 document_icons,
251 UTF8ToUTF16(app->object_type()),
252 app->application_id(),
253 false, // primary
254 app->secondary_file_extensions(),
255 &webapp_extension_map_);
256 }
257 }
258
185 // static. 259 // static.
186 void DriveWebAppsRegistry::AddAppSelectorList( 260 void DriveWebAppsRegistry::AddAppSelectorList(
187 const GURL& product_link, 261 const GURL& product_link,
188 const InstalledApp::IconList& app_icons, 262 const InstalledApp::IconList& app_icons,
189 const InstalledApp::IconList& document_icons, 263 const InstalledApp::IconList& document_icons,
190 const string16& object_type, 264 const string16& object_type,
191 const std::string& app_id, 265 const std::string& app_id,
192 bool is_primary_selector, 266 bool is_primary_selector,
193 const ScopedVector<std::string>& selectors, 267 const ScopedVector<std::string>& selectors,
194 WebAppFileSelectorMap* map) { 268 WebAppFileSelectorMap* map) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 web_app->app_icons, 306 web_app->app_icons,
233 web_app->document_icons, 307 web_app->document_icons,
234 web_store_id, 308 web_store_id,
235 product_iter->second, // app name. 309 product_iter->second, // app name.
236 web_app->object_type, 310 web_app->object_type,
237 web_app->is_primary_selector))); 311 web_app->is_primary_selector)));
238 } 312 }
239 } 313 }
240 314
241 } // namespace gdata 315 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698