| 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 // GalleryWatchStateTracker implementation. | 5 // GalleryWatchStateTracker implementation. |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_st
ate_tracker.h" | 7 #include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_st
ate_tracker.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 GalleryWatchStateTracker::GalleryWatchStateTracker(Profile* profile) | 76 GalleryWatchStateTracker::GalleryWatchStateTracker(Profile* profile) |
| 77 : profile_(profile) { | 77 : profile_(profile) { |
| 78 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 78 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 79 DCHECK(profile_); | 79 DCHECK(profile_); |
| 80 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 80 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 81 content::Source<Profile>(profile_)); | 81 content::Source<Profile>(profile_)); |
| 82 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 82 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 83 content::Source<Profile>(profile_)); | 83 content::Source<Profile>(profile_)); |
| 84 MediaGalleriesPreferences* preferences = | 84 MediaGalleriesPreferences* preferences = |
| 85 g_browser_process->media_file_system_registry()->GetPreferences( | 85 g_browser_process->media_file_system_registry()->GetPreferences(profile); |
| 86 profile); | 86 DCHECK(preferences->IsInitialized()); |
| 87 preferences->AddGalleryChangeObserver(this); | 87 preferences->AddGalleryChangeObserver(this); |
| 88 } | 88 } |
| 89 | 89 |
| 90 GalleryWatchStateTracker::~GalleryWatchStateTracker() { | 90 GalleryWatchStateTracker::~GalleryWatchStateTracker() { |
| 91 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 91 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 92 MediaGalleriesPreferences* preferences = | 92 MediaGalleriesPreferences* preferences = |
| 93 g_browser_process->media_file_system_registry()->GetPreferences( | 93 g_browser_process->media_file_system_registry()->GetPreferences(profile_); |
| 94 profile_); | 94 DCHECK(preferences->IsInitialized()); |
| 95 preferences->RemoveGalleryChangeObserver(this); | 95 preferences->RemoveGalleryChangeObserver(this); |
| 96 } | 96 } |
| 97 | 97 |
| 98 // static | 98 // static |
| 99 GalleryWatchStateTracker* GalleryWatchStateTracker::GetForProfile( | 99 GalleryWatchStateTracker* GalleryWatchStateTracker::GetForProfile( |
| 100 Profile* profile) { | 100 Profile* profile) { |
| 101 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 101 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 102 #if defined(OS_WIN) | 102 #if defined(OS_WIN) |
| 103 // Gallery watch operation is supported only on windows. | 103 // Gallery watch operation is supported only on windows. |
| 104 // Please refer to crbug.com/144491 for more details. | 104 // Please refer to crbug.com/144491 for more details. |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 kRegisteredGalleryWatchers, | 253 kRegisteredGalleryWatchers, |
| 254 WatchedGalleryIdsToValue(gallery_ids).PassAs<base::Value>()); | 254 WatchedGalleryIdsToValue(gallery_ids).PassAs<base::Value>()); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void GalleryWatchStateTracker::ReadFromStorage( | 257 void GalleryWatchStateTracker::ReadFromStorage( |
| 258 const std::string& extension_id, | 258 const std::string& extension_id, |
| 259 scoped_ptr<base::Value> value) { | 259 scoped_ptr<base::Value> value) { |
| 260 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 260 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 261 MediaGalleriesPreferences* preferences = | 261 MediaGalleriesPreferences* preferences = |
| 262 g_browser_process->media_file_system_registry()->GetPreferences(profile_); | 262 g_browser_process->media_file_system_registry()->GetPreferences(profile_); |
| 263 DCHECK(preferences->IsInitialized()); |
| 263 base::ListValue* list = NULL; | 264 base::ListValue* list = NULL; |
| 264 if (!value.get() || !value->GetAsList(&list)) | 265 if (!value.get() || !value->GetAsList(&list)) |
| 265 return; | 266 return; |
| 266 MediaGalleryPrefIdSet gallery_ids = WatchedGalleryIdsFromValue(list); | 267 MediaGalleryPrefIdSet gallery_ids = WatchedGalleryIdsFromValue(list); |
| 267 if (gallery_ids.empty()) | 268 if (gallery_ids.empty()) |
| 268 return; | 269 return; |
| 269 | 270 |
| 270 for (MediaGalleryPrefIdSet::const_iterator id_iter = gallery_ids.begin(); | 271 for (MediaGalleryPrefIdSet::const_iterator id_iter = gallery_ids.begin(); |
| 271 id_iter != gallery_ids.end(); ++id_iter) { | 272 id_iter != gallery_ids.end(); ++id_iter) { |
| 272 watched_extensions_map_[extension_id][*id_iter] = false; | 273 watched_extensions_map_[extension_id][*id_iter] = false; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 const std::string& extension_id, | 349 const std::string& extension_id, |
| 349 MediaGalleryPrefId gallery_id) { | 350 MediaGalleryPrefId gallery_id) { |
| 350 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 351 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 351 if (HasGalleryWatchInfo(extension_id, gallery_id, true)) | 352 if (HasGalleryWatchInfo(extension_id, gallery_id, true)) |
| 352 return false; | 353 return false; |
| 353 watched_extensions_map_[extension_id][gallery_id] = true; | 354 watched_extensions_map_[extension_id][gallery_id] = true; |
| 354 return true; | 355 return true; |
| 355 } | 356 } |
| 356 | 357 |
| 357 } // namespace extensions | 358 } // namespace extensions |
| OLD | NEW |