OLD | NEW |
| (Empty) |
1 // Copyright 2014 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_GALLERIES_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_CONTRO
LLER_H_ | |
6 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_CONTRO
LLER_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <string> | |
11 | |
12 #include "base/callback.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/strings/string16.h" | |
15 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | |
16 #include "components/storage_monitor/removable_storage_observer.h" | |
17 | |
18 namespace content { | |
19 class WebContents; | |
20 } | |
21 | |
22 namespace extensions { | |
23 class Extension; | |
24 } | |
25 | |
26 namespace ui { | |
27 class MenuModel; | |
28 } | |
29 | |
30 class MediaGalleriesScanResultDialogController; | |
31 class MediaGalleryContextMenu; | |
32 class Profile; | |
33 | |
34 // The view. | |
35 class MediaGalleriesScanResultDialog { | |
36 public: | |
37 virtual ~MediaGalleriesScanResultDialog(); | |
38 | |
39 // Tell the dialog to update its display list of scan results. | |
40 virtual void UpdateResults() = 0; | |
41 | |
42 // Constructs a platform-specific dialog owned and controlled by |controller|. | |
43 static MediaGalleriesScanResultDialog* Create( | |
44 MediaGalleriesScanResultDialogController* controller); | |
45 | |
46 private: | |
47 friend class TestMediaGalleriesAddScanResultsFunction; | |
48 | |
49 virtual void AcceptDialogForTesting() = 0; | |
50 }; | |
51 | |
52 // The controller is responsible for handling the logic of the dialog and | |
53 // interfacing with the model (i.e., MediaGalleriesPreferences). It shows | |
54 // the dialog and owns itself. | |
55 class MediaGalleriesScanResultDialogController | |
56 : public storage_monitor::RemovableStorageObserver, | |
57 public MediaGalleriesPreferences::GalleryChangeObserver { | |
58 public: | |
59 struct ScanResult { | |
60 ScanResult(const MediaGalleryPrefInfo& pref_info, bool selected) | |
61 : pref_info(pref_info), | |
62 selected(selected) { | |
63 } | |
64 ScanResult() : selected(false) {} | |
65 | |
66 MediaGalleryPrefInfo pref_info; | |
67 bool selected; | |
68 }; | |
69 typedef std::vector<ScanResult> OrderedScanResults; | |
70 | |
71 // |preferences| must be already initialized. | |
72 static size_t ScanResultCountForExtension( | |
73 MediaGalleriesPreferences* preferences, | |
74 const extensions::Extension* extension); | |
75 | |
76 // The constructor creates a dialog controller which owns itself. | |
77 MediaGalleriesScanResultDialogController( | |
78 content::WebContents* web_contents, | |
79 const extensions::Extension& extension, | |
80 const base::Closure& on_finish); | |
81 | |
82 // The title of the dialog view. | |
83 base::string16 GetHeader() const; | |
84 | |
85 // Explanatory text directly below the title. | |
86 base::string16 GetSubtext() const; | |
87 | |
88 // Get the scan results and their current selection state. | |
89 virtual OrderedScanResults GetGalleryList() const; | |
90 | |
91 // A checkbox beside a scan result was toggled. | |
92 virtual void DidToggleGalleryId(MediaGalleryPrefId pref_id, bool selected); | |
93 | |
94 // A folder viewer icon was clicked. | |
95 virtual void DidClickOpenFolderViewer(MediaGalleryPrefId pref_id) const; | |
96 | |
97 // The forget command in the context menu was selected. | |
98 virtual void DidForgetGallery(MediaGalleryPrefId pref_id); | |
99 | |
100 // The dialog is being deleted. | |
101 virtual void DialogFinished(bool accepted); | |
102 | |
103 virtual content::WebContents* web_contents(); | |
104 | |
105 ui::MenuModel* GetContextMenu(MediaGalleryPrefId id); | |
106 | |
107 protected: | |
108 typedef base::Callback<MediaGalleriesScanResultDialog* ( | |
109 MediaGalleriesScanResultDialogController*)> CreateDialogCallback; | |
110 typedef std::map<MediaGalleryPrefId, ScanResult> ScanResults; | |
111 | |
112 // Updates |scan_results| from |preferences|. Will not add galleries from | |
113 // |ignore_list| onto |scan_results|. | |
114 static void UpdateScanResultsFromPreferences( | |
115 MediaGalleriesPreferences* preferences, | |
116 const extensions::Extension* extension, | |
117 MediaGalleryPrefIdSet ignore_list, | |
118 ScanResults* scan_results); | |
119 | |
120 // Used for unit tests. | |
121 MediaGalleriesScanResultDialogController( | |
122 const extensions::Extension& extension, | |
123 MediaGalleriesPreferences* preferences_, | |
124 const CreateDialogCallback& create_dialog_callback, | |
125 const base::Closure& on_finish); | |
126 | |
127 virtual ~MediaGalleriesScanResultDialogController(); | |
128 | |
129 private: | |
130 friend class MediaGalleriesScanResultDialogControllerTest; | |
131 friend class MediaGalleriesScanResultDialogCocoaTest; | |
132 friend class TestMediaGalleriesAddScanResultsFunction; | |
133 | |
134 // Bottom half of constructor -- called when |preferences_| is initialized. | |
135 void OnPreferencesInitialized(); | |
136 | |
137 // Used to keep the dialog in sync with the preferences. | |
138 void OnPreferenceUpdate(const std::string& extension_id); | |
139 | |
140 // Used to keep the dialog in sync with attached and detached devices. | |
141 void OnRemovableDeviceUpdate(const std::string device_id); | |
142 | |
143 Profile* GetProfile() const; | |
144 | |
145 // RemovableStorageObserver implementation. | |
146 // Used to keep dialog in sync with removable device status. | |
147 virtual void OnRemovableStorageAttached( | |
148 const storage_monitor::StorageInfo& info) OVERRIDE; | |
149 virtual void OnRemovableStorageDetached( | |
150 const storage_monitor::StorageInfo& info) OVERRIDE; | |
151 | |
152 // MediaGalleriesPreferences::GalleryChangeObserver implementations. | |
153 // Used to keep the dialog in sync when the preferences change. | |
154 virtual void OnPermissionAdded(MediaGalleriesPreferences* pref, | |
155 const std::string& extension_id, | |
156 MediaGalleryPrefId pref_id) OVERRIDE; | |
157 virtual void OnPermissionRemoved(MediaGalleriesPreferences* pref, | |
158 const std::string& extension_id, | |
159 MediaGalleryPrefId pref_id) OVERRIDE; | |
160 virtual void OnGalleryAdded(MediaGalleriesPreferences* pref, | |
161 MediaGalleryPrefId pref_id) OVERRIDE; | |
162 virtual void OnGalleryRemoved(MediaGalleriesPreferences* pref, | |
163 MediaGalleryPrefId pref_id) OVERRIDE; | |
164 virtual void OnGalleryInfoUpdated(MediaGalleriesPreferences* pref, | |
165 MediaGalleryPrefId pref_id) OVERRIDE; | |
166 | |
167 // The web contents from which the request originated. | |
168 content::WebContents* web_contents_; | |
169 | |
170 // This is just a reference, but it's assumed that it won't become invalid | |
171 // while the dialog is showing. | |
172 const extensions::Extension* extension_; | |
173 | |
174 // The scan results that aren't blacklisted and this extension doesn't | |
175 // already have access to. | |
176 ScanResults scan_results_; | |
177 | |
178 // The set of scan results which should be removed (blacklisted) - unless | |
179 // the user clicks Cancel. | |
180 MediaGalleryPrefIdSet results_to_remove_; | |
181 | |
182 // Callback to run when the dialog closes. | |
183 base::Closure on_finish_; | |
184 | |
185 // The model that tracks galleries and extensions' permissions. | |
186 // This is the authoritative source for gallery information. | |
187 MediaGalleriesPreferences* preferences_; | |
188 | |
189 // Creates the dialog. Only changed for unit tests. | |
190 CreateDialogCallback create_dialog_callback_; | |
191 | |
192 // The view that's showing. | |
193 scoped_ptr<MediaGalleriesScanResultDialog> dialog_; | |
194 | |
195 scoped_ptr<MediaGalleryContextMenu> context_menu_; | |
196 | |
197 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesScanResultDialogController); | |
198 }; | |
199 | |
200 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_CON
TROLLER_H_ | |
OLD | NEW |