Chromium Code Reviews| Index: chrome/browser/media_gallery/media_galleries_dialog_controller.h |
| diff --git a/chrome/browser/media_gallery/media_galleries_dialog_controller.h b/chrome/browser/media_gallery/media_galleries_dialog_controller.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d31fee8d039f65e2b52c10c344c3fded3ca9a15c |
| --- /dev/null |
| +++ b/chrome/browser/media_gallery/media_galleries_dialog_controller.h |
| @@ -0,0 +1,134 @@ |
| +// Copyright (c) 2012 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_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ |
| +#define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ |
| + |
| +#include <list> |
| +#include <map> |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/string16.h" |
| +#include "chrome/browser/media_gallery/media_galleries_preferences.h" |
| +#include "ui/base/dialogs/select_file_dialog.h" |
| +#include "ui/gfx/native_widget_types.h" |
| + |
| +namespace extensions { |
| +struct Extension; |
| +} |
| + |
| +class TabContents; |
| + |
| +namespace chrome { |
| + |
| +class MediaGalleriesDialogController; |
| + |
| +// The view. |
| +class MediaGalleriesDialog { |
| + public: |
| + // Updates the checkbox state for |gallery|. |gallery| is owned by the |
| + // controller and is guaranteed to live longer than the dialog. If the |
| + // checkbox doesn't already exist, it should be created. |
| + virtual void UpdateGallery(const MediaGalleryPrefInfo* gallery, |
| + bool permitted) = 0; |
| + |
| + // Constructs a platform-specific dialog owned and controlled by |controller|. |
| + static MediaGalleriesDialog* Create( |
| + MediaGalleriesDialogController* controller); |
| +}; |
| + |
| +// An interface that notifies the caller when the user has finished interacting |
| +// with the dialog. |
| +class MediaGalleriesDialogDelegate { |
|
vandebo (ex-Chrome)
2012/08/08 19:24:21
Is there a reason to use a delegate instead of a c
Evan Stade
2012/08/08 21:48:57
Done.
|
| + public: |
| + // Called when the dialog has been dismissed. |
| + virtual void MediaGalleriesDialogFinished() = 0; |
| +}; |
| + |
| +// 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: |
| + // The constructor creates a dialog controller which owns itself. |
| + MediaGalleriesDialogController(TabContents* tab_contents, |
| + const extensions::Extension& extension, |
| + MediaGalleriesDialogDelegate* delegate); |
| + |
| + // Called by the view. |
| + string16 GetHeader(); |
| + string16 GetSubtext(); |
| + void OnAddFolderClicked(); |
| + void GalleryToggled(const MediaGalleryPrefInfo*, bool enabled); |
|
vandebo (ex-Chrome)
2012/08/08 19:24:21
This can be const ref
Evan Stade
2012/08/08 21:48:57
same case as UpdateGallery
|
| + void DialogFinished(bool accepted); |
| + |
| + // SelectFileDialog::Listener implementation: |
| + virtual void FileSelected(const FilePath& path, |
| + int index, |
| + void* params) OVERRIDE; |
| + |
| + struct GalleryPermission { |
|
vandebo (ex-Chrome)
2012/08/08 19:24:21
Should go above the constructor (implied by style
Evan Stade
2012/08/08 21:48:57
Done.
|
| + GalleryPermission(const MediaGalleryPrefInfo& pref_info, bool allowed) |
| + : pref_info(pref_info), allowed(allowed) {} |
| + GalleryPermission() {} |
| + |
| + MediaGalleryPrefInfo pref_info; |
| + bool allowed; |
| + }; |
| + |
| + // This type keeps track of media galleries already known to the prefs system. |
| + typedef std::map<MediaGalleryPrefId, GalleryPermission> |
|
vandebo (ex-Chrome)
2012/08/08 19:24:21
typedefs should be above constructors
Evan Stade
2012/08/08 21:48:57
Done.
|
| + KnownGalleryPermissions; |
| + const KnownGalleryPermissions& permissions() const { |
| + return known_galleries_; |
| + } |
| + |
| + TabContents* tab_contents() const { |
| + return tab_contents_; |
| + } |
| + |
| + private: |
| + virtual ~MediaGalleriesDialogController(); |
| + |
| + // Populates |known_galleries_|. |
| + void LookUpPermissions(); |
| + |
| + // Saves state of |known_galleries_| and |new_galleries_| to model. |
| + void SavePermissions(); |
| + |
| + // This type is for media galleries that have been added via "add gallery" |
| + // button, but have not yet been committed to the prefs system and will be |
| + // forgotten if the user Cancels. Since they don't have IDs assigned yet, it's |
| + // just a list and not a map. |
| + typedef std::list<GalleryPermission> NewGalleryPermissions; |
|
vandebo (ex-Chrome)
2012/08/08 19:24:21
above destructor
Evan Stade
2012/08/08 21:48:57
Done.
|
| + |
| + // The tab contents from which the request originated. |
| + TabContents* tab_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_; |
| + |
| + // This map excludes those galleries which have been blacklisted; it only |
| + // counts active known galleries. |
| + KnownGalleryPermissions known_galleries_; |
| + NewGalleryPermissions new_galleries_; |
| + |
| + // We notify this delegate when done. |
| + MediaGalleriesDialogDelegate* delegate_; |
| + |
| + // The model that tracks galleries and extensions' permissions. |
| + MediaGalleriesPreferences* preferences_; |
| + |
| + // The view that's showing. |
| + scoped_ptr<MediaGalleriesDialog> dialog_; |
| + |
| + scoped_refptr<ui::SelectFileDialog> select_folder_dialog_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogController); |
| +}; |
| + |
| +} // namespace chrome |
| + |
| +#endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ |