| OLD | NEW |
| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>::GetForProfile(profile); | 121 ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>::GetForProfile(profile); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void MediaGalleriesPrivateAPI::OnListenerAdded( | 124 void MediaGalleriesPrivateAPI::OnListenerAdded( |
| 125 const EventListenerInfo& details) { | 125 const EventListenerInfo& details) { |
| 126 // Start the StorageMonitor if it is not already initialized. After that, | 126 // Start the StorageMonitor if it is not already initialized. After that, |
| 127 // try to initialize the event router for the listener. | 127 // try to initialize the event router for the listener. |
| 128 // This method is called synchronously with the message handler for the | 128 // This method is called synchronously with the message handler for the |
| 129 // JS invocation. | 129 // JS invocation. |
| 130 | 130 |
| 131 chrome::StorageMonitor::GetInstance()->Initialize(base::Bind( | 131 chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( |
| 132 &MediaGalleriesPrivateAPI::MaybeInitializeEventRouterAndTracker, | 132 &MediaGalleriesPrivateAPI::MaybeInitializeEventRouterAndTracker, |
| 133 weak_ptr_factory_.GetWeakPtr())); | 133 weak_ptr_factory_.GetWeakPtr())); |
| 134 } | 134 } |
| 135 | 135 |
| 136 MediaGalleriesPrivateEventRouter* MediaGalleriesPrivateAPI::GetEventRouter() { | 136 MediaGalleriesPrivateEventRouter* MediaGalleriesPrivateAPI::GetEventRouter() { |
| 137 MaybeInitializeEventRouterAndTracker(); | 137 MaybeInitializeEventRouterAndTracker(); |
| 138 return media_galleries_private_event_router_.get(); | 138 return media_galleries_private_event_router_.get(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 GalleryWatchStateTracker* | 141 GalleryWatchStateTracker* |
| (...skipping 22 matching lines...) Expand all Loading... |
| 164 bool MediaGalleriesPrivateAddGalleryWatchFunction::RunImpl() { | 164 bool MediaGalleriesPrivateAddGalleryWatchFunction::RunImpl() { |
| 165 DCHECK(profile_); | 165 DCHECK(profile_); |
| 166 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 166 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 167 if (!render_view_host() || !render_view_host()->GetProcess()) | 167 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 168 return false; | 168 return false; |
| 169 | 169 |
| 170 scoped_ptr<AddGalleryWatch::Params> params( | 170 scoped_ptr<AddGalleryWatch::Params> params( |
| 171 AddGalleryWatch::Params::Create(*args_)); | 171 AddGalleryWatch::Params::Create(*args_)); |
| 172 EXTENSION_FUNCTION_VALIDATE(params.get()); | 172 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 173 | 173 |
| 174 chrome::StorageMonitor::GetInstance()->Initialize(base::Bind( | 174 chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( |
| 175 &MediaGalleriesPrivateAddGalleryWatchFunction::OnStorageMonitorInit, | 175 &MediaGalleriesPrivateAddGalleryWatchFunction::OnStorageMonitorInit, |
| 176 this, | 176 this, |
| 177 params->gallery_id)); | 177 params->gallery_id)); |
| 178 | 178 |
| 179 return true; | 179 return true; |
| 180 } | 180 } |
| 181 | 181 |
| 182 void MediaGalleriesPrivateAddGalleryWatchFunction::OnStorageMonitorInit( | 182 void MediaGalleriesPrivateAddGalleryWatchFunction::OnStorageMonitorInit( |
| 183 const std::string& pref_id) { | 183 const std::string& pref_id) { |
| 184 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); | 184 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 244 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 245 if (!render_view_host() || !render_view_host()->GetProcess()) | 245 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 246 return false; | 246 return false; |
| 247 | 247 |
| 248 // Remove gallery watch operation is currently supported on windows platforms. | 248 // Remove gallery watch operation is currently supported on windows platforms. |
| 249 // Please refer to crbug.com/144491 for more details. | 249 // Please refer to crbug.com/144491 for more details. |
| 250 scoped_ptr<RemoveGalleryWatch::Params> params( | 250 scoped_ptr<RemoveGalleryWatch::Params> params( |
| 251 RemoveGalleryWatch::Params::Create(*args_)); | 251 RemoveGalleryWatch::Params::Create(*args_)); |
| 252 EXTENSION_FUNCTION_VALIDATE(params.get()); | 252 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 253 | 253 |
| 254 chrome::StorageMonitor::GetInstance()->Initialize(base::Bind( | 254 chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( |
| 255 &MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit, | 255 &MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit, |
| 256 this, | 256 this, |
| 257 params->gallery_id)); | 257 params->gallery_id)); |
| 258 return true; | 258 return true; |
| 259 } | 259 } |
| 260 | 260 |
| 261 void MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit( | 261 void MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit( |
| 262 const std::string& pref_id) { | 262 const std::string& pref_id) { |
| 263 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); | 263 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); |
| 264 #if defined(OS_WIN) | 264 #if defined(OS_WIN) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 291 | 291 |
| 292 MediaGalleriesPrivateGetAllGalleryWatchFunction:: | 292 MediaGalleriesPrivateGetAllGalleryWatchFunction:: |
| 293 ~MediaGalleriesPrivateGetAllGalleryWatchFunction() { | 293 ~MediaGalleriesPrivateGetAllGalleryWatchFunction() { |
| 294 } | 294 } |
| 295 | 295 |
| 296 bool MediaGalleriesPrivateGetAllGalleryWatchFunction::RunImpl() { | 296 bool MediaGalleriesPrivateGetAllGalleryWatchFunction::RunImpl() { |
| 297 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 297 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 298 if (!render_view_host() || !render_view_host()->GetProcess()) | 298 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 299 return false; | 299 return false; |
| 300 | 300 |
| 301 chrome::StorageMonitor::GetInstance()->Initialize(base::Bind( | 301 chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( |
| 302 &MediaGalleriesPrivateGetAllGalleryWatchFunction::OnStorageMonitorInit, | 302 &MediaGalleriesPrivateGetAllGalleryWatchFunction::OnStorageMonitorInit, |
| 303 this)); | 303 this)); |
| 304 return true; | 304 return true; |
| 305 } | 305 } |
| 306 | 306 |
| 307 void MediaGalleriesPrivateGetAllGalleryWatchFunction::OnStorageMonitorInit() { | 307 void MediaGalleriesPrivateGetAllGalleryWatchFunction::OnStorageMonitorInit() { |
| 308 std::vector<std::string> result; | 308 std::vector<std::string> result; |
| 309 #if defined(OS_WIN) | 309 #if defined(OS_WIN) |
| 310 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); | 310 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); |
| 311 GalleryWatchStateTracker* state_tracker = | 311 GalleryWatchStateTracker* state_tracker = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 328 | 328 |
| 329 MediaGalleriesPrivateRemoveAllGalleryWatchFunction:: | 329 MediaGalleriesPrivateRemoveAllGalleryWatchFunction:: |
| 330 ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction() { | 330 ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction() { |
| 331 } | 331 } |
| 332 | 332 |
| 333 bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() { | 333 bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() { |
| 334 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 334 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 335 if (!render_view_host() || !render_view_host()->GetProcess()) | 335 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 336 return false; | 336 return false; |
| 337 | 337 |
| 338 chrome::StorageMonitor::GetInstance()->Initialize(base::Bind( | 338 chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( |
| 339 &MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit, | 339 &MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit, |
| 340 this)); | 340 this)); |
| 341 return true; | 341 return true; |
| 342 } | 342 } |
| 343 | 343 |
| 344 void | 344 void |
| 345 MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit() { | 345 MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit() { |
| 346 #if defined(OS_WIN) | 346 #if defined(OS_WIN) |
| 347 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); | 347 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); |
| 348 chrome::MediaFileSystemRegistry* registry = | 348 chrome::MediaFileSystemRegistry* registry = |
| (...skipping 15 matching lines...) Expand all Loading... |
| 364 MediaGalleriesPrivateEjectDeviceFunction:: | 364 MediaGalleriesPrivateEjectDeviceFunction:: |
| 365 ~MediaGalleriesPrivateEjectDeviceFunction() { | 365 ~MediaGalleriesPrivateEjectDeviceFunction() { |
| 366 } | 366 } |
| 367 | 367 |
| 368 bool MediaGalleriesPrivateEjectDeviceFunction::RunImpl() { | 368 bool MediaGalleriesPrivateEjectDeviceFunction::RunImpl() { |
| 369 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 369 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 370 | 370 |
| 371 scoped_ptr<EjectDevice::Params> params(EjectDevice::Params::Create(*args_)); | 371 scoped_ptr<EjectDevice::Params> params(EjectDevice::Params::Create(*args_)); |
| 372 EXTENSION_FUNCTION_VALIDATE(params.get()); | 372 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 373 | 373 |
| 374 chrome::StorageMonitor::GetInstance()->Initialize(base::Bind( | 374 chrome::StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( |
| 375 &MediaGalleriesPrivateEjectDeviceFunction::OnStorageMonitorInit, | 375 &MediaGalleriesPrivateEjectDeviceFunction::OnStorageMonitorInit, |
| 376 this, | 376 this, |
| 377 params->device_id)); | 377 params->device_id)); |
| 378 return true; | 378 return true; |
| 379 } | 379 } |
| 380 | 380 |
| 381 void MediaGalleriesPrivateEjectDeviceFunction::OnStorageMonitorInit( | 381 void MediaGalleriesPrivateEjectDeviceFunction::OnStorageMonitorInit( |
| 382 const std::string& transient_device_id) { | 382 const std::string& transient_device_id) { |
| 383 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); | 383 DCHECK(chrome::StorageMonitor::GetInstance()->IsInitialized()); |
| 384 chrome::StorageMonitor* monitor = chrome::StorageMonitor::GetInstance(); | 384 chrome::StorageMonitor* monitor = chrome::StorageMonitor::GetInstance(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 } | 464 } |
| 465 } | 465 } |
| 466 | 466 |
| 467 SetResult(result_list); | 467 SetResult(result_list); |
| 468 SendResponse(true); | 468 SendResponse(true); |
| 469 | 469 |
| 470 return true; | 470 return true; |
| 471 } | 471 } |
| 472 | 472 |
| 473 } // namespace extensions | 473 } // namespace extensions |
| OLD | NEW |