Index: chrome/browser/media_galleries/media_galleries_dialog_controller.h |
diff --git a/chrome/browser/media_galleries/media_galleries_dialog_controller.h b/chrome/browser/media_galleries/media_galleries_dialog_controller.h |
index 14abc3af3fd9f33d54e2fff8eb28001487783c41..01075807f984abaa93bfeebea7658ab81f8becf8 100644 |
--- a/chrome/browser/media_galleries/media_galleries_dialog_controller.h |
+++ b/chrome/browser/media_galleries/media_galleries_dialog_controller.h |
@@ -1,46 +1,24 @@ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// 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. |
#ifndef CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ |
#define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ |
-#include <map> |
-#include <string> |
#include <vector> |
-#include "base/callback.h" |
-#include "base/memory/scoped_ptr.h" |
#include "base/strings/string16.h" |
#include "chrome/browser/media_galleries/media_galleries_preferences.h" |
-#include "components/storage_monitor/removable_storage_observer.h" |
-#include "ui/gfx/native_widget_types.h" |
-#include "ui/shell_dialogs/select_file_dialog.h" |
namespace content { |
class WebContents; |
} |
-namespace extensions { |
-class Extension; |
-} |
- |
namespace ui { |
class MenuModel; |
} |
class MediaGalleriesDialogController; |
-class MediaGalleryContextMenu; |
-class Profile; |
- |
-// Newly added galleries are not added to preferences until the dialog commits, |
-// so they do not have a pref id while the dialog is open; leading to |
-// complicated code in the dialogs. To solve this complication, the controller |
-// maps pref ids into a new space where it can also assign ids to new galleries. |
-// The new number space is only valid for the lifetime of the controller. To |
-// make it more clear where real pref ids are used and where the fake ids are |
-// used, the GalleryDialogId type is used where fake ids are needed. |
-typedef MediaGalleryPrefId GalleryDialogId; |
// The view. |
class MediaGalleriesDialog { |
@@ -55,209 +33,72 @@ class MediaGalleriesDialog { |
MediaGalleriesDialogController* controller); |
}; |
-// The controller is responsible for handling the logic of the dialog and |
-// interfacing with the model (i.e., MediaGalleriesPreferences). It shows |
-// the dialog and owns itself. |
-class MediaGalleriesDialogController |
- : public ui::SelectFileDialog::Listener, |
- public storage_monitor::RemovableStorageObserver, |
- public MediaGalleriesPreferences::GalleryChangeObserver { |
+// Multiple dialog controllers are based on this interface. |
+// Implementations of this controller interface are responsible for handling |
+// the logic of the dialog and interfacing with the model (i.e., |
+// MediaGalleriesPreferences). It shows the dialog and owns itself. |
+class MediaGalleriesDialogController { |
public: |
- struct GalleryPermission { |
- GalleryPermission(GalleryDialogId gallery_id, |
- const MediaGalleryPrefInfo& pref_info, |
- bool allowed) |
- : gallery_id(gallery_id), |
- pref_info(pref_info), |
- allowed(allowed) { |
+ struct Entry { |
+ Entry(const MediaGalleryPrefInfo& pref_info, bool selected) |
+ : pref_info(pref_info), |
+ selected(selected) { |
} |
- GalleryPermission() {} |
+ Entry() {} |
- GalleryDialogId gallery_id; |
MediaGalleryPrefInfo pref_info; |
- bool allowed; |
+ bool selected; |
}; |
- typedef std::vector<GalleryPermission> GalleryPermissionsVector; |
- |
- // The constructor creates a dialog controller which owns itself. |
- MediaGalleriesDialogController(content::WebContents* web_contents, |
- const extensions::Extension& extension, |
- const base::Closure& on_finish); |
+ typedef std::vector<Entry> Entries; |
// The title of the dialog view. |
- base::string16 GetHeader() const; |
+ virtual base::string16 GetHeader() const = 0; |
// Explanatory text directly below the title. |
- base::string16 GetSubtext() const; |
- |
- // Header for unattached devices part of the dialog. |
- base::string16 GetUnattachedLocationsHeader() const; |
+ virtual base::string16 GetSubtext() const = 0; |
// Initial state of whether the dialog's confirmation button will be enabled. |
- bool IsAcceptAllowed() const; |
- |
- // Get the set of permissions to attached galleries. |
- virtual GalleryPermissionsVector AttachedPermissions() const; |
+ virtual bool IsAcceptAllowed() const = 0; |
- // Get the set of permissions to unattached galleries. |
- virtual GalleryPermissionsVector UnattachedPermissions() const; |
+ // Should the dialog present UI for the user to view the entry contents. |
+ virtual bool ShouldShowFolderViewer(const Entry& entry) const = 0; |
- // Called when the add-folder button in the dialog is clicked. |
- virtual void OnAddFolderClicked(); |
- |
- // A checkbox beside a gallery permission was checked. The full set |
- // of gallery permissions checkbox settings is sent on every checkbox toggle. |
- virtual void DidToggleGallery(GalleryDialogId gallery_id, bool enabled); |
- |
- // The forget command in the context menu was selected. |
- virtual void DidForgetGallery(GalleryDialogId gallery_id); |
- |
- // The dialog is being deleted. |
- virtual void DialogFinished(bool accepted); |
+ // The titles for different sections of entries. Empty hides the header. |
+ virtual std::vector<base::string16> GetSectionHeaders() const = 0; |
- virtual content::WebContents* web_contents(); |
+ // Get the set of permissions for the |index|th section. The size of the |
+ // vector returned from GetSectionHeaders() defines the number of sections. |
+ virtual Entries GetSectionEntries(size_t index) const = 0; |
- ui::MenuModel* GetContextMenu(GalleryDialogId gallery_id); |
- |
- protected: |
- friend class MediaGalleriesDialogControllerTest; |
- |
- typedef base::Callback<MediaGalleriesDialog* ( |
- MediaGalleriesDialogController*)> CreateDialogCallback; |
- |
- // For use with tests. |
- MediaGalleriesDialogController( |
- const extensions::Extension& extension, |
- MediaGalleriesPreferences* preferences, |
- const CreateDialogCallback& create_dialog_callback, |
- const base::Closure& on_finish); |
- |
- virtual ~MediaGalleriesDialogController(); |
- |
- private: |
- // This type keeps track of media galleries already known to the prefs system. |
- typedef std::map<GalleryDialogId, GalleryPermission> |
- GalleryPermissionsMap; |
- |
- class DialogIdMap { |
- public: |
- DialogIdMap(); |
- ~DialogIdMap(); |
- GalleryDialogId GetDialogId(MediaGalleryPrefId pref_id); |
- |
- private: |
- GalleryDialogId next_dialog_id_; |
- std::map<GalleryDialogId, MediaGalleryPrefId> mapping_; |
- DISALLOW_COPY_AND_ASSIGN(DialogIdMap); |
- }; |
+ // The text for an auxiliary button. Empty hides the button. |
+ virtual base::string16 GetAuxiliaryButtonText() const = 0; |
+ // Called when an auxiliary button is clicked. |
+ virtual void DidClickAuxiliaryButton() = 0; |
- // Bottom half of constructor -- called when |preferences_| is initialized. |
- void OnPreferencesInitialized(); |
+ // An entry checkbox was toggled. |
+ virtual void DidToggleEntry(MediaGalleryPrefId id, bool selected) = 0; |
- // SelectFileDialog::Listener implementation: |
- virtual void FileSelected(const base::FilePath& path, |
- int index, |
- void* params) OVERRIDE; |
+ // A folder viewer button was clicked for one of the entries. |
+ virtual void DidClickOpenFolderViewer(MediaGalleryPrefId id) = 0; |
- // RemovableStorageObserver implementation. |
- // Used to keep dialog in sync with removable device status. |
- virtual void OnRemovableStorageAttached( |
- const storage_monitor::StorageInfo& info) OVERRIDE; |
- virtual void OnRemovableStorageDetached( |
- const storage_monitor::StorageInfo& info) OVERRIDE; |
- |
- // MediaGalleriesPreferences::GalleryChangeObserver implementations. |
- // Used to keep the dialog in sync when the preferences change. |
- virtual void OnPermissionAdded(MediaGalleriesPreferences* pref, |
- const std::string& extension_id, |
- MediaGalleryPrefId pref_id) OVERRIDE; |
- virtual void OnPermissionRemoved(MediaGalleriesPreferences* pref, |
- const std::string& extension_id, |
- MediaGalleryPrefId pref_id) OVERRIDE; |
- virtual void OnGalleryAdded(MediaGalleriesPreferences* pref, |
- MediaGalleryPrefId pref_id) OVERRIDE; |
- virtual void OnGalleryRemoved(MediaGalleriesPreferences* pref, |
- MediaGalleryPrefId pref_id) OVERRIDE; |
- virtual void OnGalleryInfoUpdated(MediaGalleriesPreferences* pref, |
- MediaGalleryPrefId pref_id) OVERRIDE; |
- |
- // Populates |known_galleries_| from |preferences_|. Subsequent calls merge |
- // into |known_galleries_| and do not change permissions for user toggled |
- // galleries. |
- void InitializePermissions(); |
- |
- // Saves state of |known_galleries_|, |new_galleries_| and |
- // |forgotten_galleries_| to model. |
- // |
- // NOTE: possible states for a gallery: |
- // K N F (K = Known, N = New, F = Forgotten) |
- // +---+---+---+ |
- // | Y | N | N | |
- // +---+---+---+ |
- // | N | Y | N | |
- // +---+---+---+ |
- // | Y | N | Y | |
- // +---+---+---+ |
- void SavePermissions(); |
- |
- // Updates the model and view when |preferences_| changes. Some of the |
- // possible changes includes a gallery getting blacklisted, or a new |
- // auto detected gallery becoming available. |
- void UpdateGalleriesOnPreferencesEvent(); |
- |
- // Updates the model and view when a device is attached or detached. |
- void UpdateGalleriesOnDeviceEvent(const std::string& device_id); |
- |
- // Return a sorted vector of either attached or unattached gallery |
- // permissions. |
- GalleryPermissionsVector FillPermissions(bool attached) const; |
- |
- GalleryDialogId GetDialogId(MediaGalleryPrefId pref_id); |
- |
- Profile* GetProfile(); |
- |
- // The web contents from which the request originated. |
- content::WebContents* web_contents_; |
- |
- // This is just a reference, but it's assumed that it won't become invalid |
- // while the dialog is showing. |
- const extensions::Extension* extension_; |
- |
- // Mapping between pref ids and dialog ids. |
- DialogIdMap id_map_; |
- |
- // This map excludes those galleries which have been blacklisted; it only |
- // counts active known galleries. |
- GalleryPermissionsMap known_galleries_; |
- |
- // Galleries in |known_galleries_| that the user have toggled. |
- std::set<GalleryDialogId> toggled_galleries_; |
- |
- // Map of new galleries the user added, but have not saved. This list should |
- // never overlap with |known_galleries_|. |
- GalleryPermissionsMap new_galleries_; |
- |
- // Galleries in |known_galleries_| that the user has forgotten. |
- std::set<GalleryDialogId> forgotten_galleries_; |
- |
- // Callback to run when the dialog closes. |
- base::Closure on_finish_; |
+ // The forget command in the context menu was selected. |
+ virtual void DidForgetEntry(MediaGalleryPrefId id) = 0; |
- // The model that tracks galleries and extensions' permissions. |
- // This is the authoritative source for gallery information. |
- MediaGalleriesPreferences* preferences_; |
+ // The text for the accept button. |
+ virtual base::string16 GetAcceptButtonText() const = 0; |
- // The view that's showing. |
- scoped_ptr<MediaGalleriesDialog> dialog_; |
+ // The dialog is being deleted. |
+ virtual void DialogFinished(bool accepted) = 0; |
- scoped_refptr<ui::SelectFileDialog> select_folder_dialog_; |
+ virtual ui::MenuModel* GetContextMenu(MediaGalleryPrefId id) = 0; |
- scoped_ptr<MediaGalleryContextMenu> context_menu_; |
+ virtual content::WebContents* WebContents() = 0; |
- // Creates the dialog. Only changed for unit tests. |
- CreateDialogCallback create_dialog_callback_; |
+ protected: |
+ MediaGalleriesDialogController(); |
+ virtual ~MediaGalleriesDialogController(); |
DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogController); |
}; |