| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 namespace chrome { | 27 namespace chrome { |
| 28 | 28 |
| 29 class MediaGalleriesDialogController; | 29 class MediaGalleriesDialogController; |
| 30 | 30 |
| 31 // The view. | 31 // The view. |
| 32 class MediaGalleriesDialog { | 32 class MediaGalleriesDialog { |
| 33 public: | 33 public: |
| 34 virtual ~MediaGalleriesDialog(); | 34 virtual ~MediaGalleriesDialog(); |
| 35 | 35 |
| 36 // Updates the checkbox state for |gallery|. |gallery| is owned by the | 36 // Updates the entry for |gallery| with the checkbox set to the value in |
| 37 // controller and is guaranteed to live longer than the dialog. If the | 37 // |permitted|. |gallery| is owned by the controller and is guaranteed to |
| 38 // checkbox doesn't already exist, it should be created. | 38 // live longer than the dialog. If the entry does not already exist, it |
| 39 // should be created. |
| 39 virtual void UpdateGallery(const MediaGalleryPrefInfo* gallery, | 40 virtual void UpdateGallery(const MediaGalleryPrefInfo* gallery, |
| 40 bool permitted) = 0; | 41 bool permitted) = 0; |
| 41 | 42 |
| 43 // If there exists an entry for |gallery|, it should be removed. |
| 44 virtual void ForgetGallery(const MediaGalleryPrefInfo* gallery) = 0; |
| 45 |
| 42 // Constructs a platform-specific dialog owned and controlled by |controller|. | 46 // Constructs a platform-specific dialog owned and controlled by |controller|. |
| 43 static MediaGalleriesDialog* Create( | 47 static MediaGalleriesDialog* Create( |
| 44 MediaGalleriesDialogController* controller); | 48 MediaGalleriesDialogController* controller); |
| 45 }; | 49 }; |
| 46 | 50 |
| 47 // The controller is responsible for handling the logic of the dialog and | 51 // The controller is responsible for handling the logic of the dialog and |
| 48 // interfacing with the model (i.e., MediaGalleriesPreferences). It shows | 52 // interfacing with the model (i.e., MediaGalleriesPreferences). It shows |
| 49 // the dialog and owns itself. | 53 // the dialog and owns itself. |
| 50 class MediaGalleriesDialogController | 54 class MediaGalleriesDialogController |
| 51 : public ui::SelectFileDialog::Listener, | 55 : public ui::SelectFileDialog::Listener, |
| 52 public RemovableStorageObserver { | 56 public RemovableStorageObserver, |
| 57 public MediaGalleriesPreferences::GalleryChangeObserver { |
| 53 public: | 58 public: |
| 54 // A fancy pair. | 59 // A fancy pair. |
| 55 struct GalleryPermission { | 60 struct GalleryPermission { |
| 56 GalleryPermission(const MediaGalleryPrefInfo& pref_info, bool allowed) | 61 GalleryPermission(const MediaGalleryPrefInfo& pref_info, bool allowed) |
| 57 : pref_info(pref_info), allowed(allowed) {} | 62 : pref_info(pref_info), allowed(allowed) {} |
| 58 GalleryPermission() {} | 63 GalleryPermission() {} |
| 59 | 64 |
| 60 MediaGalleryPrefInfo pref_info; | 65 MediaGalleryPrefInfo pref_info; |
| 61 bool allowed; | 66 bool allowed; |
| 62 }; | 67 }; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // button, but have not yet been committed to the prefs system and will be | 99 // button, but have not yet been committed to the prefs system and will be |
| 95 // forgotten if the user Cancels. Since they don't have IDs assigned yet, it's | 100 // forgotten if the user Cancels. Since they don't have IDs assigned yet, it's |
| 96 // just a list and not a map. | 101 // just a list and not a map. |
| 97 typedef std::list<GalleryPermission> NewGalleryPermissions; | 102 typedef std::list<GalleryPermission> NewGalleryPermissions; |
| 98 | 103 |
| 99 // SelectFileDialog::Listener implementation: | 104 // SelectFileDialog::Listener implementation: |
| 100 virtual void FileSelected(const base::FilePath& path, | 105 virtual void FileSelected(const base::FilePath& path, |
| 101 int index, | 106 int index, |
| 102 void* params) OVERRIDE; | 107 void* params) OVERRIDE; |
| 103 | 108 |
| 104 // RemovableStorageObserver implementation: | 109 // RemovableStorageObserver implementation. |
| 110 // Used to keep dialog in sync with removable device status. |
| 105 virtual void OnRemovableStorageAttached( | 111 virtual void OnRemovableStorageAttached( |
| 106 const RemovableStorageNotifications::StorageInfo& info) OVERRIDE; | 112 const RemovableStorageNotifications::StorageInfo& info) OVERRIDE; |
| 107 virtual void OnRemovableStorageDetached( | 113 virtual void OnRemovableStorageDetached( |
| 108 const RemovableStorageNotifications::StorageInfo& info) OVERRIDE; | 114 const RemovableStorageNotifications::StorageInfo& info) OVERRIDE; |
| 109 | 115 |
| 110 // Populates |known_galleries_|. | 116 // MediaGalleriesPreferences::GalleryChangeObserver implementation. |
| 117 // Used to keep the dialog in sync when the preferences change. |
| 118 virtual void OnGalleryChanged(MediaGalleriesPreferences* pref, |
| 119 const std::string& extension_id) OVERRIDE; |
| 120 |
| 121 // Populates |known_galleries_| from |preferences_|. Subsequent calls merge |
| 122 // into |known_galleries_| and do not change permissions for user toggled |
| 123 // galleries. |
| 111 void InitializePermissions(); | 124 void InitializePermissions(); |
| 112 | 125 |
| 113 // Saves state of |known_galleries_| and |new_galleries_| to model. | 126 // Saves state of |known_galleries_| and |new_galleries_| to model. |
| 114 void SavePermissions(); | 127 void SavePermissions(); |
| 115 | 128 |
| 116 // Update the model and view when a device is attached or detached. | 129 // Updates the model and view when |preferences_| changes. Some of the |
| 130 // possible changes includes a gallery getting blacklisted, or a new |
| 131 // auto detected gallery becoming available. |
| 132 void UpdateGalleriesOnPreferencesEvent(); |
| 133 |
| 134 // Updates the model and view when a device is attached or detached. |
| 117 void UpdateGalleriesOnDeviceEvent(const std::string& device_id); | 135 void UpdateGalleriesOnDeviceEvent(const std::string& device_id); |
| 118 | 136 |
| 119 // The web contents from which the request originated. | 137 // The web contents from which the request originated. |
| 120 content::WebContents* web_contents_; | 138 content::WebContents* web_contents_; |
| 121 | 139 |
| 122 // This is just a reference, but it's assumed that it won't become invalid | 140 // This is just a reference, but it's assumed that it won't become invalid |
| 123 // while the dialog is showing. Will be NULL only during tests. | 141 // while the dialog is showing. Will be NULL only during tests. |
| 124 const extensions::Extension* extension_; | 142 const extensions::Extension* extension_; |
| 125 | 143 |
| 126 // This map excludes those galleries which have been blacklisted; it only | 144 // This map excludes those galleries which have been blacklisted; it only |
| 127 // counts active known galleries. | 145 // counts active known galleries. |
| 128 KnownGalleryPermissions known_galleries_; | 146 KnownGalleryPermissions known_galleries_; |
| 147 |
| 148 // Galleries in |known_galleries_| that the user have toggled. |
| 149 MediaGalleryPrefIdSet toggled_galleries_; |
| 150 |
| 151 // Map of new galleries the user added, but have not saved. This list should |
| 152 // never overlap with |known_galleries_|. |
| 129 NewGalleryPermissions new_galleries_; | 153 NewGalleryPermissions new_galleries_; |
| 130 | 154 |
| 131 // We run this callback when done. | 155 // Callback to run when the dialog closes. |
| 132 base::Closure on_finish_; | 156 base::Closure on_finish_; |
| 133 | 157 |
| 134 // The model that tracks galleries and extensions' permissions. | 158 // The model that tracks galleries and extensions' permissions. |
| 159 // This is the authoritative source for gallery information. |
| 135 MediaGalleriesPreferences* preferences_; | 160 MediaGalleriesPreferences* preferences_; |
| 136 | 161 |
| 137 // The view that's showing. | 162 // The view that's showing. |
| 138 scoped_ptr<MediaGalleriesDialog> dialog_; | 163 scoped_ptr<MediaGalleriesDialog> dialog_; |
| 139 | 164 |
| 140 scoped_refptr<ui::SelectFileDialog> select_folder_dialog_; | 165 scoped_refptr<ui::SelectFileDialog> select_folder_dialog_; |
| 141 | 166 |
| 142 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogController); | 167 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogController); |
| 143 }; | 168 }; |
| 144 | 169 |
| 145 } // namespace chrome | 170 } // namespace chrome |
| 146 | 171 |
| 147 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ | 172 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ |
| OLD | NEW |