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

Side by Side Diff: chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.cc

Issue 23727009: Cleanup: Remove chrome namespace for storage monitor and media galleries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nit Created 7 years, 3 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
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 #include "chrome/browser/extensions/api/media_galleries_private/media_galleries_ private_api.h" 5 #include "chrome/browser/extensions/api/media_galleries_private/media_galleries_ private_api.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 GalleryWatchManager::OnProfileShutdown(profile_id); 52 GalleryWatchManager::OnProfileShutdown(profile_id);
53 } 53 }
54 54
55 // Gets the |gallery_file_path| and |gallery_pref_id| of the gallery specified 55 // Gets the |gallery_file_path| and |gallery_pref_id| of the gallery specified
56 // by the |gallery_id|. Returns true and set |gallery_file_path| and 56 // by the |gallery_id|. Returns true and set |gallery_file_path| and
57 // |gallery_pref_id| if the |gallery_id| is valid and returns false otherwise. 57 // |gallery_pref_id| if the |gallery_id| is valid and returns false otherwise.
58 bool GetGalleryFilePathAndId(const std::string& gallery_id, 58 bool GetGalleryFilePathAndId(const std::string& gallery_id,
59 Profile* profile, 59 Profile* profile,
60 const Extension* extension, 60 const Extension* extension,
61 base::FilePath* gallery_file_path, 61 base::FilePath* gallery_file_path,
62 chrome::MediaGalleryPrefId* gallery_pref_id) { 62 MediaGalleryPrefId* gallery_pref_id) {
63 chrome::MediaGalleryPrefId pref_id; 63 MediaGalleryPrefId pref_id;
64 if (!base::StringToUint64(gallery_id, &pref_id)) 64 if (!base::StringToUint64(gallery_id, &pref_id))
65 return false; 65 return false;
66 chrome::MediaFileSystemRegistry* registry = 66 MediaFileSystemRegistry* registry =
67 g_browser_process->media_file_system_registry(); 67 g_browser_process->media_file_system_registry();
68 base::FilePath file_path( 68 base::FilePath file_path(
69 registry->GetPreferences(profile)->LookUpGalleryPathForExtension( 69 registry->GetPreferences(profile)->LookUpGalleryPathForExtension(
70 pref_id, extension, false)); 70 pref_id, extension, false));
71 if (file_path.empty()) 71 if (file_path.empty())
72 return false; 72 return false;
73 *gallery_pref_id = pref_id; 73 *gallery_pref_id = pref_id;
74 *gallery_file_path = file_path; 74 *gallery_file_path = file_path;
75 return true; 75 return true;
76 } 76 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>::GetForProfile(profile); 120 ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>::GetForProfile(profile);
121 } 121 }
122 122
123 void MediaGalleriesPrivateAPI::OnListenerAdded( 123 void MediaGalleriesPrivateAPI::OnListenerAdded(
124 const EventListenerInfo& details) { 124 const EventListenerInfo& details) {
125 // Start the StorageMonitor if it is not already initialized. After that, 125 // Start the StorageMonitor if it is not already initialized. After that,
126 // try to initialize the event router for the listener. 126 // try to initialize the event router for the listener.
127 // This method is called synchronously with the message handler for the 127 // This method is called synchronously with the message handler for the
128 // JS invocation. 128 // JS invocation.
129 129
130 chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( 130 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind(
131 &MediaGalleriesPrivateAPI::MaybeInitializeEventRouterAndTracker, 131 &MediaGalleriesPrivateAPI::MaybeInitializeEventRouterAndTracker,
132 weak_ptr_factory_.GetWeakPtr())); 132 weak_ptr_factory_.GetWeakPtr()));
133 } 133 }
134 134
135 MediaGalleriesPrivateEventRouter* MediaGalleriesPrivateAPI::GetEventRouter() { 135 MediaGalleriesPrivateEventRouter* MediaGalleriesPrivateAPI::GetEventRouter() {
136 MaybeInitializeEventRouterAndTracker(); 136 MaybeInitializeEventRouterAndTracker();
137 return media_galleries_private_event_router_.get(); 137 return media_galleries_private_event_router_.get();
138 } 138 }
139 139
140 GalleryWatchStateTracker* 140 GalleryWatchStateTracker*
141 MediaGalleriesPrivateAPI::GetGalleryWatchStateTracker() { 141 MediaGalleriesPrivateAPI::GetGalleryWatchStateTracker() {
142 MaybeInitializeEventRouterAndTracker(); 142 MaybeInitializeEventRouterAndTracker();
143 return tracker_.get(); 143 return tracker_.get();
144 } 144 }
145 145
146 void MediaGalleriesPrivateAPI::MaybeInitializeEventRouterAndTracker() { 146 void MediaGalleriesPrivateAPI::MaybeInitializeEventRouterAndTracker() {
147 if (media_galleries_private_event_router_.get()) 147 if (media_galleries_private_event_router_.get())
148 return; 148 return;
149 media_galleries_private_event_router_.reset( 149 media_galleries_private_event_router_.reset(
150 new MediaGalleriesPrivateEventRouter(profile_)); 150 new MediaGalleriesPrivateEventRouter(profile_));
151 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); 151 DCHECK(StorageMonitor::GetInstance()->IsInitialized());
152 tracker_.reset( 152 tracker_.reset(
153 new GalleryWatchStateTracker(profile_)); 153 new GalleryWatchStateTracker(profile_));
154 } 154 }
155 155
156 /////////////////////////////////////////////////////////////////////////////// 156 ///////////////////////////////////////////////////////////////////////////////
157 // MediaGalleriesPrivateAddGalleryWatchFunction // 157 // MediaGalleriesPrivateAddGalleryWatchFunction //
158 /////////////////////////////////////////////////////////////////////////////// 158 ///////////////////////////////////////////////////////////////////////////////
159 MediaGalleriesPrivateAddGalleryWatchFunction:: 159 MediaGalleriesPrivateAddGalleryWatchFunction::
160 ~MediaGalleriesPrivateAddGalleryWatchFunction() { 160 ~MediaGalleriesPrivateAddGalleryWatchFunction() {
161 } 161 }
162 162
163 bool MediaGalleriesPrivateAddGalleryWatchFunction::RunImpl() { 163 bool MediaGalleriesPrivateAddGalleryWatchFunction::RunImpl() {
164 DCHECK(profile_); 164 DCHECK(profile_);
165 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 165 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
166 if (!render_view_host() || !render_view_host()->GetProcess()) 166 if (!render_view_host() || !render_view_host()->GetProcess())
167 return false; 167 return false;
168 168
169 scoped_ptr<AddGalleryWatch::Params> params( 169 scoped_ptr<AddGalleryWatch::Params> params(
170 AddGalleryWatch::Params::Create(*args_)); 170 AddGalleryWatch::Params::Create(*args_));
171 EXTENSION_FUNCTION_VALIDATE(params.get()); 171 EXTENSION_FUNCTION_VALIDATE(params.get());
172 172
173 chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( 173 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind(
174 &MediaGalleriesPrivateAddGalleryWatchFunction::OnStorageMonitorInit, 174 &MediaGalleriesPrivateAddGalleryWatchFunction::OnStorageMonitorInit,
175 this, 175 this,
176 params->gallery_id)); 176 params->gallery_id));
177 177
178 return true; 178 return true;
179 } 179 }
180 180
181 void MediaGalleriesPrivateAddGalleryWatchFunction::OnStorageMonitorInit( 181 void MediaGalleriesPrivateAddGalleryWatchFunction::OnStorageMonitorInit(
182 const std::string& pref_id) { 182 const std::string& pref_id) {
183 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); 183 DCHECK(StorageMonitor::GetInstance()->IsInitialized());
184 base::FilePath gallery_file_path; 184 base::FilePath gallery_file_path;
185 chrome::MediaGalleryPrefId gallery_pref_id = 0; 185 MediaGalleryPrefId gallery_pref_id = 0;
186 if (!GetGalleryFilePathAndId(pref_id, profile_, GetExtension(), 186 if (!GetGalleryFilePathAndId(pref_id, profile_, GetExtension(),
187 &gallery_file_path, &gallery_pref_id)) { 187 &gallery_file_path, &gallery_pref_id)) {
188 error_ = kInvalidGalleryIDError; 188 error_ = kInvalidGalleryIDError;
189 HandleResponse(gallery_pref_id, false); 189 HandleResponse(gallery_pref_id, false);
190 return; 190 return;
191 } 191 }
192 192
193 #if defined(OS_WIN) 193 #if defined(OS_WIN)
194 MediaGalleriesPrivateEventRouter* router = 194 MediaGalleriesPrivateEventRouter* router =
195 MediaGalleriesPrivateAPI::Get(profile_)->GetEventRouter(); 195 MediaGalleriesPrivateAPI::Get(profile_)->GetEventRouter();
(...skipping 11 matching lines...) Expand all
207 this, 207 this,
208 gallery_pref_id)); 208 gallery_pref_id));
209 #else 209 #else
210 // Recursive gallery watch operation is not currently supported on 210 // Recursive gallery watch operation is not currently supported on
211 // non-windows platforms. Please refer to crbug.com/144491 for more details. 211 // non-windows platforms. Please refer to crbug.com/144491 for more details.
212 HandleResponse(gallery_pref_id, false); 212 HandleResponse(gallery_pref_id, false);
213 #endif 213 #endif
214 } 214 }
215 215
216 void MediaGalleriesPrivateAddGalleryWatchFunction::HandleResponse( 216 void MediaGalleriesPrivateAddGalleryWatchFunction::HandleResponse(
217 chrome::MediaGalleryPrefId gallery_id, 217 MediaGalleryPrefId gallery_id,
218 bool success) { 218 bool success) {
219 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 219 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
220 media_galleries_private::AddGalleryWatchResult result; 220 media_galleries_private::AddGalleryWatchResult result;
221 result.gallery_id = base::Uint64ToString(gallery_id); 221 result.gallery_id = base::Uint64ToString(gallery_id);
222 result.success = success; 222 result.success = success;
223 SetResult(result.ToValue().release()); 223 SetResult(result.ToValue().release());
224 if (success) { 224 if (success) {
225 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); 225 DCHECK(StorageMonitor::GetInstance()->IsInitialized());
226 GalleryWatchStateTracker* state_tracker = 226 GalleryWatchStateTracker* state_tracker =
227 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker(); 227 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker();
228 state_tracker->OnGalleryWatchAdded(extension_id(), gallery_id); 228 state_tracker->OnGalleryWatchAdded(extension_id(), gallery_id);
229 } 229 }
230 SendResponse(true); 230 SendResponse(true);
231 } 231 }
232 232
233 233
234 /////////////////////////////////////////////////////////////////////////////// 234 ///////////////////////////////////////////////////////////////////////////////
235 // MediaGalleriesPrivateRemoveGalleryWatchFunction // 235 // MediaGalleriesPrivateRemoveGalleryWatchFunction //
236 /////////////////////////////////////////////////////////////////////////////// 236 ///////////////////////////////////////////////////////////////////////////////
237 237
238 MediaGalleriesPrivateRemoveGalleryWatchFunction:: 238 MediaGalleriesPrivateRemoveGalleryWatchFunction::
239 ~MediaGalleriesPrivateRemoveGalleryWatchFunction() { 239 ~MediaGalleriesPrivateRemoveGalleryWatchFunction() {
240 } 240 }
241 241
242 bool MediaGalleriesPrivateRemoveGalleryWatchFunction::RunImpl() { 242 bool MediaGalleriesPrivateRemoveGalleryWatchFunction::RunImpl() {
243 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 243 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
244 if (!render_view_host() || !render_view_host()->GetProcess()) 244 if (!render_view_host() || !render_view_host()->GetProcess())
245 return false; 245 return false;
246 246
247 // Remove gallery watch operation is currently supported on windows platforms. 247 // Remove gallery watch operation is currently supported on windows platforms.
248 // Please refer to crbug.com/144491 for more details. 248 // Please refer to crbug.com/144491 for more details.
249 scoped_ptr<RemoveGalleryWatch::Params> params( 249 scoped_ptr<RemoveGalleryWatch::Params> params(
250 RemoveGalleryWatch::Params::Create(*args_)); 250 RemoveGalleryWatch::Params::Create(*args_));
251 EXTENSION_FUNCTION_VALIDATE(params.get()); 251 EXTENSION_FUNCTION_VALIDATE(params.get());
252 252
253 chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( 253 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind(
254 &MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit, 254 &MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit,
255 this, 255 this,
256 params->gallery_id)); 256 params->gallery_id));
257 return true; 257 return true;
258 } 258 }
259 259
260 void MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit( 260 void MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit(
261 const std::string& pref_id) { 261 const std::string& pref_id) {
262 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); 262 DCHECK(StorageMonitor::GetInstance()->IsInitialized());
263 #if defined(OS_WIN) 263 #if defined(OS_WIN)
264 base::FilePath gallery_file_path; 264 base::FilePath gallery_file_path;
265 chrome::MediaGalleryPrefId gallery_pref_id = 0; 265 MediaGalleryPrefId gallery_pref_id = 0;
266 if (!GetGalleryFilePathAndId(pref_id, profile_, GetExtension(), 266 if (!GetGalleryFilePathAndId(pref_id, profile_, GetExtension(),
267 &gallery_file_path, &gallery_pref_id)) { 267 &gallery_file_path, &gallery_pref_id)) {
268 error_ = kInvalidGalleryIDError; 268 error_ = kInvalidGalleryIDError;
269 SendResponse(false); 269 SendResponse(false);
270 return; 270 return;
271 } 271 }
272 272
273 content::BrowserThread::PostTask( 273 content::BrowserThread::PostTask(
274 content::BrowserThread::FILE, FROM_HERE, 274 content::BrowserThread::FILE, FROM_HERE,
275 base::Bind(&GalleryWatchManager::RemoveGalleryWatch, 275 base::Bind(&GalleryWatchManager::RemoveGalleryWatch,
(...skipping 14 matching lines...) Expand all
290 290
291 MediaGalleriesPrivateGetAllGalleryWatchFunction:: 291 MediaGalleriesPrivateGetAllGalleryWatchFunction::
292 ~MediaGalleriesPrivateGetAllGalleryWatchFunction() { 292 ~MediaGalleriesPrivateGetAllGalleryWatchFunction() {
293 } 293 }
294 294
295 bool MediaGalleriesPrivateGetAllGalleryWatchFunction::RunImpl() { 295 bool MediaGalleriesPrivateGetAllGalleryWatchFunction::RunImpl() {
296 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 296 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
297 if (!render_view_host() || !render_view_host()->GetProcess()) 297 if (!render_view_host() || !render_view_host()->GetProcess())
298 return false; 298 return false;
299 299
300 chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( 300 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind(
301 &MediaGalleriesPrivateGetAllGalleryWatchFunction::OnStorageMonitorInit, 301 &MediaGalleriesPrivateGetAllGalleryWatchFunction::OnStorageMonitorInit,
302 this)); 302 this));
303 return true; 303 return true;
304 } 304 }
305 305
306 void MediaGalleriesPrivateGetAllGalleryWatchFunction::OnStorageMonitorInit() { 306 void MediaGalleriesPrivateGetAllGalleryWatchFunction::OnStorageMonitorInit() {
307 std::vector<std::string> result; 307 std::vector<std::string> result;
308 #if defined(OS_WIN) 308 #if defined(OS_WIN)
309 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); 309 DCHECK(StorageMonitor::GetInstance()->IsInitialized());
310 GalleryWatchStateTracker* state_tracker = 310 GalleryWatchStateTracker* state_tracker =
311 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker(); 311 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker();
312 chrome::MediaGalleryPrefIdSet gallery_ids = 312 MediaGalleryPrefIdSet gallery_ids =
313 state_tracker->GetAllWatchedGalleryIDsForExtension(extension_id()); 313 state_tracker->GetAllWatchedGalleryIDsForExtension(extension_id());
314 for (chrome::MediaGalleryPrefIdSet::const_iterator iter = 314 for (MediaGalleryPrefIdSet::const_iterator iter = gallery_ids.begin();
315 gallery_ids.begin();
316 iter != gallery_ids.end(); ++iter) { 315 iter != gallery_ids.end(); ++iter) {
317 result.push_back(base::Uint64ToString(*iter)); 316 result.push_back(base::Uint64ToString(*iter));
318 } 317 }
319 #endif 318 #endif
320 results_ = GetAllGalleryWatch::Results::Create(result); 319 results_ = GetAllGalleryWatch::Results::Create(result);
321 SendResponse(true); 320 SendResponse(true);
322 } 321 }
323 322
324 /////////////////////////////////////////////////////////////////////////////// 323 ///////////////////////////////////////////////////////////////////////////////
325 // MediaGalleriesPrivateRemoveAllGalleryWatchFunction // 324 // MediaGalleriesPrivateRemoveAllGalleryWatchFunction //
326 /////////////////////////////////////////////////////////////////////////////// 325 ///////////////////////////////////////////////////////////////////////////////
327 326
328 MediaGalleriesPrivateRemoveAllGalleryWatchFunction:: 327 MediaGalleriesPrivateRemoveAllGalleryWatchFunction::
329 ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction() { 328 ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction() {
330 } 329 }
331 330
332 bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() { 331 bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() {
333 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 332 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
334 if (!render_view_host() || !render_view_host()->GetProcess()) 333 if (!render_view_host() || !render_view_host()->GetProcess())
335 return false; 334 return false;
336 335
337 chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( 336 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind(
338 &MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit, 337 &MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit,
339 this)); 338 this));
340 return true; 339 return true;
341 } 340 }
342 341
343 void 342 void
344 MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit() { 343 MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit() {
345 #if defined(OS_WIN) 344 #if defined(OS_WIN)
346 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); 345 DCHECK(StorageMonitor::GetInstance()->IsInitialized());
347 chrome::MediaFileSystemRegistry* registry = 346 MediaFileSystemRegistry* registry =
348 g_browser_process->media_file_system_registry(); 347 g_browser_process->media_file_system_registry();
349 chrome::MediaGalleriesPreferences* preferences = 348 MediaGalleriesPreferences* preferences = registry->GetPreferences(profile_);
350 registry->GetPreferences(profile_);
351 GalleryWatchStateTracker* state_tracker = 349 GalleryWatchStateTracker* state_tracker =
352 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker(); 350 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker();
353 state_tracker->RemoveAllGalleryWatchersForExtension( 351 state_tracker->RemoveAllGalleryWatchersForExtension(
354 extension_id(), preferences); 352 extension_id(), preferences);
355 #endif 353 #endif
356 SendResponse(true); 354 SendResponse(true);
357 } 355 }
358 356
359 /////////////////////////////////////////////////////////////////////////////// 357 ///////////////////////////////////////////////////////////////////////////////
360 // MediaGalleriesPrivateGetHandlersFunction // 358 // MediaGalleriesPrivateGetHandlersFunction //
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 } 398 }
401 } 399 }
402 400
403 SetResult(result_list); 401 SetResult(result_list);
404 SendResponse(true); 402 SendResponse(true);
405 403
406 return true; 404 return true;
407 } 405 }
408 406
409 } // namespace extensions 407 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698