Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(519)

Side by Side Diff: chrome/browser/media_gallery/media_galleries_dialog_controller.h

Issue 12095074: Media Galleries: Keep media gallery permission dialogs in sync with the gallery (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: remember user toggles Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 FilePath& path, 105 virtual void FileSelected(const 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
116 // MediaGalleriesPreferences::GalleryChangeObserver implementation.
117 // Used to keep the dialog in sync when the preferences change.
118 virtual void OnGalleryChanged(MediaGalleriesPreferences* pref) OVERRIDE;
119
110 // Populates |known_galleries_|. 120 // Populates |known_galleries_|.
111 void InitializePermissions(); 121 void InitializePermissions();
112 122
113 // Saves state of |known_galleries_| and |new_galleries_| to model. 123 // Saves state of |known_galleries_| and |new_galleries_| to model.
114 void SavePermissions(); 124 void SavePermissions();
115 125
116 // Update the model and view when a device is attached or detached. 126 // Updates the model and view when |preferences_| changes. Some of the
127 // possible changes includes a gallery getting blacklisted, or a new
128 // auto detected gallery becoming available.
129 void UpdateGalleriesOnPreferencesEvent();
130
131 // Updates the model and view when a device is attached or detached.
117 void UpdateGalleriesOnDeviceEvent(const std::string& device_id); 132 void UpdateGalleriesOnDeviceEvent(const std::string& device_id);
118 133
119 // The web contents from which the request originated. 134 // The web contents from which the request originated.
120 content::WebContents* web_contents_; 135 content::WebContents* web_contents_;
121 136
122 // This is just a reference, but it's assumed that it won't become invalid 137 // 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. 138 // while the dialog is showing. Will be NULL only during tests.
124 const extensions::Extension* extension_; 139 const extensions::Extension* extension_;
125 140
126 // This map excludes those galleries which have been blacklisted; it only 141 // This map excludes those galleries which have been blacklisted; it only
127 // counts active known galleries. 142 // counts active known galleries.
128 KnownGalleryPermissions known_galleries_; 143 KnownGalleryPermissions known_galleries_;
144
145 // Galleries in |known_galleries_| that the user have toggled.
146 MediaGalleryPrefIdSet toggled_galleries_;
147
148 // Map of new galleries the user added, but have not saved. This list should
149 // never overlap with |known_galleries_|.
129 NewGalleryPermissions new_galleries_; 150 NewGalleryPermissions new_galleries_;
130 151
131 // We run this callback when done. 152 // Callback to run when the dialog closes.
132 base::Closure on_finish_; 153 base::Closure on_finish_;
133 154
134 // The model that tracks galleries and extensions' permissions. 155 // The model that tracks galleries and extensions' permissions.
156 // This is the authoritative source for gallery information.
135 MediaGalleriesPreferences* preferences_; 157 MediaGalleriesPreferences* preferences_;
136 158
137 // The view that's showing. 159 // The view that's showing.
138 scoped_ptr<MediaGalleriesDialog> dialog_; 160 scoped_ptr<MediaGalleriesDialog> dialog_;
139 161
140 scoped_refptr<ui::SelectFileDialog> select_folder_dialog_; 162 scoped_refptr<ui::SelectFileDialog> select_folder_dialog_;
141 163
142 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogController); 164 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesDialogController);
143 }; 165 };
144 166
145 } // namespace chrome 167 } // namespace chrome
146 168
147 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_ 169 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERIES_DIALOG_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698