Chromium Code Reviews| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 MediaGalleryPrefId* gallery_pref_id) { | 62 MediaGalleryPrefId* gallery_pref_id) { |
| 63 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 MediaFileSystemRegistry* registry = | 66 MediaGalleriesPreferences* preferences = |
| 67 g_browser_process->media_file_system_registry(); | 67 g_browser_process->media_file_system_registry()->GetPreferences(profile); |
| 68 base::FilePath file_path( | 68 DCHECK(preferences->IsInitialized()); |
| 69 registry->GetPreferences(profile)->LookUpGalleryPathForExtension( | 69 base::FilePath file_path( |
| 70 pref_id, extension, false)); | 70 preferences->LookUpGalleryPathForExtension(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 } |
| 77 | 77 |
| 78 } // namespace | 78 } // namespace |
| 79 | 79 |
| 80 | 80 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 } | 115 } |
| 116 | 116 |
| 117 // static | 117 // static |
| 118 MediaGalleriesPrivateAPI* MediaGalleriesPrivateAPI::Get(Profile* profile) { | 118 MediaGalleriesPrivateAPI* MediaGalleriesPrivateAPI::Get(Profile* profile) { |
| 119 return | 119 return |
| 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 // Make sure MediaGalleriesPreferences and StorageMonitor are initialized. |
|
Lei Zhang
2013/09/21 00:12:35
Whether StorageMonitor is initialized or not is an
tommycli
2013/09/23 20:39:12
Done.
| |
| 126 // try to initialize the event router for the listener. | 126 // After that, 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 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( | 130 g_browser_process->media_file_system_registry() |
| 131 &MediaGalleriesPrivateAPI::MaybeInitializeEventRouterAndTracker, | 131 ->GetPreferences(profile_) |
|
Lei Zhang
2013/09/21 00:12:35
I hate it when things get so long that you have to
tommycli
2013/09/23 20:39:12
Done. Either way is fine with me. I just did git c
| |
| 132 weak_ptr_factory_.GetWeakPtr())); | 132 ->EnsureInitialized(base::Bind( |
| 133 &MediaGalleriesPrivateAPI::MaybeInitializeEventRouterAndTracker, | |
| 134 weak_ptr_factory_.GetWeakPtr())); | |
| 133 } | 135 } |
| 134 | 136 |
| 135 MediaGalleriesPrivateEventRouter* MediaGalleriesPrivateAPI::GetEventRouter() { | 137 MediaGalleriesPrivateEventRouter* MediaGalleriesPrivateAPI::GetEventRouter() { |
| 136 MaybeInitializeEventRouterAndTracker(); | 138 MaybeInitializeEventRouterAndTracker(); |
| 137 return media_galleries_private_event_router_.get(); | 139 return media_galleries_private_event_router_.get(); |
| 138 } | 140 } |
| 139 | 141 |
| 140 GalleryWatchStateTracker* | 142 GalleryWatchStateTracker* |
| 141 MediaGalleriesPrivateAPI::GetGalleryWatchStateTracker() { | 143 MediaGalleriesPrivateAPI::GetGalleryWatchStateTracker() { |
| 142 MaybeInitializeEventRouterAndTracker(); | 144 MaybeInitializeEventRouterAndTracker(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 RemoveGalleryWatch::Params::Create(*args_)); | 252 RemoveGalleryWatch::Params::Create(*args_)); |
| 251 EXTENSION_FUNCTION_VALIDATE(params.get()); | 253 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 252 | 254 |
| 253 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( | 255 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( |
| 254 &MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit, | 256 &MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit, |
| 255 this, | 257 this, |
| 256 params->gallery_id)); | 258 params->gallery_id)); |
| 257 return true; | 259 return true; |
| 258 } | 260 } |
| 259 | 261 |
| 260 void MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit( | 262 void MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit( |
|
Lei Zhang
2013/09/21 00:12:35
Doesn't this also need to change?
tommycli
2013/09/23 20:39:12
Done. Yes it does. Thanks.
| |
| 261 const std::string& pref_id) { | 263 const std::string& pref_id) { |
| 262 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); | 264 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
| 263 #if defined(OS_WIN) | 265 #if defined(OS_WIN) |
| 264 base::FilePath gallery_file_path; | 266 base::FilePath gallery_file_path; |
| 265 MediaGalleryPrefId gallery_pref_id = 0; | 267 MediaGalleryPrefId gallery_pref_id = 0; |
| 266 if (!GetGalleryFilePathAndId(pref_id, profile_, GetExtension(), | 268 if (!GetGalleryFilePathAndId(pref_id, profile_, GetExtension(), |
| 267 &gallery_file_path, &gallery_pref_id)) { | 269 &gallery_file_path, &gallery_pref_id)) { |
| 268 error_ = kInvalidGalleryIDError; | 270 error_ = kInvalidGalleryIDError; |
| 269 SendResponse(false); | 271 SendResponse(false); |
| 270 return; | 272 return; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 | 328 |
| 327 MediaGalleriesPrivateRemoveAllGalleryWatchFunction:: | 329 MediaGalleriesPrivateRemoveAllGalleryWatchFunction:: |
| 328 ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction() { | 330 ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction() { |
| 329 } | 331 } |
| 330 | 332 |
| 331 bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() { | 333 bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() { |
| 332 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 334 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 333 if (!render_view_host() || !render_view_host()->GetProcess()) | 335 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 334 return false; | 336 return false; |
| 335 | 337 |
| 336 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( | 338 g_browser_process->media_file_system_registry() |
| 337 &MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit, | 339 ->GetPreferences(profile_) |
| 338 this)); | 340 ->EnsureInitialized( |
| 341 base::Bind(&MediaGalleriesPrivateRemoveAllGalleryWatchFunction:: | |
| 342 OnPreferencesInit, | |
| 343 this)); | |
| 339 return true; | 344 return true; |
| 340 } | 345 } |
| 341 | 346 |
| 342 void | 347 void MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnPreferencesInit() { |
| 343 MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit() { | |
| 344 #if defined(OS_WIN) | 348 #if defined(OS_WIN) |
| 345 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); | 349 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
| 346 MediaFileSystemRegistry* registry = | 350 MediaGalleriesPreferences* preferences = |
| 347 g_browser_process->media_file_system_registry(); | 351 g_browser_process->media_file_system_registry()->GetPreferences(profile_); |
| 348 MediaGalleriesPreferences* preferences = registry->GetPreferences(profile_); | 352 DCHECK(preferences->IsInitialized()); |
| 349 GalleryWatchStateTracker* state_tracker = | 353 GalleryWatchStateTracker* state_tracker = |
| 350 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker(); | 354 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker(); |
| 351 state_tracker->RemoveAllGalleryWatchersForExtension( | 355 state_tracker->RemoveAllGalleryWatchersForExtension( |
| 352 extension_id(), preferences); | 356 extension_id(), preferences); |
| 353 #endif | 357 #endif |
| 354 SendResponse(true); | 358 SendResponse(true); |
| 355 } | 359 } |
| 356 | 360 |
| 357 /////////////////////////////////////////////////////////////////////////////// | 361 /////////////////////////////////////////////////////////////////////////////// |
| 358 // MediaGalleriesPrivateGetHandlersFunction // | 362 // MediaGalleriesPrivateGetHandlersFunction // |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 } | 402 } |
| 399 } | 403 } |
| 400 | 404 |
| 401 SetResult(result_list); | 405 SetResult(result_list); |
| 402 SendResponse(true); | 406 SendResponse(true); |
| 403 | 407 |
| 404 return true; | 408 return true; |
| 405 } | 409 } |
| 406 | 410 |
| 407 } // namespace extensions | 411 } // namespace extensions |
| OLD | NEW |