Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: chrome/browser/extensions/api/media_galleries_private/gallery_watch_state_tracker.cc

Issue 24269007: Media Galleries API: Fix MediaGalleriesPreferences finders race. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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);
87 preferences->AddGalleryChangeObserver(this); 86 preferences->AddGalleryChangeObserver(this);
88 } 87 }
89 88
90 GalleryWatchStateTracker::~GalleryWatchStateTracker() { 89 GalleryWatchStateTracker::~GalleryWatchStateTracker() {
91 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 90 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
92 MediaGalleriesPreferences* preferences = 91 MediaGalleriesPreferences* preferences =
93 g_browser_process->media_file_system_registry()->GetPreferences( 92 g_browser_process->media_file_system_registry()->GetPreferences(profile_);
94 profile_);
95 preferences->RemoveGalleryChangeObserver(this); 93 preferences->RemoveGalleryChangeObserver(this);
96 } 94 }
97 95
98 // static 96 // static
99 GalleryWatchStateTracker* GalleryWatchStateTracker::GetForProfile( 97 GalleryWatchStateTracker* GalleryWatchStateTracker::GetForProfile(
100 Profile* profile) { 98 Profile* profile) {
101 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 99 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
102 #if defined(OS_WIN) 100 #if defined(OS_WIN)
103 // Gallery watch operation is supported only on windows. 101 // Gallery watch operation is supported only on windows.
104 // Please refer to crbug.com/144491 for more details. 102 // Please refer to crbug.com/144491 for more details.
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 kRegisteredGalleryWatchers, 251 kRegisteredGalleryWatchers,
254 WatchedGalleryIdsToValue(gallery_ids).PassAs<base::Value>()); 252 WatchedGalleryIdsToValue(gallery_ids).PassAs<base::Value>());
255 } 253 }
256 254
257 void GalleryWatchStateTracker::ReadFromStorage( 255 void GalleryWatchStateTracker::ReadFromStorage(
258 const std::string& extension_id, 256 const std::string& extension_id,
259 scoped_ptr<base::Value> value) { 257 scoped_ptr<base::Value> value) {
260 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 258 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
261 MediaGalleriesPreferences* preferences = 259 MediaGalleriesPreferences* preferences =
262 g_browser_process->media_file_system_registry()->GetPreferences(profile_); 260 g_browser_process->media_file_system_registry()->GetPreferences(profile_);
261 DCHECK(preferences->IsInitialized());
vandebo (ex-Chrome) 2013/09/26 22:42:36 nit: remove
tommycli 2013/09/26 23:53:33 Done.
263 base::ListValue* list = NULL; 262 base::ListValue* list = NULL;
264 if (!value.get() || !value->GetAsList(&list)) 263 if (!value.get() || !value->GetAsList(&list))
265 return; 264 return;
266 MediaGalleryPrefIdSet gallery_ids = WatchedGalleryIdsFromValue(list); 265 MediaGalleryPrefIdSet gallery_ids = WatchedGalleryIdsFromValue(list);
267 if (gallery_ids.empty()) 266 if (gallery_ids.empty())
268 return; 267 return;
269 268
270 for (MediaGalleryPrefIdSet::const_iterator id_iter = gallery_ids.begin(); 269 for (MediaGalleryPrefIdSet::const_iterator id_iter = gallery_ids.begin();
271 id_iter != gallery_ids.end(); ++id_iter) { 270 id_iter != gallery_ids.end(); ++id_iter) {
272 watched_extensions_map_[extension_id][*id_iter] = false; 271 watched_extensions_map_[extension_id][*id_iter] = false;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 const std::string& extension_id, 347 const std::string& extension_id,
349 MediaGalleryPrefId gallery_id) { 348 MediaGalleryPrefId gallery_id) {
350 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 349 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
351 if (HasGalleryWatchInfo(extension_id, gallery_id, true)) 350 if (HasGalleryWatchInfo(extension_id, gallery_id, true))
352 return false; 351 return false;
353 watched_extensions_map_[extension_id][gallery_id] = true; 352 watched_extensions_map_[extension_id][gallery_id] = true;
354 return true; 353 return true;
355 } 354 }
356 355
357 } // namespace extensions 356 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698