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

Side by Side Diff: chrome/browser/dom_ui/app_launcher_handler.cc

Issue 6297013: [NTP] Allow reordering of apps via drag and drop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: incorporate feedback Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/dom_ui/app_launcher_handler.h" 5 #include "chrome/browser/dom_ui/app_launcher_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 dom_ui_->RegisterMessageCallback("launchApp", 150 dom_ui_->RegisterMessageCallback("launchApp",
151 NewCallback(this, &AppLauncherHandler::HandleLaunchApp)); 151 NewCallback(this, &AppLauncherHandler::HandleLaunchApp));
152 dom_ui_->RegisterMessageCallback("setLaunchType", 152 dom_ui_->RegisterMessageCallback("setLaunchType",
153 NewCallback(this, &AppLauncherHandler::HandleSetLaunchType)); 153 NewCallback(this, &AppLauncherHandler::HandleSetLaunchType));
154 dom_ui_->RegisterMessageCallback("uninstallApp", 154 dom_ui_->RegisterMessageCallback("uninstallApp",
155 NewCallback(this, &AppLauncherHandler::HandleUninstallApp)); 155 NewCallback(this, &AppLauncherHandler::HandleUninstallApp));
156 dom_ui_->RegisterMessageCallback("hideAppsPromo", 156 dom_ui_->RegisterMessageCallback("hideAppsPromo",
157 NewCallback(this, &AppLauncherHandler::HandleHideAppsPromo)); 157 NewCallback(this, &AppLauncherHandler::HandleHideAppsPromo));
158 dom_ui_->RegisterMessageCallback("createAppShortcut", 158 dom_ui_->RegisterMessageCallback("createAppShortcut",
159 NewCallback(this, &AppLauncherHandler::HandleCreateAppShortcut)); 159 NewCallback(this, &AppLauncherHandler::HandleCreateAppShortcut));
160 dom_ui_->RegisterMessageCallback("reorderApps",
161 NewCallback(this, &AppLauncherHandler::HandleReorderApps));
160 } 162 }
161 163
162 void AppLauncherHandler::Observe(NotificationType type, 164 void AppLauncherHandler::Observe(NotificationType type,
163 const NotificationSource& source, 165 const NotificationSource& source,
164 const NotificationDetails& details) { 166 const NotificationDetails& details) {
165 if (ignore_changes_) 167 if (ignore_changes_)
166 return; 168 return;
167 169
168 switch (type.value) { 170 switch (type.value) {
169 case NotificationType::EXTENSION_LOADED: 171 case NotificationType::EXTENSION_LOADED:
170 case NotificationType::EXTENSION_UNLOADED: 172 case NotificationType::EXTENSION_UNLOADED:
173 case NotificationType::EXTENSION_LAUNCHER_REORDERED:
171 if (dom_ui_->tab_contents()) 174 if (dom_ui_->tab_contents())
172 HandleGetApps(NULL); 175 HandleGetApps(NULL);
173 break; 176 break;
174 case NotificationType::PREF_CHANGED: { 177 case NotificationType::PREF_CHANGED: {
175 if (!dom_ui_->tab_contents()) 178 if (!dom_ui_->tab_contents())
176 break; 179 break;
177 180
178 DictionaryValue dictionary; 181 DictionaryValue dictionary;
179 FillAppDictionary(&dictionary); 182 FillAppDictionary(&dictionary);
180 dom_ui_->CallJavascriptFunction(L"appsPrefChangeCallback", dictionary); 183 dom_ui_->CallJavascriptFunction(L"appsPrefChangeCallback", dictionary);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 FillAppDictionary(&dictionary); 253 FillAppDictionary(&dictionary);
251 dom_ui_->CallJavascriptFunction(L"getAppsCallback", dictionary); 254 dom_ui_->CallJavascriptFunction(L"getAppsCallback", dictionary);
252 255
253 // First time we get here we set up the observer so that we can tell update 256 // First time we get here we set up the observer so that we can tell update
254 // the apps as they change. 257 // the apps as they change.
255 if (registrar_.IsEmpty()) { 258 if (registrar_.IsEmpty()) {
256 registrar_.Add(this, NotificationType::EXTENSION_LOADED, 259 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
257 NotificationService::AllSources()); 260 NotificationService::AllSources());
258 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, 261 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
259 NotificationService::AllSources()); 262 NotificationService::AllSources());
263 registrar_.Add(this, NotificationType::EXTENSION_LAUNCHER_REORDERED,
264 NotificationService::AllSources());
260 } 265 }
261 if (pref_change_registrar_.IsEmpty()) { 266 if (pref_change_registrar_.IsEmpty()) {
262 pref_change_registrar_.Init( 267 pref_change_registrar_.Init(
263 extensions_service_->extension_prefs()->pref_service()); 268 extensions_service_->extension_prefs()->pref_service());
264 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this); 269 pref_change_registrar_.Add(ExtensionPrefs::kExtensionsPref, this);
265 } 270 }
266 } 271 }
267 272
268 void AppLauncherHandler::HandleLaunchApp(const ListValue* args) { 273 void AppLauncherHandler::HandleLaunchApp(const ListValue* args) {
269 std::string extension_id; 274 std::string extension_id;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 extensions_service_->GetExtensionById(extension_id, false); 385 extensions_service_->GetExtensionById(extension_id, false);
381 CHECK(extension); 386 CHECK(extension);
382 387
383 Browser* browser = BrowserList::GetLastActive(); 388 Browser* browser = BrowserList::GetLastActive();
384 if (!browser) 389 if (!browser)
385 return; 390 return;
386 browser->window()->ShowCreateChromeAppShortcutsDialog( 391 browser->window()->ShowCreateChromeAppShortcutsDialog(
387 browser->profile(), extension); 392 browser->profile(), extension);
388 } 393 }
389 394
395 void AppLauncherHandler::HandleReorderApps(const ListValue* args) {
396 std::vector<std::string> extension_ids;
397 for (size_t i = 0; i < args->GetSize(); ++i) {
398 std::string value;
399 if (args->GetString(i, &value))
400 extension_ids.push_back(value);
401 }
402
403 extensions_service_->extension_prefs()->SetAppLauncherOrder(extension_ids);
404 }
405
390 // static 406 // static
391 void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) { 407 void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) {
392 if (!promo_active) return; 408 if (!promo_active) return;
393 409
394 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, 410 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram,
395 extension_misc::PROMO_LAUNCH_WEB_STORE, 411 extension_misc::PROMO_LAUNCH_WEB_STORE,
396 extension_misc::PROMO_BUCKET_BOUNDARY); 412 extension_misc::PROMO_BUCKET_BOUNDARY);
397 } 413 }
398 414
399 // static 415 // static
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 464
449 void AppLauncherHandler::UninstallDefaultApps() { 465 void AppLauncherHandler::UninstallDefaultApps() {
450 DefaultApps* default_apps = extensions_service_->default_apps(); 466 DefaultApps* default_apps = extensions_service_->default_apps();
451 const ExtensionIdSet& app_ids = default_apps->default_apps(); 467 const ExtensionIdSet& app_ids = default_apps->default_apps();
452 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); 468 for (ExtensionIdSet::const_iterator iter = app_ids.begin();
453 iter != app_ids.end(); ++iter) { 469 iter != app_ids.end(); ++iter) {
454 if (extensions_service_->GetExtensionById(*iter, true)) 470 if (extensions_service_->GetExtensionById(*iter, true))
455 extensions_service_->UninstallExtension(*iter, false); 471 extensions_service_->UninstallExtension(*iter, false);
456 } 472 }
457 } 473 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698