Commit ef8f0ca9 authored by jstritar@chromium.org's avatar jstritar@chromium.org

Track which apps the user has re-ordered on the NTP.

BUG=73445
TEST=ExtensionPrefsAppDraggedByUser

Review URL: http://codereview.chromium.org/6543017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75497 0039d316-1c4b-4281-b951-d872f2087c98
parent 1ab7761d
......@@ -79,6 +79,9 @@ const char kPrefLaunchType[] = "launchType";
// A preference determining the order of which the apps appear on the NTP.
const char kPrefAppLaunchIndex[] = "app_launcher_index";
// A preference specifying if the user dragged the app on the NTP.
const char kPrefUserDraggedApp[] = "user_dragged_app_ntp";
// A preference for storing extra data sent in update checks for an extension.
const char kUpdateUrlData[] = "update_url_data";
......@@ -1126,6 +1129,27 @@ void ExtensionPrefs::SetAppLauncherOrder(
NotificationService::NoDetails());
}
bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) {
DictionaryValue* dictionary = GetExtensionPref(extension_id);
if (!dictionary) {
NOTREACHED();
return false;
}
return ReadBooleanFromPref(dictionary, kPrefUserDraggedApp);
}
void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) {
DictionaryValue* dictionary = GetExtensionPref(extension_id);
if (!dictionary) {
NOTREACHED();
return;
}
dictionary->SetBoolean(kPrefUserDraggedApp, true);
SavePrefsAndNotify();
}
void ExtensionPrefs::SetUpdateUrlData(const std::string& extension_id,
const std::string& data) {
DictionaryValue* dictionary = GetExtensionPref(extension_id);
......
......@@ -260,6 +260,14 @@ class ExtensionPrefs {
// Sets the order the apps should be displayed in the app launcher.
void SetAppLauncherOrder(const std::vector<std::string>& extension_ids);
// Returns true if the user repositioned the app on the app launcher via drag
// and drop.
bool WasAppDraggedByUser(const std::string& extension_id);
// Sets a flag indicating that the user repositioned the app on the app
// launcher by drag and dropping it.
void SetAppDraggedByUser(const std::string& extension_id);
// The extension's update URL data. If not empty, the ExtensionUpdater
// will append a ap= parameter to the URL when checking if a new version
// of the extension is available.
......
......@@ -550,6 +550,30 @@ class ExtensionPrefsAppLaunchIndex : public ExtensionPrefsTest {
};
TEST_F(ExtensionPrefsAppLaunchIndex, ExtensionPrefsAppLaunchIndex) {}
class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest {
public:
virtual void Initialize() {
extension_ = prefs_.AddExtension("on_extension_installed");
EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id()));
prefs()->OnExtensionInstalled(extension_.get(),
Extension::ENABLED, false);
}
virtual void Verify() {
// Set the flag and see if it persisted.
prefs()->SetAppDraggedByUser(extension_->id());
EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id()));
// Make sure it doesn't change on consecutive calls.
prefs()->SetAppDraggedByUser(extension_->id());
EXPECT_TRUE(prefs()->WasAppDraggedByUser(extension_->id()));
}
private:
scoped_refptr<Extension> extension_;
};
TEST_F(ExtensionPrefsAppDraggedByUser, ExtensionPrefsAppDraggedByUser) {}
namespace keys = extension_manifest_keys;
class ExtensionPrefsPreferencesBase : public ExtensionPrefsTest {
......
......@@ -524,10 +524,11 @@ var apps = (function() {
this.scrollMouseXY_ = null;
},
saveDrag: function() {
saveDrag: function(draggedItem) {
this.invalidate_();
this.layout();
var draggedAppId = draggedItem.querySelector('a').getAttribute('app-id');
var appIds = this.data.filter(function(id) {
return id != 'web-store-entry';
});
......@@ -535,7 +536,7 @@ var apps = (function() {
// Wait until the transitions are complete before notifying the browser.
// Otherwise, the apps will be re-rendered while still transitioning.
setTimeout(function() {
chrome.send('reorderApps', appIds);
chrome.send('reorderApps', [draggedAppId, appIds]);
}, this.transitionsDuration + 10);
},
......
......@@ -23,9 +23,10 @@
// tells the delegate that the dragged item is currently above
// the specified coordinates.
//
// saveDrag() -->
// saveDrag(draggedItem) -->
// tells the delegate that the drag is done. move the item to the
// position last specified by setDragPlaceholder. (e.g., commit changes)
// position last specified by setDragPlaceholder (e.g., commit changes).
// draggedItem was the item being dragged.
//
// The distance, in px, that the mouse must move before initiating a drag.
......@@ -162,7 +163,7 @@ DragAndDropController.prototype = {
return;
this.delegate_.dragItem = this.startItem_ = null;
this.delegate_.saveDrag();
this.delegate_.saveDrag(dragItem);
dragItem.classList.remove('dragging');
setTimeout(function() {
......
......@@ -424,13 +424,21 @@ void AppLauncherHandler::HandleCreateAppShortcut(const ListValue* args) {
}
void AppLauncherHandler::HandleReorderApps(const ListValue* args) {
CHECK(args->GetSize() == 2);
std::string dragged_app_id;
ListValue* app_order;
CHECK(args->GetString(0, &dragged_app_id));
CHECK(args->GetList(1, &app_order));
std::vector<std::string> extension_ids;
for (size_t i = 0; i < args->GetSize(); ++i) {
for (size_t i = 0; i < app_order->GetSize(); ++i) {
std::string value;
if (args->GetString(i, &value))
if (app_order->GetString(i, &value))
extension_ids.push_back(value);
}
extensions_service_->extension_prefs()->SetAppDraggedByUser(dragged_app_id);
extensions_service_->extension_prefs()->SetAppLauncherOrder(extension_ids);
}
......
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