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

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

Issue 15742010: Use MediaGalleryPreferences directly in GalleryWatchStateTracker interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Get preferences for win call Created 7 years, 7 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 #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"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_ma nager.h" 15 #include "chrome/browser/extensions/api/media_galleries_private/gallery_watch_ma nager.h"
16 #include "chrome/browser/extensions/api/media_galleries_private/media_galleries_ private_event_router.h" 16 #include "chrome/browser/extensions/api/media_galleries_private/media_galleries_ private_event_router.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_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
21 #include "chrome/browser/extensions/extension_system.h" 21 #include "chrome/browser/extensions/extension_system.h"
22 #include "chrome/browser/extensions/media_galleries_handler.h" 22 #include "chrome/browser/extensions/media_galleries_handler.h"
23 #include "chrome/browser/media_galleries/media_file_system_registry.h" 23 #include "chrome/browser/media_galleries/media_file_system_registry.h"
24 #include "chrome/browser/media_galleries/media_galleries_preferences.h" 24 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/storage_monitor/storage_monitor.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/render_view_host.h" 28 #include "content/public/browser/render_view_host.h"
28 29
29 using base::DictionaryValue; 30 using base::DictionaryValue;
30 using base::ListValue; 31 using base::ListValue;
31 32
32 namespace extensions { 33 namespace extensions {
33 34
34 namespace AddGalleryWatch = 35 namespace AddGalleryWatch =
35 extensions::api::media_galleries_private::AddGalleryWatch; 36 extensions::api::media_galleries_private::AddGalleryWatch;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 99 }
99 100
100 } // namespace 101 } // namespace
101 102
102 103
103 /////////////////////////////////////////////////////////////////////////////// 104 ///////////////////////////////////////////////////////////////////////////////
104 // MediaGalleriesPrivateAPI // 105 // MediaGalleriesPrivateAPI //
105 /////////////////////////////////////////////////////////////////////////////// 106 ///////////////////////////////////////////////////////////////////////////////
106 107
107 MediaGalleriesPrivateAPI::MediaGalleriesPrivateAPI(Profile* profile) 108 MediaGalleriesPrivateAPI::MediaGalleriesPrivateAPI(Profile* profile)
108 : profile_(profile), 109 : profile_(profile) {
109 tracker_(profile) {
110 DCHECK(profile_); 110 DCHECK(profile_);
111 (new MediaGalleriesHandlerParser)->Register(); 111 (new MediaGalleriesHandlerParser)->Register();
112 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 112 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
113 this, event_names::kOnAttachEventName); 113 this, event_names::kOnAttachEventName);
114 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 114 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
115 this, event_names::kOnDetachEventName); 115 this, event_names::kOnDetachEventName);
116 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 116 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
117 this, event_names::kOnGalleryChangedEventName); 117 this, event_names::kOnGalleryChangedEventName);
118 } 118 }
119 119
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 MaybeInitializeEventRouter(); 271 MaybeInitializeEventRouter();
272 } 272 }
273 273
274 MediaGalleriesPrivateEventRouter* MediaGalleriesPrivateAPI::GetEventRouter() { 274 MediaGalleriesPrivateEventRouter* MediaGalleriesPrivateAPI::GetEventRouter() {
275 MaybeInitializeEventRouter(); 275 MaybeInitializeEventRouter();
276 return media_galleries_private_event_router_.get(); 276 return media_galleries_private_event_router_.get();
277 } 277 }
278 278
279 GalleryWatchStateTracker* 279 GalleryWatchStateTracker*
280 MediaGalleriesPrivateAPI::GetGalleryWatchStateTracker() { 280 MediaGalleriesPrivateAPI::GetGalleryWatchStateTracker() {
281 return &tracker_; 281 MaybeInitializeEventRouter();
282 return tracker_.get();
282 } 283 }
283 284
284 void MediaGalleriesPrivateAPI::MaybeInitializeEventRouter() { 285 void MediaGalleriesPrivateAPI::MaybeInitializeEventRouter() {
Finnur 2013/05/24 09:27:41 nit: Why not rename this function to include Track
Greg Billock 2013/05/29 16:33:48 Done.
285 if (media_galleries_private_event_router_.get()) 286 if (media_galleries_private_event_router_.get())
286 return; 287 return;
287 media_galleries_private_event_router_.reset( 288 media_galleries_private_event_router_.reset(
288 new MediaGalleriesPrivateEventRouter(profile_)); 289 new MediaGalleriesPrivateEventRouter(profile_));
290 tracker_.reset(
291 new GalleryWatchStateTracker(profile_));
289 } 292 }
290 293
291 /////////////////////////////////////////////////////////////////////////////// 294 ///////////////////////////////////////////////////////////////////////////////
292 // MediaGalleriesPrivateAddGalleryWatchFunction // 295 // MediaGalleriesPrivateAddGalleryWatchFunction //
293 /////////////////////////////////////////////////////////////////////////////// 296 ///////////////////////////////////////////////////////////////////////////////
294 MediaGalleriesPrivateAddGalleryWatchFunction:: 297 MediaGalleriesPrivateAddGalleryWatchFunction::
295 ~MediaGalleriesPrivateAddGalleryWatchFunction() { 298 ~MediaGalleriesPrivateAddGalleryWatchFunction() {
296 } 299 }
297 300
298 bool MediaGalleriesPrivateAddGalleryWatchFunction::RunImpl() { 301 bool MediaGalleriesPrivateAddGalleryWatchFunction::RunImpl() {
299 DCHECK(profile_); 302 DCHECK(profile_);
300 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 303 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
301 if (!render_view_host() || !render_view_host()->GetProcess()) 304 if (!render_view_host() || !render_view_host()->GetProcess())
302 return false; 305 return false;
303 306
304 scoped_ptr<AddGalleryWatch::Params> params( 307 scoped_ptr<AddGalleryWatch::Params> params(
305 AddGalleryWatch::Params::Create(*args_)); 308 AddGalleryWatch::Params::Create(*args_));
306 EXTENSION_FUNCTION_VALIDATE(params.get()); 309 EXTENSION_FUNCTION_VALIDATE(params.get());
310
307 base::FilePath gallery_file_path; 311 base::FilePath gallery_file_path;
308 chrome::MediaGalleryPrefId gallery_pref_id = 0; 312 chrome::MediaGalleryPrefId gallery_pref_id = 0;
309 if (!GetGalleryFilePathAndId(params->gallery_id, profile_, GetExtension(), 313 if (!GetGalleryFilePathAndId(params->gallery_id, profile_, GetExtension(),
310 &gallery_file_path, &gallery_pref_id)) { 314 &gallery_file_path, &gallery_pref_id)) {
311 error_ = kInvalidGalleryIDError; 315 error_ = kInvalidGalleryIDError;
312 return false; 316 return false;
313 } 317 }
314 318
315 #if defined(OS_WIN) 319 #if defined(OS_WIN)
316 MediaGalleriesPrivateEventRouter* router = 320 MediaGalleriesPrivateEventRouter* router =
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 MediaGalleriesPrivateRemoveAllGalleryWatchFunction:: 435 MediaGalleriesPrivateRemoveAllGalleryWatchFunction::
432 ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction() { 436 ~MediaGalleriesPrivateRemoveAllGalleryWatchFunction() {
433 } 437 }
434 438
435 bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() { 439 bool MediaGalleriesPrivateRemoveAllGalleryWatchFunction::RunImpl() {
436 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 440 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
437 #if defined(OS_WIN) 441 #if defined(OS_WIN)
438 if (!render_view_host() || !render_view_host()->GetProcess()) 442 if (!render_view_host() || !render_view_host()->GetProcess())
439 return false; 443 return false;
440 444
445 chrome::MediaFileSystemRegistry* registry =
446 g_browser_process->media_file_system_registry();
447 chrome::MediaGalleriesPreferences* preferences =
448 registry->GetPreferences(profile_);
441 GalleryWatchStateTracker* state_tracker = 449 GalleryWatchStateTracker* state_tracker =
442 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker(); 450 MediaGalleriesPrivateAPI::Get(profile_)->GetGalleryWatchStateTracker();
443 state_tracker->RemoveAllGalleryWatchersForExtension(extension_id()); 451 state_tracker->RemoveAllGalleryWatchersForExtension(
452 extension_id(), preferences);
444 #endif 453 #endif
445 return true; 454 return true;
446 } 455 }
447 456
448 /////////////////////////////////////////////////////////////////////////////// 457 ///////////////////////////////////////////////////////////////////////////////
449 // MediaGalleriesPrivateEjectDeviceFunction // 458 // MediaGalleriesPrivateEjectDeviceFunction //
450 /////////////////////////////////////////////////////////////////////////////// 459 ///////////////////////////////////////////////////////////////////////////////
451 460
452 MediaGalleriesPrivateEjectDeviceFunction:: 461 MediaGalleriesPrivateEjectDeviceFunction::
453 ~MediaGalleriesPrivateEjectDeviceFunction() { 462 ~MediaGalleriesPrivateEjectDeviceFunction() {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 } 553 }
545 } 554 }
546 555
547 SetResult(result_list); 556 SetResult(result_list);
548 SendResponse(true); 557 SendResponse(true);
549 558
550 return true; 559 return true;
551 } 560 }
552 561
553 } // namespace extensions 562 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698