Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ | |
| 6 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 #include <map> | |
| 10 | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/string16.h" | |
| 13 #include "chrome/browser/media_gallery/media_galleries_preferences.h" | |
| 14 #include "ui/base/dialogs/select_file_dialog.h" | |
| 15 #include "ui/gfx/native_widget_types.h" | |
| 16 | |
| 17 namespace extensions { | |
| 18 struct Extension; | |
| 19 } | |
| 20 | |
| 21 class TabContents; | |
| 22 | |
| 23 namespace chrome { | |
| 24 | |
| 25 class MediaGalleriesDialogController; | |
| 26 | |
| 27 // The view. | |
| 28 class MediaGalleriesDialog { | |
| 29 public: | |
| 30 // Updates the checkbox state for |gallery|. |gallery| is owned by the | |
| 31 // controller and is guaranteed to live longer than the dialog. If the | |
| 32 // checkbox doesn't already exist, it should be created. | |
| 33 virtual void UpdateGallery(const MediaGalleryPrefInfo* gallery, | |
|
vandebo (ex-Chrome)
2012/08/06 20:39:30
const ref?
Evan Stade
2012/08/06 23:43:02
the memory address is being used to identify the g
| |
| 34 bool permitted) = 0; | |
| 35 | |
| 36 // Constructs a platform-specific dialog owned and controlled by |controller|. | |
| 37 static MediaGalleriesDialog* Create( | |
| 38 MediaGalleriesDialogController* controller); | |
| 39 }; | |
| 40 | |
| 41 // An interface that notifies the caller when the user has finished interacting | |
| 42 // with the dialog. | |
| 43 class MediaGalleriesDialogDelegate { | |
| 44 public: | |
| 45 // Called when the dialog has been dismissed. | |
| 46 virtual void MediaGalleriesDialogFinished() = 0; | |
| 47 }; | |
| 48 | |
| 49 // The controller is responsible for handling the logic of the dialog and | |
| 50 // interfacing with the model (i.e., MediaGalleriesPreferences). It shows | |
| 51 // the dialog and owns itself. | |
| 52 class MediaGalleriesDialogController : public ui::SelectFileDialog::Listener { | |
| 53 public: | |
| 54 // The constructor creates a dialog controller which owns itself. | |
| 55 MediaGalleriesDialogController(TabContents* tab_contents, | |
| 56 const extensions::Extension* extension, | |
|
vandebo (ex-Chrome)
2012/08/06 20:39:30
const ref?
Evan Stade
2012/08/06 23:43:02
extensions are traditionally passed around by poin
| |
| 57 MediaGalleriesDialogDelegate* delegate); | |
| 58 | |
| 59 // Called by the view. | |
| 60 string16 GetHeader(); | |
| 61 string16 GetSubtext(); | |
| 62 void OnAddFolderClicked(); | |
| 63 void GalleryToggled(const MediaGalleryPrefInfo*, bool enabled); | |
| 64 void DialogFinished(bool accepted); | |
| 65 | |
| 66 // SelectFileDialog::Listener implementation: | |
| 67 virtual void FileSelected(const FilePath& path, | |
| 68 int index, | |
| 69 void* params) OVERRIDE; | |
| 70 | |
| 71 // This type keeps track of media galleries already known to the prefs system. | |
| 72 typedef std::map<MediaGalleryPrefId, std::pair<MediaGalleryPrefInfo, bool> > | |
|
vandebo (ex-Chrome)
2012/08/06 20:39:30
Any advantage to using a pair instead of an explic
Evan Stade
2012/08/06 23:43:02
Done.
| |
| 73 KnownGalleryPermissions; | |
| 74 const KnownGalleryPermissions& permissions() const { | |
| 75 return known_galleries_; | |
| 76 } | |
| 77 | |
| 78 TabContents* tab_contents() const { | |
| 79 return tab_contents_; | |
| 80 } | |
| 81 | |
| 82 private: | |
| 83 virtual ~MediaGalleriesDialogController(); | |
| 84 | |
| 85 // Populates |known_galleries_|. | |
| 86 void LookUpPermissions(); | |
| 87 | |
| 88 // Saves state of |known_galleries_| and |new_galleries_| to model. | |
| 89 void SavePermissions(); | |
| 90 | |
| 91 // This type is for media galleries that have been added via "add gallery" | |
| 92 // button, but have not yet been committed to the prefs system and will be | |
| 93 // forgotten if the user Cancels. Since they don't have IDs assigned yet, it's | |
| 94 // just a list and not a map. | |
| 95 typedef std::list<std::pair<MediaGalleryPrefInfo, bool> > | |
|
vandebo (ex-Chrome)
2012/08/06 20:39:30
The struct mentioned above can be reused here.
Any
Evan Stade
2012/08/06 23:43:02
don't need random access; desire cheap append
| |
| 96 NewGalleryPermissions; | |
| 97 | |
| 98 // The tab contents from which the request originated. | |
| 99 TabContents* tab_contents_; | |
| 100 | |
| 101 // This is just a reference, but it's assumed that it won't become invalid | |
| 102 // while the dialog is showing. | |
| 103 const extensions::Extension* extension_; | |
|
vandebo (ex-Chrome)
2012/08/06 20:39:30
Why not actually make it const ref?
Evan Stade
2012/08/06 23:43:02
see above
| |
| 104 | |
| 105 KnownGalleryPermissions known_galleries_; | |
| 106 NewGalleryPermissions new_galleries_; | |
| 107 | |
| 108 // We notify this delegate when done. | |
| 109 MediaGalleriesDialogDelegate* delegate_; | |
| 110 | |
| 111 // The model that tracks galleries and extensions' permissions. | |
| 112 MediaGalleriesPreferences* preferences_; | |
| 113 | |
| 114 // The view that's showing. | |
| 115 scoped_ptr<MediaGalleriesDialog> dialog_; | |
| 116 | |
| 117 scoped_refptr<ui::SelectFileDialog> select_folder_dialog_; | |
| 118 | |
| 119 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogController); | |
| 120 }; | |
| 121 | |
| 122 } // namespace chrome | |
| 123 | |
| 124 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ | |
| OLD | NEW |