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

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

Issue 166053003: Move ProfileKeyedAPI implementations to take BrowserContext in the constructor (part 2). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: | Created 6 years, 10 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"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 return true; 74 return true;
75 } 75 }
76 76
77 } // namespace 77 } // namespace
78 78
79 79
80 /////////////////////////////////////////////////////////////////////////////// 80 ///////////////////////////////////////////////////////////////////////////////
81 // MediaGalleriesPrivateAPI // 81 // MediaGalleriesPrivateAPI //
82 /////////////////////////////////////////////////////////////////////////////// 82 ///////////////////////////////////////////////////////////////////////////////
83 83
84 MediaGalleriesPrivateAPI::MediaGalleriesPrivateAPI(Profile* profile) 84 MediaGalleriesPrivateAPI::MediaGalleriesPrivateAPI(
85 : profile_(profile), 85 content::BrowserContext* context)
86 weak_ptr_factory_(this) { 86 : profile_(Profile::FromBrowserContext(context)), weak_ptr_factory_(this) {
87 DCHECK(profile_); 87 DCHECK(profile_);
88 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 88 EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router();
89 event_router->RegisterObserver(
89 this, media_galleries_private::OnDeviceAttached::kEventName); 90 this, media_galleries_private::OnDeviceAttached::kEventName);
90 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 91 event_router->RegisterObserver(
91 this, media_galleries_private::OnDeviceDetached::kEventName); 92 this, media_galleries_private::OnDeviceDetached::kEventName);
92 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( 93 event_router->RegisterObserver(
93 this, media_galleries_private::OnGalleryChanged::kEventName); 94 this, media_galleries_private::OnGalleryChanged::kEventName);
94 } 95 }
95 96
96 MediaGalleriesPrivateAPI::~MediaGalleriesPrivateAPI() { 97 MediaGalleriesPrivateAPI::~MediaGalleriesPrivateAPI() {
97 } 98 }
98 99
99 void MediaGalleriesPrivateAPI::Shutdown() { 100 void MediaGalleriesPrivateAPI::Shutdown() {
100 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); 101 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
101 weak_ptr_factory_.InvalidateWeakPtrs(); 102 weak_ptr_factory_.InvalidateWeakPtrs();
102 content::BrowserThread::PostTask( 103 content::BrowserThread::PostTask(
103 content::BrowserThread::FILE, FROM_HERE, 104 content::BrowserThread::FILE, FROM_HERE,
104 base::Bind(&HandleProfileShutdownOnFileThread, profile_)); 105 base::Bind(&HandleProfileShutdownOnFileThread, profile_));
105 } 106 }
106 107
107 static base::LazyInstance<ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI> > 108 static base::LazyInstance<ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI> >
108 g_factory = LAZY_INSTANCE_INITIALIZER; 109 g_factory = LAZY_INSTANCE_INITIALIZER;
109 110
110 // static 111 // static
111 ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>* 112 ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>*
112 MediaGalleriesPrivateAPI::GetFactoryInstance() { 113 MediaGalleriesPrivateAPI::GetFactoryInstance() {
113 return g_factory.Pointer(); 114 return g_factory.Pointer();
114 } 115 }
115 116
116 // static 117 // static
117 MediaGalleriesPrivateAPI* MediaGalleriesPrivateAPI::Get(Profile* profile) { 118 MediaGalleriesPrivateAPI* MediaGalleriesPrivateAPI::Get(
118 return 119 content::BrowserContext* context) {
119 ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>::GetForProfile(profile); 120 return ProfileKeyedAPIFactory<MediaGalleriesPrivateAPI>::GetForProfile(
121 context);
120 } 122 }
121 123
122 void MediaGalleriesPrivateAPI::OnListenerAdded( 124 void MediaGalleriesPrivateAPI::OnListenerAdded(
123 const EventListenerInfo& details) { 125 const EventListenerInfo& details) {
124 // Make sure MediaGalleriesPreferences is initialized. After that, 126 // Make sure MediaGalleriesPreferences is initialized. After that,
125 // try to initialize the event router for the listener. 127 // try to initialize the event router for the listener.
126 // This method is called synchronously with the message handler for the 128 // This method is called synchronously with the message handler for the
127 // JS invocation. 129 // JS invocation.
128 130
129 MediaGalleriesPreferences* preferences = 131 MediaGalleriesPreferences* preferences =
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 418 }
417 } 419 }
418 420
419 SetResult(result_list); 421 SetResult(result_list);
420 SendResponse(true); 422 SendResponse(true);
421 423
422 return true; 424 return true;
423 } 425 }
424 426
425 } // namespace extensions 427 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698