| 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 29 matching lines...) Expand all Loading... |
| 40 namespace media_galleries_private = | 40 namespace media_galleries_private = |
| 41 api::media_galleries_private; | 41 api::media_galleries_private; |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 const char kInvalidGalleryIDError[] = "Invalid gallery ID"; | 45 const char kInvalidGalleryIDError[] = "Invalid gallery ID"; |
| 46 | 46 |
| 47 // Handles the profile shutdown event on the file thread to clean up | 47 // Handles the profile shutdown event on the file thread to clean up |
| 48 // GalleryWatchManager. | 48 // GalleryWatchManager. |
| 49 void HandleProfileShutdownOnFileThread(void* profile_id) { | 49 void HandleProfileShutdownOnFileThread(void* profile_id) { |
| 50 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 50 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 51 GalleryWatchManager::OnProfileShutdown(profile_id); | 51 GalleryWatchManager::OnProfileShutdown(profile_id); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Gets the |gallery_file_path| and |gallery_pref_id| of the gallery specified | 54 // Gets the |gallery_file_path| and |gallery_pref_id| of the gallery specified |
| 55 // by the |gallery_id|. Returns true and set |gallery_file_path| and | 55 // by the |gallery_id|. Returns true and set |gallery_file_path| and |
| 56 // |gallery_pref_id| if the |gallery_id| is valid and returns false otherwise. | 56 // |gallery_pref_id| if the |gallery_id| is valid and returns false otherwise. |
| 57 bool GetGalleryFilePathAndId(const std::string& gallery_id, | 57 bool GetGalleryFilePathAndId(const std::string& gallery_id, |
| 58 Profile* profile, | 58 Profile* profile, |
| 59 const Extension* extension, | 59 const Extension* extension, |
| 60 base::FilePath* gallery_file_path, | 60 base::FilePath* gallery_file_path, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 154 |
| 155 /////////////////////////////////////////////////////////////////////////////// | 155 /////////////////////////////////////////////////////////////////////////////// |
| 156 // MediaGalleriesPrivateAddGalleryWatchFunction // | 156 // MediaGalleriesPrivateAddGalleryWatchFunction // |
| 157 /////////////////////////////////////////////////////////////////////////////// | 157 /////////////////////////////////////////////////////////////////////////////// |
| 158 MediaGalleriesPrivateAddGalleryWatchFunction:: | 158 MediaGalleriesPrivateAddGalleryWatchFunction:: |
| 159 ~MediaGalleriesPrivateAddGalleryWatchFunction() { | 159 ~MediaGalleriesPrivateAddGalleryWatchFunction() { |
| 160 } | 160 } |
| 161 | 161 |
| 162 bool MediaGalleriesPrivateAddGalleryWatchFunction::RunImpl() { | 162 bool MediaGalleriesPrivateAddGalleryWatchFunction::RunImpl() { |
| 163 DCHECK(GetProfile()); | 163 DCHECK(GetProfile()); |
| 164 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 164 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 165 if (!render_view_host() || !render_view_host()->GetProcess()) | 165 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 166 return false; | 166 return false; |
| 167 | 167 |
| 168 scoped_ptr<AddGalleryWatch::Params> params( | 168 scoped_ptr<AddGalleryWatch::Params> params( |
| 169 AddGalleryWatch::Params::Create(*args_)); | 169 AddGalleryWatch::Params::Create(*args_)); |
| 170 EXTENSION_FUNCTION_VALIDATE(params.get()); | 170 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 171 | 171 |
| 172 MediaGalleriesPreferences* preferences = | 172 MediaGalleriesPreferences* preferences = |
| 173 g_browser_process->media_file_system_registry()->GetPreferences( | 173 g_browser_process->media_file_system_registry()->GetPreferences( |
| 174 GetProfile()); | 174 GetProfile()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 #else | 213 #else |
| 214 // Recursive gallery watch operation is not currently supported on | 214 // Recursive gallery watch operation is not currently supported on |
| 215 // non-windows platforms. Please refer to crbug.com/144491 for more details. | 215 // non-windows platforms. Please refer to crbug.com/144491 for more details. |
| 216 HandleResponse(gallery_pref_id, false); | 216 HandleResponse(gallery_pref_id, false); |
| 217 #endif | 217 #endif |
| 218 } | 218 } |
| 219 | 219 |
| 220 void MediaGalleriesPrivateAddGalleryWatchFunction::HandleResponse( | 220 void MediaGalleriesPrivateAddGalleryWatchFunction::HandleResponse( |
| 221 MediaGalleryPrefId gallery_id, | 221 MediaGalleryPrefId gallery_id, |
| 222 bool success) { | 222 bool success) { |
| 223 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 223 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 224 media_galleries_private::AddGalleryWatchResult result; | 224 media_galleries_private::AddGalleryWatchResult result; |
| 225 result.gallery_id = base::Uint64ToString(gallery_id); | 225 result.gallery_id = base::Uint64ToString(gallery_id); |
| 226 result.success = success; | 226 result.success = success; |
| 227 SetResult(result.ToValue().release()); | 227 SetResult(result.ToValue().release()); |
| 228 if (success) { | 228 if (success) { |
| 229 DCHECK(g_browser_process->media_file_system_registry() | 229 DCHECK(g_browser_process->media_file_system_registry() |
| 230 ->GetPreferences(GetProfile()) | 230 ->GetPreferences(GetProfile()) |
| 231 ->IsInitialized()); | 231 ->IsInitialized()); |
| 232 GalleryWatchStateTracker* state_tracker = MediaGalleriesPrivateAPI::Get( | 232 GalleryWatchStateTracker* state_tracker = MediaGalleriesPrivateAPI::Get( |
| 233 GetProfile())->GetGalleryWatchStateTracker(); | 233 GetProfile())->GetGalleryWatchStateTracker(); |
| 234 state_tracker->OnGalleryWatchAdded(extension_id(), gallery_id); | 234 state_tracker->OnGalleryWatchAdded(extension_id(), gallery_id); |
| 235 } | 235 } |
| 236 SendResponse(true); | 236 SendResponse(true); |
| 237 } | 237 } |
| 238 | 238 |
| 239 | 239 |
| 240 /////////////////////////////////////////////////////////////////////////////// | 240 /////////////////////////////////////////////////////////////////////////////// |
| 241 // MediaGalleriesPrivateRemoveGalleryWatchFunction // | 241 // MediaGalleriesPrivateRemoveGalleryWatchFunction // |
| 242 /////////////////////////////////////////////////////////////////////////////// | 242 /////////////////////////////////////////////////////////////////////////////// |
| 243 | 243 |
| 244 MediaGalleriesPrivateRemoveGalleryWatchFunction:: | 244 MediaGalleriesPrivateRemoveGalleryWatchFunction:: |
| 245 ~MediaGalleriesPrivateRemoveGalleryWatchFunction() { | 245 ~MediaGalleriesPrivateRemoveGalleryWatchFunction() { |
| 246 } | 246 } |
| 247 | 247 |
| 248 bool MediaGalleriesPrivateRemoveGalleryWatchFunction::RunImpl() { | 248 bool MediaGalleriesPrivateRemoveGalleryWatchFunction::RunImpl() { |
| 249 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 249 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 250 if (!render_view_host() || !render_view_host()->GetProcess()) | 250 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 251 return false; | 251 return false; |
| 252 | 252 |
| 253 // Remove gallery watch operation is currently supported on windows platforms. | 253 // Remove gallery watch operation is currently supported on windows platforms. |
| 254 // Please refer to crbug.com/144491 for more details. | 254 // Please refer to crbug.com/144491 for more details. |
| 255 scoped_ptr<RemoveGalleryWatch::Params> params( | 255 scoped_ptr<RemoveGalleryWatch::Params> params( |
| 256 RemoveGalleryWatch::Params::Create(*args_)); | 256 RemoveGalleryWatch::Params::Create(*args_)); |
| 257 EXTENSION_FUNCTION_VALIDATE(params.get()); | 257 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 258 | 258 |
| 259 MediaGalleriesPreferences* preferences = | 259 MediaGalleriesPreferences* preferences = |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 298 |
| 299 /////////////////////////////////////////////////////////////////////////////// | 299 /////////////////////////////////////////////////////////////////////////////// |
| 300 // MediaGalleriesPrivateGetAllGalleryWatchFunction // | 300 // MediaGalleriesPrivateGetAllGalleryWatchFunction // |
| 301 /////////////////////////////////////////////////////////////////////////////// | 301 /////////////////////////////////////////////////////////////////////////////// |
| 302 | 302 |
| 303 MediaGalleriesPrivateGetAllGalleryWatchFunction:: | 303 MediaGalleriesPrivateGetAllGalleryWatchFunction:: |
| 304 ~MediaGalleriesPrivateGetAllGalleryWatchFunction() { | 304 ~MediaGalleriesPrivateGetAllGalleryWatchFunction() { |
| 305 } | 305 } |
| 306 | 306 |
| 307 bool MediaGalleriesPrivateGetAllGalleryWatchFunction::RunImpl() { | 307 bool MediaGalleriesPrivateGetAllGalleryWatchFunction::RunImpl() { |
| 308 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 308 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 309 if (!render_view_host() || !render_view_host()->GetProcess()) | 309 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 310 return false; | 310 return false; |
| 311 | 311 |
| 312 MediaGalleriesPreferences* preferences = | 312 MediaGalleriesPreferences* preferences = |
| 313 g_browser_process->media_file_system_registry()->GetPreferences( | 313 g_browser_process->media_file_system_registry()->GetPreferences( |
| 314 GetProfile()); | 314 GetProfile()); |
| 315 preferences->EnsureInitialized(base::Bind( | 315 preferences->EnsureInitialized(base::Bind( |
| 316 &MediaGalleriesPrivateGetAllGalleryWatchFunction::OnPreferencesInit, | 316 &MediaGalleriesPrivateGetAllGalleryWatchFunction::OnPreferencesInit, |
| 317 this)); | 317 this)); |
| 318 return true; | 318 return true; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 336 | 336 |
| 337 /////////////////////////////////////////////////////////////////////////////// | 337 /////////////////////////////////////////////////////////////////////////////// |
| 338 // MediaGalleriesPrivateRemoveAllGalleryWatchFunction // | 338 // MediaGalleriesPrivateRemoveAllGalleryWatchFunction // |
| 339 /////////////////////////////////////////////////////////////////////////////// | 339 /////////////////////////////////////////////////////////////////////////////// |
| 340 | 340 |
| 341 MediaGalleriesPrivateRemoveAllGalleryWatchFunction:: | 341 MediaGalleriesPrivateRemoveAllGalleryWatchFunction:: |
| 342 ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction() { | 342 ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction() { |
| 343 } | 343 } |
| 344 | 344 |
| 345 bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() { | 345 bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() { |
| 346 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 346 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 347 if (!render_view_host() || !render_view_host()->GetProcess()) | 347 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 348 return false; | 348 return false; |
| 349 | 349 |
| 350 MediaGalleriesPreferences* preferences = | 350 MediaGalleriesPreferences* preferences = |
| 351 g_browser_process->media_file_system_registry()->GetPreferences( | 351 g_browser_process->media_file_system_registry()->GetPreferences( |
| 352 GetProfile()); | 352 GetProfile()); |
| 353 preferences->EnsureInitialized(base::Bind( | 353 preferences->EnsureInitialized(base::Bind( |
| 354 &MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnPreferencesInit, | 354 &MediaGalleriesPrivateRemoveAllGalleryWatchFunction::OnPreferencesInit, |
| 355 this)); | 355 this)); |
| 356 return true; | 356 return true; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 371 | 371 |
| 372 /////////////////////////////////////////////////////////////////////////////// | 372 /////////////////////////////////////////////////////////////////////////////// |
| 373 // MediaGalleriesPrivateGetHandlersFunction // | 373 // MediaGalleriesPrivateGetHandlersFunction // |
| 374 /////////////////////////////////////////////////////////////////////////////// | 374 /////////////////////////////////////////////////////////////////////////////// |
| 375 | 375 |
| 376 MediaGalleriesPrivateGetHandlersFunction:: | 376 MediaGalleriesPrivateGetHandlersFunction:: |
| 377 ~MediaGalleriesPrivateGetHandlersFunction() { | 377 ~MediaGalleriesPrivateGetHandlersFunction() { |
| 378 } | 378 } |
| 379 | 379 |
| 380 bool MediaGalleriesPrivateGetHandlersFunction::RunImpl() { | 380 bool MediaGalleriesPrivateGetHandlersFunction::RunImpl() { |
| 381 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 381 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 382 | 382 |
| 383 ExtensionService* service = | 383 ExtensionService* service = |
| 384 extensions::ExtensionSystem::Get(GetProfile())->extension_service(); | 384 extensions::ExtensionSystem::Get(GetProfile())->extension_service(); |
| 385 DCHECK(service); | 385 DCHECK(service); |
| 386 | 386 |
| 387 base::ListValue* result_list = new base::ListValue; | 387 base::ListValue* result_list = new base::ListValue; |
| 388 | 388 |
| 389 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); | 389 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); |
| 390 iter != service->extensions()->end(); | 390 iter != service->extensions()->end(); |
| 391 ++iter) { | 391 ++iter) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 413 } | 413 } |
| 414 } | 414 } |
| 415 | 415 |
| 416 SetResult(result_list); | 416 SetResult(result_list); |
| 417 SendResponse(true); | 417 SendResponse(true); |
| 418 | 418 |
| 419 return true; | 419 return true; |
| 420 } | 420 } |
| 421 | 421 |
| 422 } // namespace extensions | 422 } // namespace extensions |
| OLD | NEW |