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

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

Issue 14556015: [Media Galleries] Lazily initialize the storage monitor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix merge Created 7 years, 6 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
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 99 }
100 100
101 } // namespace 101 } // namespace
102 102
103 103
104 /////////////////////////////////////////////////////////////////////////////// 104 ///////////////////////////////////////////////////////////////////////////////
105 // MediaGalleriesPrivateAPI // 105 // MediaGalleriesPrivateAPI //
106 /////////////////////////////////////////////////////////////////////////////// 106 ///////////////////////////////////////////////////////////////////////////////
107 107
108 MediaGalleriesPrivateAPI::MediaGalleriesPrivateAPI(Profile* profile) 108 MediaGalleriesPrivateAPI::MediaGalleriesPrivateAPI(Profile* profile)
109 : profile_(profile) { 109 : profile_(profile),
110 weak_ptr_factory_(this) {
110 DCHECK(profile_); 111 DCHECK(profile_);
111 (new MediaGalleriesHandlerParser)->Register(); 112 (new MediaGalleriesHandlerParser)->Register();
112 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 113 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
113 this, event_names::kOnAttachEventName); 114 this, event_names::kOnAttachEventName);
114 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 115 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
115 this, event_names::kOnDetachEventName); 116 this, event_names::kOnDetachEventName);
116 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 117 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
117 this, event_names::kOnGalleryChangedEventName); 118 this, event_names::kOnGalleryChangedEventName);
118 } 119 }
119 120
120 MediaGalleriesPrivateAPI::~MediaGalleriesPrivateAPI() { 121 MediaGalleriesPrivateAPI::~MediaGalleriesPrivateAPI() {
121 } 122 }
122 123
123 void MediaGalleriesPrivateAPI::Shutdown() { 124 void MediaGalleriesPrivateAPI::Shutdown() {
124 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); 125 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
126 weak_ptr_factory_.InvalidateWeakPtrs();
125 content::BrowserThread::PostTask( 127 content::BrowserThread::PostTask(
126 content::BrowserThread::FILE, FROM_HERE, 128 content::BrowserThread::FILE, FROM_HERE,
127 base::Bind(&HandleProfileShutdownOnFileThread, profile_)); 129 base::Bind(&HandleProfileShutdownOnFileThread, profile_));
128 } 130 }
129 131
130 static base::LazyInstance<ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI> > 132 static base::LazyInstance<ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI> >
131 g_factory = LAZY_INSTANCE_INITIALIZER; 133 g_factory = LAZY_INSTANCE_INITIALIZER;
132 134
133 // static 135 // static
134 ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>* 136 ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>*
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 if (!Extension::IdIsValid(iter.key())) { 260 if (!Extension::IdIsValid(iter.key())) {
259 NOTREACHED(); 261 NOTREACHED();
260 continue; 262 continue;
261 } 263 }
262 UnsetMediaGalleryPermission(prefs, iter.key(), gallery_id); 264 UnsetMediaGalleryPermission(prefs, iter.key(), gallery_id);
263 } 265 }
264 } 266 }
265 267
266 void MediaGalleriesPrivateAPI::OnListenerAdded( 268 void MediaGalleriesPrivateAPI::OnListenerAdded(
267 const EventListenerInfo& details) { 269 const EventListenerInfo& details) {
268 // Try to initialize the event router for the listener. If 270 // Start the StorageMonitor if it is not already initialized. After that,
269 // MediaGalleriesPrivateAPI::GetEventRouter() was called before adding 271 // try to initialize the event router for the listener.
270 // the listener, router would be initialized. 272 // This method is called synchronously with the message handler for the
271 MaybeInitializeEventRouterAndTracker(); 273 // JS invocation.
274
275 chrome::StorageMonitor::GetInstance()->Initialize(base::Bind(
276 &MediaGalleriesPrivateAPI::MaybeInitializeEventRouterAndTracker,
277 weak_ptr_factory_.GetWeakPtr()));
272 } 278 }
273 279
274 MediaGalleriesPrivateEventRouter* MediaGalleriesPrivateAPI::GetEventRouter() { 280 MediaGalleriesPrivateEventRouter* MediaGalleriesPrivateAPI::GetEventRouter() {
275 MaybeInitializeEventRouterAndTracker(); 281 MaybeInitializeEventRouterAndTracker();
276 return media_galleries_private_event_router_.get(); 282 return media_galleries_private_event_router_.get();
277 } 283 }
278 284
279 GalleryWatchStateTracker* 285 GalleryWatchStateTracker*
280 MediaGalleriesPrivateAPI::GetGalleryWatchStateTracker() { 286 MediaGalleriesPrivateAPI::GetGalleryWatchStateTracker() {
281 MaybeInitializeEventRouterAndTracker(); 287 MaybeInitializeEventRouterAndTracker();
282 return tracker_.get(); 288 return tracker_.get();
283 } 289 }
284 290
285 void MediaGalleriesPrivateAPI::MaybeInitializeEventRouterAndTracker() { 291 void MediaGalleriesPrivateAPI::MaybeInitializeEventRouterAndTracker() {
286 if (media_galleries_private_event_router_.get()) 292 if (media_galleries_private_event_router_.get())
287 return; 293 return;
288 media_galleries_private_event_router_.reset( 294 media_galleries_private_event_router_.reset(
289 new MediaGalleriesPrivateEventRouter(profile_)); 295 new MediaGalleriesPrivateEventRouter(profile_));
296 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized());
290 tracker_.reset( 297 tracker_.reset(
291 new GalleryWatchStateTracker(profile_)); 298 new GalleryWatchStateTracker(profile_));
292 } 299 }
293 300
294 /////////////////////////////////////////////////////////////////////////////// 301 ///////////////////////////////////////////////////////////////////////////////
295 // MediaGalleriesPrivateAddGalleryWatchFunction // 302 // MediaGalleriesPrivateAddGalleryWatchFunction //
296 /////////////////////////////////////////////////////////////////////////////// 303 ///////////////////////////////////////////////////////////////////////////////
297 MediaGalleriesPrivateAddGalleryWatchFunction:: 304 MediaGalleriesPrivateAddGalleryWatchFunction::
298 ~MediaGalleriesPrivateAddGalleryWatchFunction() { 305 ~MediaGalleriesPrivateAddGalleryWatchFunction() {
299 } 306 }
300 307
301 bool MediaGalleriesPrivateAddGalleryWatchFunction::RunImpl() { 308 bool MediaGalleriesPrivateAddGalleryWatchFunction::RunImpl() {
302 DCHECK(profile_); 309 DCHECK(profile_);
303 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 310 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
304 if (!render_view_host() || !render_view_host()->GetProcess()) 311 if (!render_view_host() || !render_view_host()->GetProcess())
305 return false; 312 return false;
306 313
307 scoped_ptr<AddGalleryWatch::Params> params( 314 scoped_ptr<AddGalleryWatch::Params> params(
308 AddGalleryWatch::Params::Create(*args_)); 315 AddGalleryWatch::Params::Create(*args_));
309 EXTENSION_FUNCTION_VALIDATE(params.get()); 316 EXTENSION_FUNCTION_VALIDATE(params.get());
310 317
318 chrome::StorageMonitor::GetInstance()->Initialize(base::Bind(
319 &MediaGalleriesPrivateAddGalleryWatchFunction::OnStorageMonitorInit,
320 this,
321 params->gallery_id));
322
323 return true;
324 }
325
326 void MediaGalleriesPrivateAddGalleryWatchFunction::OnStorageMonitorInit(
327 const std::string& pref_id) {
328 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized());
311 base::FilePath gallery_file_path; 329 base::FilePath gallery_file_path;
312 chrome::MediaGalleryPrefId gallery_pref_id = 0; 330 chrome::MediaGalleryPrefId gallery_pref_id = 0;
313 if (!GetGalleryFilePathAndId(params->gallery_id, profile_, GetExtension(), 331 if (!GetGalleryFilePathAndId(pref_id, profile_, GetExtension(),
314 &gallery_file_path, &gallery_pref_id)) { 332 &gallery_file_path, &gallery_pref_id)) {
315 error_ = kInvalidGalleryIDError; 333 error_ = kInvalidGalleryIDError;
316 return false; 334 HandleResponse(gallery_pref_id, false);
335 return;
317 } 336 }
318 337
319 #if defined(OS_WIN) 338 #if defined(OS_WIN)
320 MediaGalleriesPrivateEventRouter* router = 339 MediaGalleriesPrivateEventRouter* router =
321 MediaGalleriesPrivateAPI::Get(profile_)->GetEventRouter(); 340 MediaGalleriesPrivateAPI::Get(profile_)->GetEventRouter();
322 DCHECK(router); 341 DCHECK(router);
323 content::BrowserThread::PostTaskAndReplyWithResult( 342 content::BrowserThread::PostTaskAndReplyWithResult(
324 content::BrowserThread::FILE, 343 content::BrowserThread::FILE,
325 FROM_HERE, 344 FROM_HERE,
326 base::Bind(&GalleryWatchManager::SetupGalleryWatch, 345 base::Bind(&GalleryWatchManager::SetupGalleryWatch,
327 profile_, 346 profile_,
328 gallery_pref_id, 347 gallery_pref_id,
329 gallery_file_path, 348 gallery_file_path,
330 extension_id(), 349 extension_id(),
331 router->AsWeakPtr()), 350 router->AsWeakPtr()),
332 base::Bind(&MediaGalleriesPrivateAddGalleryWatchFunction::HandleResponse, 351 base::Bind(&MediaGalleriesPrivateAddGalleryWatchFunction::HandleResponse,
333 this, 352 this,
334 gallery_pref_id)); 353 gallery_pref_id));
335 #else 354 #else
336 // Recursive gallery watch operation is not currently supported on 355 // Recursive gallery watch operation is not currently supported on
337 // non-windows platforms. Please refer to crbug.com/144491 for more details. 356 // non-windows platforms. Please refer to crbug.com/144491 for more details.
338 HandleResponse(gallery_pref_id, false); 357 HandleResponse(gallery_pref_id, false);
339 #endif 358 #endif
340 return true;
341 } 359 }
342 360
343 void MediaGalleriesPrivateAddGalleryWatchFunction::HandleResponse( 361 void MediaGalleriesPrivateAddGalleryWatchFunction::HandleResponse(
344 chrome::MediaGalleryPrefId gallery_id, 362 chrome::MediaGalleryPrefId gallery_id,
345 bool success) { 363 bool success) {
346 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 364 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
347 extensions::api::media_galleries_private::AddGalleryWatchResult result; 365 extensions::api::media_galleries_private::AddGalleryWatchResult result;
348 result.gallery_id = base::Uint64ToString(gallery_id); 366 result.gallery_id = base::Uint64ToString(gallery_id);
349 result.success = success; 367 result.success = success;
350 SetResult(result.ToValue().release()); 368 SetResult(result.ToValue().release());
351 if (success) { 369 if (success) {
370 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized());
352 GalleryWatchStateTracker* state_tracker = 371 GalleryWatchStateTracker* state_tracker =
353 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker(); 372 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker();
354 state_tracker->OnGalleryWatchAdded(extension_id(), gallery_id); 373 state_tracker->OnGalleryWatchAdded(extension_id(), gallery_id);
355 } 374 }
356 SendResponse(true); 375 SendResponse(true);
357 } 376 }
358 377
359 378
360 /////////////////////////////////////////////////////////////////////////////// 379 ///////////////////////////////////////////////////////////////////////////////
361 // MediaGalleriesPrivateRemoveGalleryWatchFunction // 380 // MediaGalleriesPrivateRemoveGalleryWatchFunction //
362 /////////////////////////////////////////////////////////////////////////////// 381 ///////////////////////////////////////////////////////////////////////////////
363 382
364 MediaGalleriesPrivateRemoveGalleryWatchFunction:: 383 MediaGalleriesPrivateRemoveGalleryWatchFunction::
365 ~MediaGalleriesPrivateRemoveGalleryWatchFunction() { 384 ~MediaGalleriesPrivateRemoveGalleryWatchFunction() {
366 } 385 }
367 386
368 bool MediaGalleriesPrivateRemoveGalleryWatchFunction::RunImpl() { 387 bool MediaGalleriesPrivateRemoveGalleryWatchFunction::RunImpl() {
369 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 388 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
370 #if defined(OS_WIN)
371 if (!render_view_host() || !render_view_host()->GetProcess()) 389 if (!render_view_host() || !render_view_host()->GetProcess())
372 return false; 390 return false;
373 391
374 // Remove gallery watch operation is currently supported on windows platforms. 392 // Remove gallery watch operation is currently supported on windows platforms.
375 // Please refer to crbug.com/144491 for more details. 393 // Please refer to crbug.com/144491 for more details.
376 scoped_ptr<RemoveGalleryWatch::Params> params( 394 scoped_ptr<RemoveGalleryWatch::Params> params(
377 RemoveGalleryWatch::Params::Create(*args_)); 395 RemoveGalleryWatch::Params::Create(*args_));
378 EXTENSION_FUNCTION_VALIDATE(params.get()); 396 EXTENSION_FUNCTION_VALIDATE(params.get());
379 397
398 chrome::StorageMonitor::GetInstance()->Initialize(base::Bind(
399 &MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit,
400 this,
401 params->gallery_id));
402 return true;
403 }
404
405 void MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit(
406 const std::string& pref_id) {
407 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized());
408 #if defined(OS_WIN)
380 base::FilePath gallery_file_path; 409 base::FilePath gallery_file_path;
381 chrome::MediaGalleryPrefId gallery_pref_id = 0; 410 chrome::MediaGalleryPrefId gallery_pref_id = 0;
382 if (!GetGalleryFilePathAndId(params->gallery_id, profile_, GetExtension(), 411 if (!GetGalleryFilePathAndId(pref_id, profile_, GetExtension(),
383 &gallery_file_path, &gallery_pref_id)) { 412 &gallery_file_path, &gallery_pref_id)) {
384 error_ = kInvalidGalleryIDError; 413 error_ = kInvalidGalleryIDError;
385 return false; 414 SendResponse(false);
415 return;
386 } 416 }
387 417
388 content::BrowserThread::PostTask( 418 content::BrowserThread::PostTask(
389 content::BrowserThread::FILE, FROM_HERE, 419 content::BrowserThread::FILE, FROM_HERE,
390 base::Bind(&GalleryWatchManager::RemoveGalleryWatch, 420 base::Bind(&GalleryWatchManager::RemoveGalleryWatch,
391 profile_, 421 profile_,
392 gallery_file_path, 422 gallery_file_path,
393 extension_id())); 423 extension_id()));
394 424
395 GalleryWatchStateTracker* state_tracker = 425 GalleryWatchStateTracker* state_tracker =
396 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker(); 426 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker();
397 state_tracker->OnGalleryWatchRemoved(extension_id(), gallery_pref_id); 427 state_tracker->OnGalleryWatchRemoved(extension_id(), gallery_pref_id);
398 #endif 428 #endif
399 return true; 429 SendResponse(true);
400 } 430 }
401 431
402 /////////////////////////////////////////////////////////////////////////////// 432 ///////////////////////////////////////////////////////////////////////////////
403 // MediaGalleriesPrivateGetAllGalleryWatchFunction // 433 // MediaGalleriesPrivateGetAllGalleryWatchFunction //
404 /////////////////////////////////////////////////////////////////////////////// 434 ///////////////////////////////////////////////////////////////////////////////
405 435
406 MediaGalleriesPrivateGetAllGalleryWatchFunction:: 436 MediaGalleriesPrivateGetAllGalleryWatchFunction::
407 ~MediaGalleriesPrivateGetAllGalleryWatchFunction() { 437 ~MediaGalleriesPrivateGetAllGalleryWatchFunction() {
408 } 438 }
409 439
410 bool MediaGalleriesPrivateGetAllGalleryWatchFunction::RunImpl() { 440 bool MediaGalleriesPrivateGetAllGalleryWatchFunction::RunImpl() {
411 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 441 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
412 if (!render_view_host() || !render_view_host()->GetProcess()) 442 if (!render_view_host() || !render_view_host()->GetProcess())
413 return false; 443 return false;
414 444
445 chrome::StorageMonitor::GetInstance()->Initialize(base::Bind(
446 &MediaGalleriesPrivateGetAllGalleryWatchFunction::OnStorageMonitorInit,
447 this));
448 return true;
449 }
450
451 void MediaGalleriesPrivateGetAllGalleryWatchFunction::OnStorageMonitorInit() {
415 std::vector<std::string> result; 452 std::vector<std::string> result;
416 #if defined(OS_WIN) 453 #if defined(OS_WIN)
454 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized());
417 GalleryWatchStateTracker* state_tracker = 455 GalleryWatchStateTracker* state_tracker =
418 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker(); 456 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker();
419 chrome::MediaGalleryPrefIdSet gallery_ids = 457 chrome::MediaGalleryPrefIdSet gallery_ids =
420 state_tracker->GetAllWatchedGalleryIDsForExtension(extension_id()); 458 state_tracker->GetAllWatchedGalleryIDsForExtension(extension_id());
421 for (chrome::MediaGalleryPrefIdSet::const_iterator iter = 459 for (chrome::MediaGalleryPrefIdSet::const_iterator iter =
422 gallery_ids.begin(); 460 gallery_ids.begin();
423 iter != gallery_ids.end(); ++iter) { 461 iter != gallery_ids.end(); ++iter) {
424 result.push_back(base::Uint64ToString(*iter)); 462 result.push_back(base::Uint64ToString(*iter));
425 } 463 }
426 #endif 464 #endif
427 results_ = GetAllGalleryWatch::Results::Create(result); 465 results_ = GetAllGalleryWatch::Results::Create(result);
428 return true; 466 SendResponse(true);
429 } 467 }
430 468
431 /////////////////////////////////////////////////////////////////////////////// 469 ///////////////////////////////////////////////////////////////////////////////
432 // MediaGalleriesPrivateRemoveAllGalleryWatchFunction // 470 // MediaGalleriesPrivateRemoveAllGalleryWatchFunction //
433 /////////////////////////////////////////////////////////////////////////////// 471 ///////////////////////////////////////////////////////////////////////////////
434 472
435 MediaGalleriesPrivateRemoveAllGalleryWatchFunction:: 473 MediaGalleriesPrivateRemoveAllGalleryWatchFunction::
436 ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction() { 474 ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction() {
437 } 475 }
438 476
439 bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() { 477 bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() {
440 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 478 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
441 #if defined(OS_WIN)
442 if (!render_view_host() || !render_view_host()->GetProcess()) 479 if (!render_view_host() || !render_view_host()->GetProcess())
443 return false; 480 return false;
444 481
482 chrome::StorageMonitor::GetInstance()->Initialize(base::Bind(
483 &MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit,
484 this));
485 return true;
486 }
487
488 void
489 MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit() {
490 #if defined(OS_WIN)
491 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized());
445 chrome::MediaFileSystemRegistry* registry = 492 chrome::MediaFileSystemRegistry* registry =
446 g_browser_process->media_file_system_registry(); 493 g_browser_process->media_file_system_registry();
447 chrome::MediaGalleriesPreferences* preferences = 494 chrome::MediaGalleriesPreferences* preferences =
448 registry->GetPreferences(profile_); 495 registry->GetPreferences(profile_);
449 GalleryWatchStateTracker* state_tracker = 496 GalleryWatchStateTracker* state_tracker =
450 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker(); 497 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker();
451 state_tracker->RemoveAllGalleryWatchersForExtension( 498 state_tracker->RemoveAllGalleryWatchersForExtension(
452 extension_id(), preferences); 499 extension_id(), preferences);
453 #endif 500 #endif
454 return true; 501 SendResponse(true);
455 } 502 }
456 503
457 /////////////////////////////////////////////////////////////////////////////// 504 ///////////////////////////////////////////////////////////////////////////////
458 // MediaGalleriesPrivateEjectDeviceFunction // 505 // MediaGalleriesPrivateEjectDeviceFunction //
459 /////////////////////////////////////////////////////////////////////////////// 506 ///////////////////////////////////////////////////////////////////////////////
460 507
461 MediaGalleriesPrivateEjectDeviceFunction:: 508 MediaGalleriesPrivateEjectDeviceFunction::
462 ~MediaGalleriesPrivateEjectDeviceFunction() { 509 ~MediaGalleriesPrivateEjectDeviceFunction() {
463 } 510 }
464 511
465 bool MediaGalleriesPrivateEjectDeviceFunction::RunImpl() { 512 bool MediaGalleriesPrivateEjectDeviceFunction::RunImpl() {
466 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 513 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
467 514
468 scoped_ptr<EjectDevice::Params> params(EjectDevice::Params::Create(*args_)); 515 scoped_ptr<EjectDevice::Params> params(EjectDevice::Params::Create(*args_));
469 EXTENSION_FUNCTION_VALIDATE(params.get()); 516 EXTENSION_FUNCTION_VALIDATE(params.get());
470 517
518 chrome::StorageMonitor::GetInstance()->Initialize(base::Bind(
519 &MediaGalleriesPrivateEjectDeviceFunction::OnStorageMonitorInit,
520 this,
521 params->device_id));
522 return true;
523 }
524
525 void MediaGalleriesPrivateEjectDeviceFunction::OnStorageMonitorInit(
526 const std::string& transient_device_id) {
527 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized());
471 chrome::StorageMonitor* monitor = chrome::StorageMonitor::GetInstance(); 528 chrome::StorageMonitor* monitor = chrome::StorageMonitor::GetInstance();
472 std::string device_id_str = 529 std::string device_id_str =
473 monitor->GetDeviceIdForTransientId(params->device_id); 530 monitor->GetDeviceIdForTransientId(transient_device_id);
474 if (device_id_str == "") { 531 if (device_id_str == "") {
475 HandleResponse(chrome::StorageMonitor::EJECT_NO_SUCH_DEVICE); 532 HandleResponse(chrome::StorageMonitor::EJECT_NO_SUCH_DEVICE);
476 return true; 533 return;
477 } 534 }
478 535
479 monitor->EjectDevice( 536 monitor->EjectDevice(
480 device_id_str, 537 device_id_str,
481 base::Bind(&MediaGalleriesPrivateEjectDeviceFunction::HandleResponse, 538 base::Bind(&MediaGalleriesPrivateEjectDeviceFunction::HandleResponse,
482 this)); 539 this));
483
484 return true;
485 } 540 }
486 541
487 void MediaGalleriesPrivateEjectDeviceFunction::HandleResponse( 542 void MediaGalleriesPrivateEjectDeviceFunction::HandleResponse(
488 chrome::StorageMonitor::EjectStatus status) { 543 chrome::StorageMonitor::EjectStatus status) {
489 using extensions::api::media_galleries_private:: 544 using extensions::api::media_galleries_private::
490 EJECT_DEVICE_RESULT_CODE_FAILURE; 545 EJECT_DEVICE_RESULT_CODE_FAILURE;
491 using extensions::api::media_galleries_private:: 546 using extensions::api::media_galleries_private::
492 EJECT_DEVICE_RESULT_CODE_IN_USE; 547 EJECT_DEVICE_RESULT_CODE_IN_USE;
493 using extensions::api::media_galleries_private:: 548 using extensions::api::media_galleries_private::
494 EJECT_DEVICE_RESULT_CODE_NO_SUCH_DEVICE; 549 EJECT_DEVICE_RESULT_CODE_NO_SUCH_DEVICE;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 } 608 }
554 } 609 }
555 610
556 SetResult(result_list); 611 SetResult(result_list);
557 SendResponse(true); 612 SendResponse(true);
558 613
559 return true; 614 return true;
560 } 615 }
561 616
562 } // namespace extensions 617 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698