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

Side by Side Diff: chrome/browser/extensions/api/media_galleries/media_galleries_api.h

Issue 93643002: Media Galleries: Add chrome.mediaGalleries.addUserSelectedFolder(). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase Created 7 years 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 // Defines the Chrome Extensions Media Galleries API functions for accessing 5 // Defines the Chrome Extensions Media Galleries API functions for accessing
6 // user's media files, as specified in the extension API IDL. 6 // user's media files, as specified in the extension API IDL.
7 7
8 #ifndef CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ 8 #ifndef CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_
9 #define CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ 9 #define CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_
10 10
11 #include <vector> 11 #include <vector>
12 12
13 #include "chrome/browser/extensions/chrome_extension_function.h" 13 #include "chrome/browser/extensions/chrome_extension_function.h"
14 #include "chrome/browser/media_galleries/media_file_system_registry.h" 14 #include "chrome/browser/media_galleries/media_file_system_registry.h"
15 #include "chrome/browser/storage_monitor/media_storage_util.h" 15 #include "chrome/browser/storage_monitor/media_storage_util.h"
16 #include "chrome/common/extensions/api/media_galleries.h" 16 #include "chrome/common/extensions/api/media_galleries.h"
17 17
18 namespace MediaGalleries = extensions::api::media_galleries; 18 namespace MediaGalleries = extensions::api::media_galleries;
19 19
20 namespace base {
21 class FilePath;
22 }
23
20 namespace extensions { 24 namespace extensions {
21 25
26 // Common class for media gallery functions that create DOMFileSystems.
27 // Abstract due to the lack of a ChromeAsyncExtensionFunction::RunImpl()
28 // implementation.
29 class MediaGalleriesGetMediaFileSystemsBase
vandebo (ex-Chrome) 2013/12/18 20:15:53 nit: Maybe name this just GetMediaFileSystemsBase
Lei Zhang 2014/01/08 23:49:54 With the IDL changes, there's less of a need for a
30 : public ChromeAsyncExtensionFunction {
31 protected:
32 virtual ~MediaGalleriesGetMediaFileSystemsBase();
33
34 // Always show the dialog. Forces MediaFileSystemRegistry to read its
35 // preferences.
36 void ReadPrefsAndShowDialog();
vandebo (ex-Chrome) 2013/12/18 20:15:53 Is this needed? It looks like all callers may have
37
38 // Simply shows the configuration dialog to edit gallery preferences.
39 // Does not force MediaFileSystemRegistry to read its preferences.
vandebo (ex-Chrome) 2013/12/18 20:15:53 nit: Maybe change the code and comment to assert t
40 void ShowDialog();
41
42 // Grabs galleries from the media file system registry and passes them to
43 // |ReturnGalleries|.
44 void GetAndReturnGalleries();
45
46 // Returns galleries to the caller.
47 void ReturnGalleries(const std::vector<MediaFileSystemInfo>& filesystems);
48
49 // Take an array of MediaFileSystemInfo and turn it into a ListValue
50 // suitable for use with JS.
51 // Returns NULL on failure. Callers owns the returned value.
52 // The custom JS binding can use this list to create DOMFileSystem objects.
53 base::ListValue* ConstructFileSystemList(
54 const std::vector<MediaFileSystemInfo>& filesystems);
55
56 // A helper method that calls
57 // MediaFileSystemRegistry::GetMediaFileSystemsForExtension().
58 void GetMediaFileSystemsForExtension(const MediaFileSystemsCallback& cb);
59
60 // Helper function to get the appropriate WebContents.
61 content::WebContents* GetWebContents();
62
63 // Helper function to get the MediaGalleriesPreferences.
64 MediaGalleriesPreferences* GetMediaGalleriesPreferences();
65
66 private:
67 // Callback adaptor that just shows the dialog.
68 void AlwaysShowDialog(const std::vector<MediaFileSystemInfo>& filesystems);
vandebo (ex-Chrome) 2013/12/18 20:15:53 Having ReadPrefsAndShowDialog, ShowDialog, and Alw
69 };
70
22 class MediaGalleriesGetMediaFileSystemsFunction 71 class MediaGalleriesGetMediaFileSystemsFunction
23 : public ChromeAsyncExtensionFunction { 72 : public MediaGalleriesGetMediaFileSystemsBase {
24 public: 73 public:
25 DECLARE_EXTENSION_FUNCTION("mediaGalleries.getMediaFileSystems", 74 DECLARE_EXTENSION_FUNCTION("mediaGalleries.getMediaFileSystems",
26 MEDIAGALLERIES_GETMEDIAFILESYSTEMS) 75 MEDIAGALLERIES_GETMEDIAFILESYSTEMS)
27 76
28 protected: 77 protected:
29 virtual ~MediaGalleriesGetMediaFileSystemsFunction(); 78 virtual ~MediaGalleriesGetMediaFileSystemsFunction();
30 virtual bool RunImpl() OVERRIDE; 79 virtual bool RunImpl() OVERRIDE;
31 80
32 private: 81 private:
33 // Bottom half for RunImpl, invoked after the preferences is initialized. 82 // Bottom half for RunImpl, invoked after the preferences is initialized.
34 void OnPreferencesInit( 83 void OnPreferencesInit(
35 MediaGalleries::GetMediaFileSystemsInteractivity interactive); 84 MediaGalleries::GetMediaFileSystemsInteractivity interactive);
36 85
37 // Always show the dialog.
38 void AlwaysShowDialog(const std::vector<MediaFileSystemInfo>& filesystems);
39
40 // If no galleries are found, show the dialog, otherwise return them. 86 // If no galleries are found, show the dialog, otherwise return them.
41 void ShowDialogIfNoGalleries( 87 void ShowDialogIfNoGalleries(
42 const std::vector<MediaFileSystemInfo>& filesystems); 88 const std::vector<MediaFileSystemInfo>& filesystems);
43
44 // Grabs galleries from the media file system registry and passes them to
45 // |ReturnGalleries|.
46 void GetAndReturnGalleries();
47
48 // Returns galleries to the caller.
49 void ReturnGalleries(const std::vector<MediaFileSystemInfo>& filesystems);
50
51 // Shows the configuration dialog to edit gallery preferences.
52 void ShowDialog();
53
54 // A helper method that calls
55 // MediaFileSystemRegistry::GetMediaFileSystemsForExtension().
56 void GetMediaFileSystemsForExtension(const MediaFileSystemsCallback& cb);
57 }; 89 };
58 90
59 class MediaGalleriesGetAllMediaFileSystemMetadataFunction 91 class MediaGalleriesGetAllMediaFileSystemMetadataFunction
60 : public ChromeAsyncExtensionFunction { 92 : public ChromeAsyncExtensionFunction {
61 public: 93 public:
62 DECLARE_EXTENSION_FUNCTION("mediaGalleries.getAllMediaFileSystemMetadata", 94 DECLARE_EXTENSION_FUNCTION("mediaGalleries.getAllMediaFileSystemMetadata",
63 MEDIAGALLERIES_GETALLMEDIAFILESYSTEMMETADATA) 95 MEDIAGALLERIES_GETALLMEDIAFILESYSTEMMETADATA)
64 96
65 protected: 97 protected:
66 virtual ~MediaGalleriesGetAllMediaFileSystemMetadataFunction(); 98 virtual ~MediaGalleriesGetAllMediaFileSystemMetadataFunction();
67 virtual bool RunImpl() OVERRIDE; 99 virtual bool RunImpl() OVERRIDE;
68 100
69 private: 101 private:
70 // Bottom half for RunImpl, invoked after the preferences is initialized. 102 // Bottom half for RunImpl, invoked after the preferences is initialized.
71 // Gets the list of permitted galleries and checks if they are available. 103 // Gets the list of permitted galleries and checks if they are available.
72 void OnPreferencesInit(); 104 void OnPreferencesInit();
73 105
74 // Callback to run upon getting the list of available devices. 106 // Callback to run upon getting the list of available devices.
75 // Sends the list of media filesystem metadata back to the extension. 107 // Sends the list of media filesystem metadata back to the extension.
76 void OnGetGalleries(const MediaGalleryPrefIdSet& permitted_gallery_ids, 108 void OnGetGalleries(const MediaGalleryPrefIdSet& permitted_gallery_ids,
77 const MediaStorageUtil::DeviceIdSet* available_devices); 109 const MediaStorageUtil::DeviceIdSet* available_devices);
78 }; 110 };
79 111
112 class MediaGalleriesManageMediaLocationsFunction
113 : public MediaGalleriesGetMediaFileSystemsBase {
114 public:
115 DECLARE_EXTENSION_FUNCTION("mediaGalleries.manageMediaLocations",
116 MEDIAGALLERIES_MANAGEMEDIALOCATIONS)
117
118 protected:
119 virtual ~MediaGalleriesManageMediaLocationsFunction();
120 virtual bool RunImpl() OVERRIDE;
121
122 private:
123 // Bottom half for RunImpl, invoked after the preferences is initialized.
124 // Handle the |request_type| appropriately.
125 void OnPreferencesInit(MediaGalleries::ManageRequestType request_type);
126
127 // Callback for the directory prompt request, with the input from the user.
128 // If |selected_directory| is empty, then the user canceled.
129 // Either handle the user canceled case or add the selected gallery.
130 void OnDirectorySelected(const base::FilePath& selected_directory);
131
132 // Callback for the directory prompt request. |pref_id| is for the gallery
133 // the user just added. |filesystems| is the entire list of file systems.
134 // The fsid for the file system that corresponds to |pref_id| will be
135 // appended to the list of file systems returned to the caller. The
136 // Javascript binding for this API will interpret the list appropriately.
137 void ReturnGalleriesAndId(
138 MediaGalleryPrefId pref_id,
139 const std::vector<MediaFileSystemInfo>& filesystems);
140 };
141
80 } // namespace extensions 142 } // namespace extensions
81 143
82 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_ 144 #endif // CHROME_BROWSER_EXTENSIONS_API_MEDIA_GALLERIES_MEDIA_GALLERIES_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698