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

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

Issue 12091054: Media Galleries: Always call MediaFileSystemRegistry::GetMediaFileSystemsForExtension() before show… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: 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
« no previous file with comments | « chrome/browser/extensions/api/media_galleries/media_galleries_api.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Implements the Chrome Extensions Media Galleries API. 5 // Implements the Chrome Extensions Media Galleries API.
6 6
7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h" 7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h"
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 20 matching lines...) Expand all
31 #include "content/public/browser/render_process_host.h" 31 #include "content/public/browser/render_process_host.h"
32 #include "content/public/browser/render_view_host.h" 32 #include "content/public/browser/render_view_host.h"
33 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
34 34
35 #if defined(OS_WIN) 35 #if defined(OS_WIN)
36 #include "base/sys_string_conversions.h" 36 #include "base/sys_string_conversions.h"
37 #endif 37 #endif
38 38
39 using chrome::MediaFileSystemInfo; 39 using chrome::MediaFileSystemInfo;
40 using chrome::MediaFileSystemRegistry; 40 using chrome::MediaFileSystemRegistry;
41 using chrome::MediaFileSystemsCallback;
41 using content::ChildProcessSecurityPolicy; 42 using content::ChildProcessSecurityPolicy;
42 using content::WebContents; 43 using content::WebContents;
43 44
44 namespace MediaGalleries = extensions::api::media_galleries; 45 namespace MediaGalleries = extensions::api::media_galleries;
45 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems; 46 namespace GetMediaFileSystems = MediaGalleries::GetMediaFileSystems;
46 47
47 namespace extensions { 48 namespace extensions {
48 49
49 namespace { 50 namespace {
50 51
(...skipping 29 matching lines...) Expand all
80 GetMediaFileSystems::Params::Create(*args_)); 81 GetMediaFileSystems::Params::Create(*args_));
81 EXTENSION_FUNCTION_VALIDATE(params.get()); 82 EXTENSION_FUNCTION_VALIDATE(params.get());
82 MediaGalleries::GetMediaFileSystemsInteractivity interactive = 83 MediaGalleries::GetMediaFileSystemsInteractivity interactive =
83 MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO; 84 MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO;
84 if (params->details.get() && params->details->interactive != MediaGalleries:: 85 if (params->details.get() && params->details->interactive != MediaGalleries::
85 GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE) { 86 GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE) {
86 interactive = params->details->interactive; 87 interactive = params->details->interactive;
87 } 88 }
88 89
89 switch (interactive) { 90 switch (interactive) {
90 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_YES: 91 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_YES: {
91 ShowDialog(); 92 // On the first call to this API, the MediaFileSystemRegistry would not
vandebo (ex-Chrome) 2013/01/30 21:24:25 This comment is pretty opaque to the actual reason
Lei Zhang 2013/01/30 23:13:34 Done. I made it opaque because the statements in t
93 // know about the calling extension if this code path simply shows the
94 // media gallery dialog. The GetMediaFileSystemsForExtension() call here
95 // lets the MediaFileSystemRegistry know the calling extension is
96 // interested in getting media galleries, even though AlwaysShowDialog()
97 // does not care about the returned results.
98 GetMediaFileSystemsForExtension(base::Bind(
99 &MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog, this));
92 return true; 100 return true;
101 }
93 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_IF_NEEDED: { 102 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_IF_NEEDED: {
94 MediaFileSystemRegistry* registry = 103 GetMediaFileSystemsForExtension(base::Bind(
95 g_browser_process->media_file_system_registry(); 104 &MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries,
96 registry->GetMediaFileSystemsForExtension( 105 this));
97 render_view_host(), GetExtension(), base::Bind(
98 &MediaGalleriesGetMediaFileSystemsFunction::
99 ShowDialogIfNoGalleries,
100 this));
101 return true; 106 return true;
102 } 107 }
103 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO: 108 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO:
104 GetAndReturnGalleries(); 109 GetAndReturnGalleries();
105 return true; 110 return true;
106 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE: 111 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE:
107 NOTREACHED(); 112 NOTREACHED();
108 } 113 }
109 error_ = kInvalidInteractive; 114 error_ = kInvalidInteractive;
110 return false; 115 return false;
111 } 116 }
112 117
118 void MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog(
vandebo (ex-Chrome) 2013/01/30 21:24:25 Hmm, I wonder if it would be worthwhile to add a b
119 const std::vector<MediaFileSystemInfo>& /*filesystems*/) {
120 ShowDialog();
121 }
122
113 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries( 123 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries(
114 const std::vector<MediaFileSystemInfo>& filesystems) { 124 const std::vector<MediaFileSystemInfo>& filesystems) {
115 if (filesystems.empty()) 125 if (filesystems.empty())
116 ShowDialog(); 126 ShowDialog();
117 else 127 else
118 ReturnGalleries(filesystems); 128 ReturnGalleries(filesystems);
119 } 129 }
120 130
121 void MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries() { 131 void MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries() {
122 MediaFileSystemRegistry* registry = 132 GetMediaFileSystemsForExtension(base::Bind(
123 g_browser_process->media_file_system_registry(); 133 &MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries, this));
124 registry->GetMediaFileSystemsForExtension(
125 render_view_host(), GetExtension(), base::Bind(
126 &MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries, this));
127 } 134 }
128 135
129 void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries( 136 void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries(
130 const std::vector<MediaFileSystemInfo>& filesystems) { 137 const std::vector<MediaFileSystemInfo>& filesystems) {
131 content::RenderViewHost* rvh = render_view_host(); 138 content::RenderViewHost* rvh = render_view_host();
132 if (!rvh) { 139 if (!rvh) {
133 SendResponse(false); 140 SendResponse(false);
134 return; 141 return;
135 } 142 }
136 MediaGalleriesPermission::CheckParam read_param( 143 MediaGalleriesPermission::CheckParam read_param(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 return; 221 return;
215 } 222 }
216 } 223 }
217 224
218 // Controller will delete itself. 225 // Controller will delete itself.
219 base::Closure cb = base::Bind( 226 base::Closure cb = base::Bind(
220 &MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries, this); 227 &MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries, this);
221 new chrome::MediaGalleriesDialogController(contents, *GetExtension(), cb); 228 new chrome::MediaGalleriesDialogController(contents, *GetExtension(), cb);
222 } 229 }
223 230
231 void MediaGalleriesGetMediaFileSystemsFunction::GetMediaFileSystemsForExtension(
232 const chrome::MediaFileSystemsCallback& cb) {
233 MediaFileSystemRegistry* registry =
234 g_browser_process->media_file_system_registry();
235 registry->GetMediaFileSystemsForExtension(
236 render_view_host(), GetExtension(), cb);
237 }
238
224 // MediaGalleriesAssembleMediaFileFunction ------------------------------------- 239 // MediaGalleriesAssembleMediaFileFunction -------------------------------------
225 240
226 MediaGalleriesAssembleMediaFileFunction:: 241 MediaGalleriesAssembleMediaFileFunction::
227 ~MediaGalleriesAssembleMediaFileFunction() {} 242 ~MediaGalleriesAssembleMediaFileFunction() {}
228 243
229 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { 244 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() {
230 if (!ApiIsAccessible(&error_)) 245 if (!ApiIsAccessible(&error_))
231 return false; 246 return false;
232 247
233 // TODO(vandebo) Update the metadata and return the new file. 248 // TODO(vandebo) Update the metadata and return the new file.
234 SetResult(base::Value::CreateNullValue()); 249 SetResult(base::Value::CreateNullValue());
235 return true; 250 return true;
236 } 251 }
237 252
238 } // namespace extensions 253 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/media_galleries/media_galleries_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698