| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_GALLERIES_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_CONTRO
LLER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_SCAN_RESULT_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_CONTRO
LLER_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_SCAN_RESULT_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" |
| 15 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | 16 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
| 16 #include "components/storage_monitor/removable_storage_observer.h" | 17 #include "components/storage_monitor/removable_storage_observer.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 class WebContents; | 20 class WebContents; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace extensions { | 23 namespace extensions { |
| 23 class Extension; | 24 class Extension; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace ui { | 27 namespace ui { |
| 27 class MenuModel; | 28 class MenuModel; |
| 28 } | 29 } |
| 29 | 30 |
| 30 class MediaGalleriesScanResultDialogController; | 31 class MediaGalleriesScanResultController; |
| 31 class MediaGalleryContextMenu; | 32 class MediaGalleryContextMenu; |
| 32 class Profile; | 33 class Profile; |
| 33 | 34 |
| 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 | 35 // The controller is responsible for handling the logic of the dialog and |
| 53 // interfacing with the model (i.e., MediaGalleriesPreferences). It shows | 36 // interfacing with the model (i.e., MediaGalleriesPreferences). It shows |
| 54 // the dialog and owns itself. | 37 // the dialog and owns itself. |
| 55 class MediaGalleriesScanResultDialogController | 38 class MediaGalleriesScanResultController |
| 56 : public storage_monitor::RemovableStorageObserver, | 39 : public MediaGalleriesDialogController, |
| 40 public storage_monitor::RemovableStorageObserver, |
| 57 public MediaGalleriesPreferences::GalleryChangeObserver { | 41 public MediaGalleriesPreferences::GalleryChangeObserver { |
| 58 public: | 42 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. | 43 // |preferences| must be already initialized. |
| 72 static size_t ScanResultCountForExtension( | 44 static size_t ScanResultCountForExtension( |
| 73 MediaGalleriesPreferences* preferences, | 45 MediaGalleriesPreferences* preferences, |
| 74 const extensions::Extension* extension); | 46 const extensions::Extension* extension); |
| 75 | 47 |
| 76 // The constructor creates a dialog controller which owns itself. | 48 // The constructor creates a dialog controller which owns itself. |
| 77 MediaGalleriesScanResultDialogController( | 49 MediaGalleriesScanResultController( |
| 78 content::WebContents* web_contents, | 50 content::WebContents* web_contents, |
| 79 const extensions::Extension& extension, | 51 const extensions::Extension& extension, |
| 80 const base::Closure& on_finish); | 52 const base::Closure& on_finish); |
| 81 | 53 |
| 82 // The title of the dialog view. | 54 // MediaGalleriesDialogController implementation. |
| 83 base::string16 GetHeader() const; | 55 virtual base::string16 GetHeader() const OVERRIDE; |
| 84 | 56 virtual base::string16 GetSubtext() const OVERRIDE; |
| 85 // Explanatory text directly below the title. | 57 virtual bool IsAcceptAllowed() const OVERRIDE; |
| 86 base::string16 GetSubtext() const; | 58 virtual bool ShouldShowFolderViewer(const Entry& entry) const OVERRIDE; |
| 87 | 59 virtual std::vector<base::string16> GetSectionHeaders() const OVERRIDE; |
| 88 // Get the scan results and their current selection state. | 60 virtual Entries GetSectionEntries(size_t index) const OVERRIDE; |
| 89 virtual OrderedScanResults GetGalleryList() const; | 61 virtual base::string16 GetAuxiliaryButtonText() const OVERRIDE; |
| 90 | 62 virtual void DidClickAuxiliaryButton() OVERRIDE; |
| 91 // A checkbox beside a scan result was toggled. | 63 virtual void DidToggleEntry(MediaGalleryPrefId id, bool selected) OVERRIDE; |
| 92 virtual void DidToggleGalleryId(MediaGalleryPrefId pref_id, bool selected); | 64 virtual void DidClickOpenFolderViewer(MediaGalleryPrefId id) OVERRIDE; |
| 93 | 65 virtual void DidForgetEntry(MediaGalleryPrefId id) OVERRIDE; |
| 94 // A folder viewer icon was clicked. | 66 virtual base::string16 GetAcceptButtonText() const OVERRIDE; |
| 95 virtual void DidClickOpenFolderViewer(MediaGalleryPrefId pref_id) const; | 67 virtual void DialogFinished(bool accepted) OVERRIDE; |
| 96 | 68 virtual ui::MenuModel* GetContextMenu(MediaGalleryPrefId id) OVERRIDE; |
| 97 // The forget command in the context menu was selected. | 69 virtual content::WebContents* WebContents() OVERRIDE; |
| 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 | 70 |
| 107 protected: | 71 protected: |
| 108 typedef base::Callback<MediaGalleriesScanResultDialog* ( | 72 typedef base::Callback<MediaGalleriesDialog* ( |
| 109 MediaGalleriesScanResultDialogController*)> CreateDialogCallback; | 73 MediaGalleriesDialogController*)> CreateDialogCallback; |
| 110 typedef std::map<MediaGalleryPrefId, ScanResult> ScanResults; | 74 typedef std::map<MediaGalleryPrefId, Entry> ScanResults; |
| 111 | 75 |
| 112 // Updates |scan_results| from |preferences|. Will not add galleries from | 76 // Updates |scan_results| from |preferences|. Will not add galleries from |
| 113 // |ignore_list| onto |scan_results|. | 77 // |ignore_list| onto |scan_results|. |
| 114 static void UpdateScanResultsFromPreferences( | 78 static void UpdateScanResultsFromPreferences( |
| 115 MediaGalleriesPreferences* preferences, | 79 MediaGalleriesPreferences* preferences, |
| 116 const extensions::Extension* extension, | 80 const extensions::Extension* extension, |
| 117 MediaGalleryPrefIdSet ignore_list, | 81 MediaGalleryPrefIdSet ignore_list, |
| 118 ScanResults* scan_results); | 82 ScanResults* scan_results); |
| 119 | 83 |
| 120 // Used for unit tests. | 84 // Used for unit tests. |
| 121 MediaGalleriesScanResultDialogController( | 85 MediaGalleriesScanResultController( |
| 122 const extensions::Extension& extension, | 86 const extensions::Extension& extension, |
| 123 MediaGalleriesPreferences* preferences_, | 87 MediaGalleriesPreferences* preferences_, |
| 124 const CreateDialogCallback& create_dialog_callback, | 88 const CreateDialogCallback& create_dialog_callback, |
| 125 const base::Closure& on_finish); | 89 const base::Closure& on_finish); |
| 126 | 90 |
| 127 virtual ~MediaGalleriesScanResultDialogController(); | 91 virtual ~MediaGalleriesScanResultController(); |
| 128 | 92 |
| 129 private: | 93 private: |
| 130 friend class MediaGalleriesScanResultDialogControllerTest; | 94 friend class MediaGalleriesScanResultControllerTest; |
| 131 friend class MediaGalleriesScanResultDialogCocoaTest; | 95 friend class MediaGalleriesScanResultCocoaTest; |
| 132 friend class TestMediaGalleriesAddScanResultsFunction; | 96 friend class TestMediaGalleriesAddScanResultsFunction; |
| 133 | 97 |
| 134 // Bottom half of constructor -- called when |preferences_| is initialized. | 98 // Bottom half of constructor -- called when |preferences_| is initialized. |
| 135 void OnPreferencesInitialized(); | 99 void OnPreferencesInitialized(); |
| 136 | 100 |
| 137 // Used to keep the dialog in sync with the preferences. | 101 // Used to keep the dialog in sync with the preferences. |
| 138 void OnPreferenceUpdate(const std::string& extension_id); | 102 void OnPreferenceUpdate(const std::string& extension_id); |
| 139 | 103 |
| 140 // Used to keep the dialog in sync with attached and detached devices. | 104 // Used to keep the dialog in sync with attached and detached devices. |
| 141 void OnRemovableDeviceUpdate(const std::string device_id); | 105 void OnRemovableDeviceUpdate(const std::string device_id); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 base::Closure on_finish_; | 147 base::Closure on_finish_; |
| 184 | 148 |
| 185 // The model that tracks galleries and extensions' permissions. | 149 // The model that tracks galleries and extensions' permissions. |
| 186 // This is the authoritative source for gallery information. | 150 // This is the authoritative source for gallery information. |
| 187 MediaGalleriesPreferences* preferences_; | 151 MediaGalleriesPreferences* preferences_; |
| 188 | 152 |
| 189 // Creates the dialog. Only changed for unit tests. | 153 // Creates the dialog. Only changed for unit tests. |
| 190 CreateDialogCallback create_dialog_callback_; | 154 CreateDialogCallback create_dialog_callback_; |
| 191 | 155 |
| 192 // The view that's showing. | 156 // The view that's showing. |
| 193 scoped_ptr<MediaGalleriesScanResultDialog> dialog_; | 157 scoped_ptr<MediaGalleriesDialog> dialog_; |
| 194 | 158 |
| 195 scoped_ptr<MediaGalleryContextMenu> context_menu_; | 159 scoped_ptr<MediaGalleryContextMenu> context_menu_; |
| 196 | 160 |
| 197 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesScanResultDialogController); | 161 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesScanResultController); |
| 198 }; | 162 }; |
| 199 | 163 |
| 200 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_CON
TROLLER_H_ | 164 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_SCAN_RESULT_CONTROLLER
_H_ |
| OLD | NEW |