Commit 46c5b30d authored by fukino's avatar fukino Committed by Commit bot

Remove "Move window to..." from gear menu.

This CL removes:
- "Move window to..." menu item from the gear menu.
- Remove APIs fileBrowserPrivate.onProfileAdded and fileBrowserPrivate.onDesktopChanged as they are used only for updating gear menu.
- Remove corresponding tests.

BUG=408965
TEST=run browser_test, unit_tests
TBR=benwells@chromium.org
# TBRing for just removing unused events from file_browser_private.idl

Review URL: https://codereview.chromium.org/530553006

Cr-Commit-Position: refs/heads/master@{#292860}
parent 6e873ef3
......@@ -38,7 +38,6 @@
#include "chromeos/network/network_handler.h"
#include "chromeos/network/network_state_handler.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "extensions/browser/event_router.h"
......@@ -251,22 +250,6 @@ std::string FileErrorToErrorName(base::File::Error error_code) {
}
}
void GrantAccessForAddedProfileToRunningInstance(Profile* added_profile,
Profile* running_profile) {
extensions::ProcessManager* const process_manager =
extensions::ExtensionSystem::Get(running_profile)->process_manager();
if (!process_manager)
return;
extensions::ExtensionHost* const extension_host =
process_manager->GetBackgroundHostForExtension(kFileManagerAppId);
if (!extension_host || !extension_host->render_process_host())
return;
const int id = extension_host->render_process_host()->GetID();
file_manager::util::SetupProfileFileAccessPermissions(id, added_profile);
}
// Checks if we should send a progress event or not according to the
// |last_time| of sending an event. If |always| is true, the function always
// returns true. If the function returns true, the function also updates
......@@ -367,7 +350,6 @@ EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus(
EventRouter::EventRouter(Profile* profile)
: pref_change_registrar_(new PrefChangeRegistrar),
profile_(profile),
multi_user_window_manager_observer_registered_(false),
device_event_router_(new DeviceEventRouterImpl(profile)),
weak_factory_(this) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
......@@ -413,14 +395,6 @@ void EventRouter::Shutdown() {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient();
power_manager_client->RemoveObserver(device_event_router_.get());
chrome::MultiUserWindowManager* const multi_user_window_manager =
chrome::MultiUserWindowManager::GetInstance();
if (multi_user_window_manager &&
multi_user_window_manager_observer_registered_) {
multi_user_window_manager_observer_registered_ = false;
multi_user_window_manager->RemoveObserver(this);
}
profile_ = NULL;
}
......@@ -471,10 +445,6 @@ void EventRouter::ObserveEvents() {
pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback);
pref_change_registrar_->Add(prefs::kDisableDrive, callback);
pref_change_registrar_->Add(prefs::kUse24HourClock, callback);
notification_registrar_.Add(this,
chrome::NOTIFICATION_PROFILE_ADDED,
content::NotificationService::AllSources());
}
// File watch setup routines.
......@@ -940,35 +910,4 @@ void EventRouter::OnFormatCompleted(const std::string& device_path,
// Do nothing.
}
void EventRouter::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
if (type == chrome::NOTIFICATION_PROFILE_ADDED) {
Profile* const added_profile = content::Source<Profile>(source).ptr();
if (!added_profile->IsOffTheRecord())
GrantAccessForAddedProfileToRunningInstance(added_profile, profile_);
BroadcastEvent(profile_,
file_browser_private::OnProfileAdded::kEventName,
file_browser_private::OnProfileAdded::Create());
}
}
void EventRouter::RegisterMultiUserWindowManagerObserver() {
if (multi_user_window_manager_observer_registered_)
return;
chrome::MultiUserWindowManager* const multi_user_window_manager =
chrome::MultiUserWindowManager::GetInstance();
if (multi_user_window_manager) {
multi_user_window_manager->AddObserver(this);
multi_user_window_manager_observer_registered_ = true;
}
}
void EventRouter::OnOwnerEntryChanged(aura::Window* window) {
BroadcastEvent(profile_,
file_browser_private::OnDesktopChanged::kEventName,
file_browser_private::OnDesktopChanged::Create());
}
} // namespace file_manager
......@@ -21,12 +21,9 @@
#include "chrome/browser/chromeos/file_manager/volume_manager.h"
#include "chrome/browser/chromeos/file_manager/volume_manager_observer.h"
#include "chrome/browser/drive/drive_service_interface.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
#include "chrome/common/extensions/api/file_browser_private.h"
#include "chromeos/disks/disk_mount_manager.h"
#include "chromeos/network/network_state_handler_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "webkit/browser/fileapi/file_system_operation.h"
class PrefChangeRegistrar;
......@@ -51,14 +48,11 @@ class DeviceEventRouter;
// Monitors changes in disk mounts, network connection state and preferences
// affecting File Manager. Dispatches appropriate File Browser events.
class EventRouter
: public chromeos::NetworkStateHandlerObserver,
public drive::FileSystemObserver,
public drive::JobListObserver,
public drive::DriveServiceObserver,
public VolumeManagerObserver,
public content::NotificationObserver,
public chrome::MultiUserWindowManager::Observer {
class EventRouter : public chromeos::NetworkStateHandlerObserver,
public drive::FileSystemObserver,
public drive::JobListObserver,
public drive::DriveServiceObserver,
public VolumeManagerObserver {
public:
explicit EventRouter(Profile* profile);
virtual ~EventRouter();
......@@ -96,9 +90,6 @@ class EventRouter
const GURL& destination_url,
int64 size);
// Register observer to the multi user window manager.
void RegisterMultiUserWindowManagerObserver();
// chromeos::NetworkStateHandlerObserver overrides.
virtual void DefaultNetworkChanged(
const chromeos::NetworkState* network) OVERRIDE;
......@@ -135,14 +126,6 @@ class EventRouter
virtual void OnFormatCompleted(
const std::string& device_path, bool success) OVERRIDE;
// content::NotificationObserver overrides.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// chrome::MultiUserWindowManager::Observer overrides:
virtual void OnOwnerEntryChanged(aura::Window* window) OVERRIDE;
private:
typedef std::map<base::FilePath, FileWatcher*> WatcherMap;
......@@ -202,9 +185,6 @@ class EventRouter
scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
Profile* profile_;
content::NotificationRegistrar notification_registrar_;
bool multi_user_window_manager_observer_registered_;
scoped_ptr<DeviceEventRouter> device_event_router_;
// Note: This should remain the last member so it'll be destroyed and
......
......@@ -11,7 +11,6 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/extensions/file_manager/event_router.h"
#include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.h"
#include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
#include "chrome/browser/chromeos/file_manager/app_installer.h"
......@@ -418,11 +417,6 @@ bool FileBrowserPrivateVisitDesktopFunction::RunSync() {
return false;
}
// Observe owner changes of windows.
file_manager::EventRouter* const event_router =
file_manager::FileBrowserPrivateAPI::Get(GetProfile())->event_router();
event_router->RegisterMultiUserWindowManagerObserver();
// Move the window to the user's desktop.
window_manager->ShowWindowForUser(app_window->GetNativeWindow(),
params->profile_id);
......
......@@ -1219,26 +1219,6 @@ IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest, MAYBE_BasicDrive) {
StartTest();
}
// Slow tests are disabled on debug build. http://crbug.com/327719
#if !defined(NDEBUG)
#define MAYBE_PRE_VisitDesktopMenu DISABLED_PRE_VisitDesktopMenu
#define MAYBE_VisitDesktopMenu DISABLED_VisitDesktopMenu
#else
#define MAYBE_PRE_VisitDesktopMenu PRE_VisitDesktopMenu
#define MAYBE_VisitDesktopMenu VisitDesktopMenu
#endif
IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest,
MAYBE_PRE_VisitDesktopMenu) {
AddAllUsers();
}
IN_PROC_BROWSER_TEST_F(MultiProfileFileManagerBrowserTest,
MAYBE_VisitDesktopMenu) {
// Test for the menu item for visiting other profile's desktop.
set_test_case_name("multiProfileVisitDesktopMenu");
StartTest();
}
template<GuestMode M>
class GalleryBrowserTestBase : public FileManagerBrowserTestBase {
public:
......
......@@ -818,12 +818,5 @@ interface Events {
static void onDeviceChanged(DeviceEvent event);
static void onDriveSyncError(DriveSyncErrorEvent event);
// Dispatched when a profile is added.
static void onProfileAdded();
// Dispatched when any window moves another desktop.
// TODO(hirono): Add information which window is moved.
static void onDesktopChanged();
};
};
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* @type {string}
* @const
*/
var UNTIL_ADDED = 'untilAdded';
/**
* @type {string}
* @const
*/
var UNTIL_REMOVED = 'untilRemoved';
/**
* Waits for the 'move to profileId' menu to appear or to disappear.
* @param {string} windowId Window ID.
* @param {string} profileId Profile ID.
* @param {string} waitMode UNTIL_ADDED or UNTIL_REMOVED.
* @return {Promise} Promise to be fulfilled when the menu appears or
* disappears.
*/
function waitForVisitDesktopMenu(windowId, profileId, waitMode) {
if (waitMode !== UNTIL_ADDED && waitMode !== UNTIL_REMOVED)
throw new Error('Wait mode is invalid: ' + waitMode);
return repeatUntil(function() {
return callRemoteTestUtil('queryAllElements', windowId, ['.visit-desktop']).
then(function(elements) {
var found = false;
for (var i = 0; i < elements.length; i++) {
if (elements[i].text.indexOf(profileId) !== -1) {
found = true;
break;
}
}
if ((waitMode === UNTIL_ADDED && !found) ||
(waitMode === UNTIL_REMOVED && found))
return pending(
'Waiting for the visit desktop menu to %s: ' +
'%s, but currently it is %j.',
waitMode === UNTIL_ADDED ? 'contain' : 'exclude',
profileId,
elements);
});
});
}
testcase.multiProfileVisitDesktopMenu = function() {
var appId;
StepsRunner.run([
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
// Add all users.
function(inAppId) {
appId = inAppId;
chrome.test.sendMessage(JSON.stringify({name: 'addAllUsers'}),
this.next);
},
// Wait for menu items. Profiles for non-current desktop should appear and
// the profile for the current desktop (alice) should be hidden.
function(json) {
chrome.test.assertTrue(JSON.parse(json));
Promise.all([
waitForVisitDesktopMenu(appId, 'bob@invalid.domain', UNTIL_ADDED),
waitForVisitDesktopMenu(appId, 'charlie@invalid.domain', UNTIL_ADDED),
waitForVisitDesktopMenu(appId, 'alice@invalid.domain', UNTIL_REMOVED)
]).
then(this.next, function(error) {
chrome.test.fail(error.stack || error);
});
},
// Activate the visit desktop menu.
function() {
callRemoteTestUtil('runVisitDesktopMenu',
appId,
['bob@invalid.domain'],
this.next);
},
// Wait for the new menu state. Now 'alice' is shown and 'bob' is hidden.
function(result) {
chrome.test.assertTrue(result);
Promise.all([
waitForVisitDesktopMenu(appId, 'bob@invalid.domain', UNTIL_REMOVED),
waitForVisitDesktopMenu(appId, 'charlie@invalid.domain', UNTIL_ADDED),
waitForVisitDesktopMenu(appId, 'alice@invalid.domain', UNTIL_ADDED)
]).
then(this.next, function(error) {
chrome.test.fail(error.stack || error);
});
},
// Check that the window owner has indeed been changed.
function() {
chrome.test.sendMessage(JSON.stringify({name: 'getWindowOwnerId'}),
this.next);
},
function(result) {
chrome.test.assertEq('bob@invalid.domain', result);
checkIfNoErrorsOccured(this.next);
}
]);
};
......@@ -19,7 +19,6 @@
"file_manager/folder_shortcuts.js",
"file_manager/grid_view.js",
"file_manager/keyboard_operations.js",
"file_manager/multi_profile.js",
"file_manager/open_audio_files.js",
"file_manager/open_video_files.js",
"file_manager/open_zip_files.js",
......
......@@ -478,12 +478,6 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
this.gearButton_ = this.dialogDom_.querySelector('#gear-button');
this.gearButton_.addEventListener('menushow',
this.onShowGearMenu_.bind(this));
chrome.fileBrowserPrivate.onDesktopChanged.addListener(function() {
this.updateVisitDesktopMenus_();
}.bind(this));
chrome.fileBrowserPrivate.onProfileAdded.addListener(
this.updateVisitDesktopMenus_.bind(this));
this.updateVisitDesktopMenus_();
this.dialogDom_.querySelector('#gear-menu').menuItemSelector =
'menuitem, hr';
......@@ -2154,62 +2148,6 @@ var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52;
this.refreshRemainingSpace_(true); // Show loading caption.
};
/**
* Update menus that move the window to the other profile's desktop.
* TODO(hirono): Add the GearMenu class and make it a member of the class.
* TODO(hirono): Handle the case where a profile is added while the menu is
* opened.
* @private
*/
FileManager.prototype.updateVisitDesktopMenus_ = function() {
var gearMenu = this.document_.querySelector('#gear-menu');
var separator =
this.document_.querySelector('#multi-profile-separator');
// Remove existing menu items.
var oldItems =
this.document_.querySelectorAll('#gear-menu .visit-desktop');
for (var i = 0; i < oldItems.length; i++) {
gearMenu.removeChild(oldItems[i]);
}
separator.hidden = true;
if (this.dialogType !== DialogType.FULL_PAGE)
return;
// Obtain the profile information.
chrome.fileBrowserPrivate.getProfiles(function(profiles,
currentId,
displayedId) {
// Check if the menus are needed or not.
var insertingPosition = separator.nextSibling;
if (profiles.length === 1 && profiles[0].profileId === displayedId)
return;
separator.hidden = false;
for (var i = 0; i < profiles.length; i++) {
var profile = profiles[i];
if (profile.profileId === displayedId)
continue;
var item = this.document_.createElement('menuitem');
cr.ui.MenuItem.decorate(item);
gearMenu.insertBefore(item, insertingPosition);
item.className = 'visit-desktop';
item.label = strf('VISIT_DESKTOP_OF_USER',
profile.displayName,
profile.profileId);
item.addEventListener('activate', function(inProfile, event) {
// Stop propagate and hide the menu manually, in order to prevent the
// focus from being back to the button. (cf. http://crbug.com/248479)
event.stopPropagation();
this.gearButton_.hideMenu();
this.gearButton_.blur();
chrome.fileBrowserPrivate.visitDesktop(inProfile.profileId);
}.bind(this, profile));
}
}.bind(this));
};
/**
* Refreshes space info of the current volume.
* @param {boolean} showLoadingCaption Whether show loading caption or not.
......
......@@ -241,7 +241,6 @@
<menu id="gear-menu" class="chrome-menu" showShortcuts>
<menuitem id="gear-menu-newwindow" command="#new-window"></menuitem>
<menuitem id="gear-menu-newfolder" command="#new-folder"></menuitem>
<hr id="multi-profile-separator">
<hr id="drive-separator">
<menuitem id="gear-menu-drive-sync-settings"
command="#drive-sync-settings"></menuitem>
......
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