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

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 // To keep the media galleries permissions dialogs in sync with pref
vandebo (ex-Chrome) 2013/01/30 23:23:12 nit nit: the cause and effect seem backward in thi
Lei Zhang 2013/01/30 23:29:42 Sounds good.
93 // changes, the MediaFileSystemRegistry has to update the preferences
94 // for all the extensions it knows about. If this is the first time an
95 // extension called chrome.getMediaFileSystems, the
96 // MediaFileSystemRegistry would not know about the extension yet. To let
97 // MediaFileSystemRegistry know about the extension, call
98 // GetMediaFileSystemsForExtension() here even though the results
99 // returned in the callback are unused.
100 GetMediaFileSystemsForExtension(base::Bind(
101 &MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog, this));
92 return true; 102 return true;
103 }
93 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_IF_NEEDED: { 104 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_IF_NEEDED: {
94 MediaFileSystemRegistry* registry = 105 GetMediaFileSystemsForExtension(base::Bind(
95 g_browser_process->media_file_system_registry(); 106 &MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries,
96 registry->GetMediaFileSystemsForExtension( 107 this));
97 render_view_host(), GetExtension(), base::Bind(
98 &MediaGalleriesGetMediaFileSystemsFunction::
99 ShowDialogIfNoGalleries,
100 this));
101 return true; 108 return true;
102 } 109 }
103 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO: 110 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NO:
104 GetAndReturnGalleries(); 111 GetAndReturnGalleries();
105 return true; 112 return true;
106 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE: 113 case MediaGalleries::GET_MEDIA_FILE_SYSTEMS_INTERACTIVITY_NONE:
107 NOTREACHED(); 114 NOTREACHED();
108 } 115 }
109 error_ = kInvalidInteractive; 116 error_ = kInvalidInteractive;
110 return false; 117 return false;
111 } 118 }
112 119
120 void MediaGalleriesGetMediaFileSystemsFunction::AlwaysShowDialog(
121 const std::vector<MediaFileSystemInfo>& /*filesystems*/) {
122 ShowDialog();
123 }
124
113 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries( 125 void MediaGalleriesGetMediaFileSystemsFunction::ShowDialogIfNoGalleries(
114 const std::vector<MediaFileSystemInfo>& filesystems) { 126 const std::vector<MediaFileSystemInfo>& filesystems) {
115 if (filesystems.empty()) 127 if (filesystems.empty())
116 ShowDialog(); 128 ShowDialog();
117 else 129 else
118 ReturnGalleries(filesystems); 130 ReturnGalleries(filesystems);
119 } 131 }
120 132
121 void MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries() { 133 void MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries() {
122 MediaFileSystemRegistry* registry = 134 GetMediaFileSystemsForExtension(base::Bind(
123 g_browser_process->media_file_system_registry(); 135 &MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries, this));
124 registry->GetMediaFileSystemsForExtension(
125 render_view_host(), GetExtension(), base::Bind(
126 &MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries, this));
127 } 136 }
128 137
129 void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries( 138 void MediaGalleriesGetMediaFileSystemsFunction::ReturnGalleries(
130 const std::vector<MediaFileSystemInfo>& filesystems) { 139 const std::vector<MediaFileSystemInfo>& filesystems) {
131 content::RenderViewHost* rvh = render_view_host(); 140 content::RenderViewHost* rvh = render_view_host();
132 if (!rvh) { 141 if (!rvh) {
133 SendResponse(false); 142 SendResponse(false);
134 return; 143 return;
135 } 144 }
136 MediaGalleriesPermission::CheckParam read_param( 145 MediaGalleriesPermission::CheckParam read_param(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 return; 223 return;
215 } 224 }
216 } 225 }
217 226
218 // Controller will delete itself. 227 // Controller will delete itself.
219 base::Closure cb = base::Bind( 228 base::Closure cb = base::Bind(
220 &MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries, this); 229 &MediaGalleriesGetMediaFileSystemsFunction::GetAndReturnGalleries, this);
221 new chrome::MediaGalleriesDialogController(contents, *GetExtension(), cb); 230 new chrome::MediaGalleriesDialogController(contents, *GetExtension(), cb);
222 } 231 }
223 232
233 void MediaGalleriesGetMediaFileSystemsFunction::GetMediaFileSystemsForExtension(
234 const chrome::MediaFileSystemsCallback& cb) {
235 MediaFileSystemRegistry* registry =
236 g_browser_process->media_file_system_registry();
237 registry->GetMediaFileSystemsForExtension(
238 render_view_host(), GetExtension(), cb);
239 }
240
224 // MediaGalleriesAssembleMediaFileFunction ------------------------------------- 241 // MediaGalleriesAssembleMediaFileFunction -------------------------------------
225 242
226 MediaGalleriesAssembleMediaFileFunction:: 243 MediaGalleriesAssembleMediaFileFunction::
227 ~MediaGalleriesAssembleMediaFileFunction() {} 244 ~MediaGalleriesAssembleMediaFileFunction() {}
228 245
229 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() { 246 bool MediaGalleriesAssembleMediaFileFunction::RunImpl() {
230 if (!ApiIsAccessible(&error_)) 247 if (!ApiIsAccessible(&error_))
231 return false; 248 return false;
232 249
233 // TODO(vandebo) Update the metadata and return the new file. 250 // TODO(vandebo) Update the metadata and return the new file.
234 SetResult(base::Value::CreateNullValue()); 251 SetResult(base::Value::CreateNullValue());
235 return true; 252 return true;
236 } 253 }
237 254
238 } // namespace extensions 255 } // 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