| 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/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/lazy_instance.h" |
| 10 #include "base/location.h" | 11 #include "base/location.h" |
| 11 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_ma
nager.h" | 14 #include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_ma
nager.h" |
| 14 #include "chrome/browser/extensions/api/media_galleries_private/media_galleries_
private_api_factory.h" | |
| 15 #include "chrome/browser/extensions/api/media_galleries_private/media_galleries_
private_event_router.h" | 15 #include "chrome/browser/extensions/api/media_galleries_private/media_galleries_
private_event_router.h" |
| 16 #include "chrome/browser/extensions/api/media_galleries_private/media_gallery_ex
tension_notification_observer.h" | 16 #include "chrome/browser/extensions/api/media_galleries_private/media_gallery_ex
tension_notification_observer.h" |
| 17 #include "chrome/browser/extensions/event_names.h" | 17 #include "chrome/browser/extensions/event_names.h" |
| 18 #include "chrome/browser/extensions/event_router.h" | 18 #include "chrome/browser/extensions/event_router.h" |
| 19 #include "chrome/browser/extensions/extension_function.h" | 19 #include "chrome/browser/extensions/extension_function.h" |
| 20 #include "chrome/browser/extensions/extension_system.h" | 20 #include "chrome/browser/extensions/extension_system.h" |
| 21 #include "chrome/browser/media_gallery/media_file_system_registry.h" | 21 #include "chrome/browser/media_gallery/media_file_system_registry.h" |
| 22 #include "chrome/browser/media_gallery/media_galleries_preferences.h" | 22 #include "chrome/browser/media_gallery/media_galleries_preferences.h" |
| 23 #include "chrome/browser/system_monitor/media_storage_util.h" | 23 #include "chrome/browser/system_monitor/media_storage_util.h" |
| 24 #include "chrome/common/extensions/api/media_galleries_private.h" | 24 #include "chrome/common/extensions/api/media_galleries_private.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 MediaGalleriesPrivateAPI::~MediaGalleriesPrivateAPI() { | 122 MediaGalleriesPrivateAPI::~MediaGalleriesPrivateAPI() { |
| 123 } | 123 } |
| 124 | 124 |
| 125 void MediaGalleriesPrivateAPI::Shutdown() { | 125 void MediaGalleriesPrivateAPI::Shutdown() { |
| 126 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 126 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
| 127 content::BrowserThread::PostTask( | 127 content::BrowserThread::PostTask( |
| 128 content::BrowserThread::FILE, FROM_HERE, | 128 content::BrowserThread::FILE, FROM_HERE, |
| 129 base::Bind(&HandleProfileShutdownOnFileThread, profile_)); | 129 base::Bind(&HandleProfileShutdownOnFileThread, profile_)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 static base::LazyInstance<ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI> > |
| 133 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 134 |
| 135 // static |
| 136 ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>* |
| 137 MediaGalleriesPrivateAPI::GetFactoryInstance() { |
| 138 return &g_factory.Get(); |
| 139 } |
| 140 |
| 141 // static |
| 142 MediaGalleriesPrivateAPI* MediaGalleriesPrivateAPI::Get(Profile* profile) { |
| 143 return |
| 144 ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>::GetForProfile(profile); |
| 145 } |
| 146 |
| 132 void MediaGalleriesPrivateAPI::OnListenerAdded( | 147 void MediaGalleriesPrivateAPI::OnListenerAdded( |
| 133 const EventListenerInfo& details) { | 148 const EventListenerInfo& details) { |
| 134 // Try to initialize the event router for the listener. If | 149 // Try to initialize the event router for the listener. If |
| 135 // MediaGalleriesPrivateAPI::GetEventRouter() was called before adding | 150 // MediaGalleriesPrivateAPI::GetEventRouter() was called before adding |
| 136 // the listener, router would be initialized. | 151 // the listener, router would be initialized. |
| 137 MaybeInitializeEventRouter(); | 152 MaybeInitializeEventRouter(); |
| 138 } | 153 } |
| 139 | 154 |
| 140 MediaGalleriesPrivateEventRouter* MediaGalleriesPrivateAPI::GetEventRouter() { | 155 MediaGalleriesPrivateEventRouter* MediaGalleriesPrivateAPI::GetEventRouter() { |
| 141 MaybeInitializeEventRouter(); | 156 MaybeInitializeEventRouter(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 static_cast<uint64>(params->gallery_id); | 191 static_cast<uint64>(params->gallery_id); |
| 177 FilePath gallery_file_path( | 192 FilePath gallery_file_path( |
| 178 GetGalleryAbsolutePath(gallery_pref_id, profile_, GetExtension())); | 193 GetGalleryAbsolutePath(gallery_pref_id, profile_, GetExtension())); |
| 179 if (gallery_file_path.empty()) { | 194 if (gallery_file_path.empty()) { |
| 180 error_ = kInvalidGalleryIDError; | 195 error_ = kInvalidGalleryIDError; |
| 181 return false; | 196 return false; |
| 182 } | 197 } |
| 183 | 198 |
| 184 #if defined(OS_WIN) | 199 #if defined(OS_WIN) |
| 185 MediaGalleriesPrivateEventRouter* router = | 200 MediaGalleriesPrivateEventRouter* router = |
| 186 MediaGalleriesPrivateAPIFactory::GetForProfile( | 201 MediaGalleriesPrivateAPI::Get(profile_)->GetEventRouter(); |
| 187 profile_)->GetEventRouter(); | |
| 188 DCHECK(router); | 202 DCHECK(router); |
| 189 content::BrowserThread::PostTaskAndReplyWithResult( | 203 content::BrowserThread::PostTaskAndReplyWithResult( |
| 190 content::BrowserThread::FILE, | 204 content::BrowserThread::FILE, |
| 191 FROM_HERE, | 205 FROM_HERE, |
| 192 base::Bind(&SetupGalleryWatchOnFileThread, | 206 base::Bind(&SetupGalleryWatchOnFileThread, |
| 193 profile_, | 207 profile_, |
| 194 gallery_pref_id, | 208 gallery_pref_id, |
| 195 gallery_file_path, | 209 gallery_file_path, |
| 196 extension_id(), | 210 extension_id(), |
| 197 router->AsWeakPtr()), | 211 router->AsWeakPtr()), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 content::BrowserThread::FILE, FROM_HERE, | 272 content::BrowserThread::FILE, FROM_HERE, |
| 259 base::Bind(&RemoveGalleryWatchOnFileThread, | 273 base::Bind(&RemoveGalleryWatchOnFileThread, |
| 260 profile_, | 274 profile_, |
| 261 gallery_file_path, | 275 gallery_file_path, |
| 262 extension_id())); | 276 extension_id())); |
| 263 #endif | 277 #endif |
| 264 return true; | 278 return true; |
| 265 } | 279 } |
| 266 | 280 |
| 267 } // namespace extensions | 281 } // namespace extensions |
| OLD | NEW |