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

Side by Side Diff: chrome/browser/chromeos/offline/offline_load_service.cc

Issue 5682008: Make members of Singleton<T> private and only visible to the singleton type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/chromeos/offline/offline_load_service.h" 5 #include "chrome/browser/chromeos/offline/offline_load_service.h"
6 6
7 #include "base/lazy_instance.h"
7 #include "base/ref_counted.h" 8 #include "base/ref_counted.h"
8 #include "base/singleton.h"
9 #include "chrome/browser/browser_thread.h" 9 #include "chrome/browser/browser_thread.h"
10 #include "chrome/browser/tab_contents/navigation_controller.h" 10 #include "chrome/browser/tab_contents/navigation_controller.h"
11 #include "chrome/browser/tab_contents/tab_contents.h" 11 #include "chrome/browser/tab_contents/tab_contents.h"
12 #include "chrome/browser/tab_contents/tab_util.h" 12 #include "chrome/browser/tab_contents/tab_util.h"
13 #include "chrome/common/notification_service.h" 13 #include "chrome/common/notification_service.h"
14 14
15 namespace chromeos { 15 namespace chromeos {
16 16
17 // A utility class that serves a singleton instance of OfflineLoadService. 17 // A utility class that serves a singleton instance of OfflineLoadService.
18 // OfflineLoadSerivce itself cannot be a singleton as it implements 18 // OfflineLoadSerivce itself cannot be a singleton as it implements
19 // RefCount interface. 19 // RefCount interface.
20 class OfflineLoadServiceSingleton { 20 class OfflineLoadServiceSingleton {
21 public: 21 public:
22 chromeos::OfflineLoadService* offline_load_service() { 22 chromeos::OfflineLoadService* offline_load_service() {
23 return offline_load_service_.get(); 23 return offline_load_service_.get();
24 } 24 }
25 25
26 private: 26 private:
27 friend struct DefaultSingletonTraits<OfflineLoadServiceSingleton>; 27 friend struct base::DefaultLazyInstanceTraits<OfflineLoadServiceSingleton>;
28 OfflineLoadServiceSingleton() 28 OfflineLoadServiceSingleton()
29 : offline_load_service_(new chromeos::OfflineLoadService()) {} 29 : offline_load_service_(new chromeos::OfflineLoadService()) {}
30 virtual ~OfflineLoadServiceSingleton() {} 30 virtual ~OfflineLoadServiceSingleton() {}
31 31
32 scoped_refptr<chromeos::OfflineLoadService> offline_load_service_; 32 scoped_refptr<chromeos::OfflineLoadService> offline_load_service_;
33 33
34 DISALLOW_COPY_AND_ASSIGN(OfflineLoadServiceSingleton); 34 DISALLOW_COPY_AND_ASSIGN(OfflineLoadServiceSingleton);
35 }; 35 };
36 36
37 static base::LazyInstance<OfflineLoadServiceSingleton>
38 g_offline_load_service_singleton(base::LINKER_INITIALIZED);
39
37 // static 40 // static
38 OfflineLoadService* OfflineLoadService::Get() { 41 OfflineLoadService* OfflineLoadService::Get() {
39 return Singleton<OfflineLoadServiceSingleton>::get()->offline_load_service(); 42 return g_offline_load_service_singleton.Get().offline_load_service();
40 } 43 }
41 44
42 void OfflineLoadService::Observe(NotificationType type, 45 void OfflineLoadService::Observe(NotificationType type,
43 const NotificationSource& source, 46 const NotificationSource& source,
44 const NotificationDetails& details) { 47 const NotificationDetails& details) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
46 if (type.value == NotificationType::TAB_CLOSED) { 49 if (type.value == NotificationType::TAB_CLOSED) {
47 registrar_.Remove(this, NotificationType::TAB_CLOSED, source); 50 registrar_.Remove(this, NotificationType::TAB_CLOSED, source);
48 NavigationController* tab = Source<NavigationController>(source).ptr(); 51 NavigationController* tab = Source<NavigationController>(source).ptr();
49 BrowserThread::PostTask( 52 BrowserThread::PostTask(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 98
96 void OfflineLoadService::RegisterNotification( 99 void OfflineLoadService::RegisterNotification(
97 NavigationController* navigation_controller) { 100 NavigationController* navigation_controller) {
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
99 registrar_.Add(this, NotificationType::TAB_CLOSED, 102 registrar_.Add(this, NotificationType::TAB_CLOSED,
100 Source<NavigationController>( 103 Source<NavigationController>(
101 navigation_controller)); 104 navigation_controller));
102 } 105 }
103 106
104 } // namespace chromeos 107 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698