| 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_CONTROLLER_H_ | |
| 6 #define CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_SCAN_RESULT_CONTROLLER_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <set> | |
| 12 #include <string> | |
| 13 | |
| 14 #include "base/callback.h" | |
| 15 #include "base/macros.h" | |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/strings/string16.h" | |
| 18 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" | |
| 19 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | |
| 20 #include "components/storage_monitor/removable_storage_observer.h" | |
| 21 | |
| 22 namespace content { | |
| 23 class WebContents; | |
| 24 } | |
| 25 | |
| 26 namespace extensions { | |
| 27 class Extension; | |
| 28 } | |
| 29 | |
| 30 namespace ui { | |
| 31 class MenuModel; | |
| 32 } | |
| 33 | |
| 34 class MediaGalleriesScanResultController; | |
| 35 class MediaGalleryContextMenu; | |
| 36 class Profile; | |
| 37 | |
| 38 // The controller is responsible for handling the logic of the dialog and | |
| 39 // interfacing with the model (i.e., MediaGalleriesPreferences). It shows | |
| 40 // the dialog and owns itself. | |
| 41 class MediaGalleriesScanResultController | |
| 42 : public MediaGalleriesDialogController, | |
| 43 public storage_monitor::RemovableStorageObserver, | |
| 44 public MediaGalleriesPreferences::GalleryChangeObserver { | |
| 45 public: | |
| 46 // |preferences| must be already initialized. | |
| 47 static size_t ScanResultCountForExtension( | |
| 48 MediaGalleriesPreferences* preferences, | |
| 49 const extensions::Extension* extension); | |
| 50 | |
| 51 // The constructor creates a dialog controller which owns itself. | |
| 52 MediaGalleriesScanResultController( | |
| 53 content::WebContents* web_contents, | |
| 54 const extensions::Extension& extension, | |
| 55 const base::Closure& on_finish); | |
| 56 | |
| 57 // MediaGalleriesDialogController implementation. | |
| 58 base::string16 GetHeader() const override; | |
| 59 base::string16 GetSubtext() const override; | |
| 60 bool IsAcceptAllowed() const override; | |
| 61 bool ShouldShowFolderViewer(const Entry& entry) const override; | |
| 62 std::vector<base::string16> GetSectionHeaders() const override; | |
| 63 Entries GetSectionEntries(size_t index) const override; | |
| 64 base::string16 GetAuxiliaryButtonText() const override; | |
| 65 void DidClickAuxiliaryButton() override; | |
| 66 void DidToggleEntry(MediaGalleryPrefId id, bool selected) override; | |
| 67 void DidClickOpenFolderViewer(MediaGalleryPrefId id) override; | |
| 68 void DidForgetEntry(MediaGalleryPrefId id) override; | |
| 69 base::string16 GetAcceptButtonText() const override; | |
| 70 void DialogFinished(bool accepted) override; | |
| 71 ui::MenuModel* GetContextMenu(MediaGalleryPrefId id) override; | |
| 72 content::WebContents* WebContents() override; | |
| 73 | |
| 74 protected: | |
| 75 typedef base::Callback<MediaGalleriesDialog* ( | |
| 76 MediaGalleriesDialogController*)> CreateDialogCallback; | |
| 77 typedef std::map<MediaGalleryPrefId, Entry> ScanResults; | |
| 78 | |
| 79 // Updates |scan_results| from |preferences|. Will not add galleries from | |
| 80 // |ignore_list| onto |scan_results|. | |
| 81 static void UpdateScanResultsFromPreferences( | |
| 82 MediaGalleriesPreferences* preferences, | |
| 83 const extensions::Extension* extension, | |
| 84 MediaGalleryPrefIdSet ignore_list, | |
| 85 ScanResults* scan_results); | |
| 86 | |
| 87 // Used for unit tests. | |
| 88 MediaGalleriesScanResultController( | |
| 89 const extensions::Extension& extension, | |
| 90 MediaGalleriesPreferences* preferences_, | |
| 91 const CreateDialogCallback& create_dialog_callback, | |
| 92 const base::Closure& on_finish); | |
| 93 | |
| 94 ~MediaGalleriesScanResultController() override; | |
| 95 | |
| 96 private: | |
| 97 friend class MediaGalleriesScanResultControllerTest; | |
| 98 friend class MediaGalleriesScanResultCocoaTest; | |
| 99 friend class TestMediaGalleriesAddScanResultsFunction; | |
| 100 | |
| 101 // Bottom half of constructor -- called when |preferences_| is initialized. | |
| 102 void OnPreferencesInitialized(); | |
| 103 | |
| 104 // Used to keep the dialog in sync with the preferences. | |
| 105 void OnPreferenceUpdate(const std::string& extension_id); | |
| 106 | |
| 107 // Used to keep the dialog in sync with attached and detached devices. | |
| 108 void OnRemovableDeviceUpdate(const std::string& device_id); | |
| 109 | |
| 110 Profile* GetProfile() const; | |
| 111 | |
| 112 // RemovableStorageObserver implementation. | |
| 113 // Used to keep dialog in sync with removable device status. | |
| 114 void OnRemovableStorageAttached( | |
| 115 const storage_monitor::StorageInfo& info) override; | |
| 116 void OnRemovableStorageDetached( | |
| 117 const storage_monitor::StorageInfo& info) override; | |
| 118 | |
| 119 // MediaGalleriesPreferences::GalleryChangeObserver implementations. | |
| 120 // Used to keep the dialog in sync when the preferences change. | |
| 121 void OnPermissionAdded(MediaGalleriesPreferences* pref, | |
| 122 const std::string& extension_id, | |
| 123 MediaGalleryPrefId pref_id) override; | |
| 124 void OnPermissionRemoved(MediaGalleriesPreferences* pref, | |
| 125 const std::string& extension_id, | |
| 126 MediaGalleryPrefId pref_id) override; | |
| 127 void OnGalleryAdded(MediaGalleriesPreferences* pref, | |
| 128 MediaGalleryPrefId pref_id) override; | |
| 129 void OnGalleryRemoved(MediaGalleriesPreferences* pref, | |
| 130 MediaGalleryPrefId pref_id) override; | |
| 131 void OnGalleryInfoUpdated(MediaGalleriesPreferences* pref, | |
| 132 MediaGalleryPrefId pref_id) override; | |
| 133 | |
| 134 // The web contents from which the request originated. | |
| 135 content::WebContents* web_contents_; | |
| 136 | |
| 137 // This is just a reference, but it's assumed that it won't become invalid | |
| 138 // while the dialog is showing. | |
| 139 const extensions::Extension* extension_; | |
| 140 | |
| 141 // The scan results that aren't blacklisted and this extension doesn't | |
| 142 // already have access to. | |
| 143 ScanResults scan_results_; | |
| 144 | |
| 145 // The set of scan results which should be removed (blacklisted) - unless | |
| 146 // the user clicks Cancel. | |
| 147 MediaGalleryPrefIdSet results_to_remove_; | |
| 148 | |
| 149 // Callback to run when the dialog closes. | |
| 150 base::Closure on_finish_; | |
| 151 | |
| 152 // The model that tracks galleries and extensions' permissions. | |
| 153 // This is the authoritative source for gallery information. | |
| 154 MediaGalleriesPreferences* preferences_; | |
| 155 | |
| 156 // Creates the dialog. Only changed for unit tests. | |
| 157 CreateDialogCallback create_dialog_callback_; | |
| 158 | |
| 159 // The view that's showing. | |
| 160 scoped_ptr<MediaGalleriesDialog> dialog_; | |
| 161 | |
| 162 scoped_ptr<MediaGalleryContextMenu> context_menu_; | |
| 163 | |
| 164 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesScanResultController); | |
| 165 }; | |
| 166 | |
| 167 #endif // CHROME_BROWSER_MEDIA_GALLERIES_MEDIA_GALLERIES_SCAN_RESULT_CONTROLLER
_H_ | |
| OLD | NEW |