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()); |
|
vandebo (ex-Chrome)
2013/09/23 18:35:13
Actually... since preferences checks that its init
tommycli
2013/09/23 20:39:12
Done.
| |
| 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 is 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 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( | 130 MediaGalleriesPreferences* preferences = |
| 131 g_browser_process->media_file_system_registry()->GetPreferences(profile_); | |
| 132 preferences->EnsureInitialized(base::Bind( | |
| 131 &MediaGalleriesPrivateAPI::MaybeInitializeEventRouterAndTracker, | 133 &MediaGalleriesPrivateAPI::MaybeInitializeEventRouterAndTracker, |
| 132 weak_ptr_factory_.GetWeakPtr())); | 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* |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 163 bool MediaGalleriesPrivateAddGalleryWatchFunction::RunImpl() { | 165 bool MediaGalleriesPrivateAddGalleryWatchFunction::RunImpl() { |
| 164 DCHECK(profile_); | 166 DCHECK(profile_); |
| 165 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 167 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 166 if (!render_view_host() || !render_view_host()->GetProcess()) | 168 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 167 return false; | 169 return false; |
| 168 | 170 |
| 169 scoped_ptr<AddGalleryWatch::Params> params( | 171 scoped_ptr<AddGalleryWatch::Params> params( |
| 170 AddGalleryWatch::Params::Create(*args_)); | 172 AddGalleryWatch::Params::Create(*args_)); |
| 171 EXTENSION_FUNCTION_VALIDATE(params.get()); | 173 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 172 | 174 |
| 173 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( | 175 MediaGalleriesPreferences* preferences = |
| 174 &MediaGalleriesPrivateAddGalleryWatchFunction::OnStorageMonitorInit, | 176 g_browser_process->media_file_system_registry()->GetPreferences(profile_); |
| 177 preferences->EnsureInitialized(base::Bind( | |
| 178 &MediaGalleriesPrivateAddGalleryWatchFunction::OnPreferencesInit, | |
| 175 this, | 179 this, |
| 176 params->gallery_id)); | 180 params->gallery_id)); |
| 177 | 181 |
| 178 return true; | 182 return true; |
| 179 } | 183 } |
| 180 | 184 |
| 181 void MediaGalleriesPrivateAddGalleryWatchFunction::OnStorageMonitorInit( | 185 void MediaGalleriesPrivateAddGalleryWatchFunction::OnPreferencesInit( |
| 182 const std::string& pref_id) { | 186 const std::string& pref_id) { |
| 183 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); | 187 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
| 184 base::FilePath gallery_file_path; | 188 base::FilePath gallery_file_path; |
| 185 MediaGalleryPrefId gallery_pref_id = 0; | 189 MediaGalleryPrefId gallery_pref_id = 0; |
| 186 if (!GetGalleryFilePathAndId(pref_id, profile_, GetExtension(), | 190 if (!GetGalleryFilePathAndId(pref_id, profile_, GetExtension(), |
| 187 &gallery_file_path, &gallery_pref_id)) { | 191 &gallery_file_path, &gallery_pref_id)) { |
| 188 error_ = kInvalidGalleryIDError; | 192 error_ = kInvalidGalleryIDError; |
| 189 HandleResponse(gallery_pref_id, false); | 193 HandleResponse(gallery_pref_id, false); |
| 190 return; | 194 return; |
| 191 } | 195 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 247 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 244 if (!render_view_host() || !render_view_host()->GetProcess()) | 248 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 245 return false; | 249 return false; |
| 246 | 250 |
| 247 // Remove gallery watch operation is currently supported on windows platforms. | 251 // Remove gallery watch operation is currently supported on windows platforms. |
| 248 // Please refer to crbug.com/144491 for more details. | 252 // Please refer to crbug.com/144491 for more details. |
| 249 scoped_ptr<RemoveGalleryWatch::Params> params( | 253 scoped_ptr<RemoveGalleryWatch::Params> params( |
| 250 RemoveGalleryWatch::Params::Create(*args_)); | 254 RemoveGalleryWatch::Params::Create(*args_)); |
| 251 EXTENSION_FUNCTION_VALIDATE(params.get()); | 255 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 252 | 256 |
| 253 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( | 257 MediaGalleriesPreferences* preferences = |
| 254 &MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit, | 258 g_browser_process->media_file_system_registry()->GetPreferences(profile_); |
| 259 preferences->EnsureInitialized(base::Bind( | |
| 260 &MediaGalleriesPrivateRemoveGalleryWatchFunction::OnPreferencesInit, | |
| 255 this, | 261 this, |
| 256 params->gallery_id)); | 262 params->gallery_id)); |
| 257 return true; | 263 return true; |
| 258 } | 264 } |
| 259 | 265 |
| 260 void MediaGalleriesPrivateRemoveGalleryWatchFunction::OnStorageMonitorInit( | 266 void MediaGalleriesPrivateRemoveGalleryWatchFunction::OnPreferencesInit( |
| 261 const std::string& pref_id) { | 267 const std::string& pref_id) { |
| 262 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); | 268 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
| 263 #if defined(OS_WIN) | 269 #if defined(OS_WIN) |
| 264 base::FilePath gallery_file_path; | 270 base::FilePath gallery_file_path; |
| 265 MediaGalleryPrefId gallery_pref_id = 0; | 271 MediaGalleryPrefId gallery_pref_id = 0; |
| 266 if (!GetGalleryFilePathAndId(pref_id, profile_, GetExtension(), | 272 if (!GetGalleryFilePathAndId(pref_id, profile_, GetExtension(), |
| 267 &gallery_file_path, &gallery_pref_id)) { | 273 &gallery_file_path, &gallery_pref_id)) { |
| 268 error_ = kInvalidGalleryIDError; | 274 error_ = kInvalidGalleryIDError; |
| 269 SendResponse(false); | 275 SendResponse(false); |
| 270 return; | 276 return; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 | 332 |
| 327 MediaGalleriesPrivateRemoveAllGalleryWatchFunction:: | 333 MediaGalleriesPrivateRemoveAllGalleryWatchFunction:: |
| 328 ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction() { | 334 ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction() { |
| 329 } | 335 } |
| 330 | 336 |
| 331 bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() { | 337 bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() { |
| 332 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 338 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 333 if (!render_view_host() || !render_view_host()->GetProcess()) | 339 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 334 return false; | 340 return false; |
| 335 | 341 |
| 336 StorageMonitor::GetInstance()->EnsureInitialized(base::Bind( | 342 MediaGalleriesPreferences* preferences = |
| 337 &MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit, | 343 g_browser_process->media_file_system_registry()->GetPreferences(profile_); |
| 344 preferences->EnsureInitialized(base::Bind( | |
| 345 &MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnPreferencesInit, | |
| 338 this)); | 346 this)); |
| 339 return true; | 347 return true; |
| 340 } | 348 } |
| 341 | 349 |
| 342 void | 350 void MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnPreferencesInit() { |
| 343 MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnStorageMonitorInit() { | |
| 344 #if defined(OS_WIN) | 351 #if defined(OS_WIN) |
| 345 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); | 352 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
| 346 MediaFileSystemRegistry* registry = | 353 MediaGalleriesPreferences* preferences = |
| 347 g_browser_process->media_file_system_registry(); | 354 g_browser_process->media_file_system_registry()->GetPreferences(profile_); |
| 348 MediaGalleriesPreferences* preferences = registry->GetPreferences(profile_); | 355 DCHECK(preferences->IsInitialized()); |
| 349 GalleryWatchStateTracker* state_tracker = | 356 GalleryWatchStateTracker* state_tracker = |
| 350 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker(); | 357 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker(); |
| 351 state_tracker->RemoveAllGalleryWatchersForExtension( | 358 state_tracker->RemoveAllGalleryWatchersForExtension( |
| 352 extension_id(), preferences); | 359 extension_id(), preferences); |
| 353 #endif | 360 #endif |
| 354 SendResponse(true); | 361 SendResponse(true); |
| 355 } | 362 } |
| 356 | 363 |
| 357 /////////////////////////////////////////////////////////////////////////////// | 364 /////////////////////////////////////////////////////////////////////////////// |
| 358 // MediaGalleriesPrivateGetHandlersFunction // | 365 // MediaGalleriesPrivateGetHandlersFunction // |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 } | 405 } |
| 399 } | 406 } |
| 400 | 407 |
| 401 SetResult(result_list); | 408 SetResult(result_list); |
| 402 SendResponse(true); | 409 SendResponse(true); |
| 403 | 410 |
| 404 return true; | 411 return true; |
| 405 } | 412 } |
| 406 | 413 |
| 407 } // namespace extensions | 414 } // namespace extensions |
| OLD | NEW |