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

Side by Side Diff: chrome/browser/ui/webui/chrome_url_data_manager.cc

Issue 8590003: chrome: Remove 11 exit time destructors and 4 static initializers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: no gyp changes :-( Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ui/webui/chrome_url_data_manager.h" 5 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
11 #include "base/lazy_instance.h"
11 #include "base/memory/ref_counted_memory.h" 12 #include "base/memory/ref_counted_memory.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h" 14 #include "base/message_loop.h"
14 #include "base/string_util.h" 15 #include "base/string_util.h"
15 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "chrome/browser/net/chrome_url_request_context.h" 18 #include "chrome/browser/net/chrome_url_request_context.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" 20 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "grit/platform_locale_settings.h" 22 #include "grit/platform_locale_settings.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 24
24 #if defined(OS_WIN) 25 #if defined(OS_WIN)
25 #include "base/win/windows_version.h" 26 #include "base/win/windows_version.h"
26 #endif 27 #endif
27 28
28 using content::BrowserThread; 29 using content::BrowserThread;
29 30
30 // static 31 static base::LazyInstance<base::Lock,
31 base::Lock ChromeURLDataManager::delete_lock_; 32 base::LeakyLazyInstanceTraits<base::Lock> >
33 g_delete_lock = LAZY_INSTANCE_INITIALIZER;
32 34
33 // static 35 // static
34 ChromeURLDataManager::DataSources* ChromeURLDataManager::data_sources_ = NULL; 36 ChromeURLDataManager::DataSources* ChromeURLDataManager::data_sources_ = NULL;
35 37
36 // Invoked on the IO thread to do the actual adding of the DataSource. 38 // Invoked on the IO thread to do the actual adding of the DataSource.
37 static void AddDataSourceOnIOThread( 39 static void AddDataSourceOnIOThread(
38 const base::Callback<ChromeURLDataManagerBackend*(void)>& backend, 40 const base::Callback<ChromeURLDataManagerBackend*(void)>& backend,
39 scoped_refptr<ChromeURLDataManager::DataSource> data_source) { 41 scoped_refptr<ChromeURLDataManager::DataSource> data_source) {
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
41 backend.Run()->AddDataSource(data_source.get()); 43 backend.Run()->AddDataSource(data_source.get());
(...skipping 13 matching lines...) Expand all
55 BrowserThread::IO, FROM_HERE, 57 BrowserThread::IO, FROM_HERE,
56 base::Bind(&AddDataSourceOnIOThread, 58 base::Bind(&AddDataSourceOnIOThread,
57 backend_, make_scoped_refptr(source))); 59 backend_, make_scoped_refptr(source)));
58 } 60 }
59 61
60 // static 62 // static
61 void ChromeURLDataManager::DeleteDataSources() { 63 void ChromeURLDataManager::DeleteDataSources() {
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
63 DataSources sources; 65 DataSources sources;
64 { 66 {
65 base::AutoLock lock(delete_lock_); 67 base::AutoLock lock(g_delete_lock.Get());
66 if (!data_sources_) 68 if (!data_sources_)
67 return; 69 return;
68 data_sources_->swap(sources); 70 data_sources_->swap(sources);
69 } 71 }
70 for (size_t i = 0; i < sources.size(); ++i) 72 for (size_t i = 0; i < sources.size(); ++i)
71 delete sources[i]; 73 delete sources[i];
72 } 74 }
73 75
74 // static 76 // static
75 void ChromeURLDataManager::DeleteDataSource(const DataSource* data_source) { 77 void ChromeURLDataManager::DeleteDataSource(const DataSource* data_source) {
76 // Invoked when a DataSource is no longer referenced and needs to be deleted. 78 // Invoked when a DataSource is no longer referenced and needs to be deleted.
77 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { 79 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
78 // We're on the UI thread, delete right away. 80 // We're on the UI thread, delete right away.
79 delete data_source; 81 delete data_source;
80 return; 82 return;
81 } 83 }
82 84
83 // We're not on the UI thread, add the DataSource to the list of DataSources 85 // We're not on the UI thread, add the DataSource to the list of DataSources
84 // to delete. 86 // to delete.
85 bool schedule_delete = false; 87 bool schedule_delete = false;
86 { 88 {
87 base::AutoLock lock(delete_lock_); 89 base::AutoLock lock(g_delete_lock.Get());
88 if (!data_sources_) 90 if (!data_sources_)
89 data_sources_ = new DataSources(); 91 data_sources_ = new DataSources();
90 schedule_delete = data_sources_->empty(); 92 schedule_delete = data_sources_->empty();
91 data_sources_->push_back(data_source); 93 data_sources_->push_back(data_source);
92 } 94 }
93 if (schedule_delete) { 95 if (schedule_delete) {
94 // Schedule a task to delete the DataSource back on the UI thread. 96 // Schedule a task to delete the DataSource back on the UI thread.
95 BrowserThread::PostTask( 97 BrowserThread::PostTask(
96 BrowserThread::UI, FROM_HERE, 98 BrowserThread::UI, FROM_HERE,
97 base::Bind(&ChromeURLDataManager::DeleteDataSources)); 99 base::Bind(&ChromeURLDataManager::DeleteDataSources));
98 } 100 }
99 } 101 }
100 102
101 // static 103 // static
102 bool ChromeURLDataManager::IsScheduledForDeletion( 104 bool ChromeURLDataManager::IsScheduledForDeletion(
103 const DataSource* data_source) { 105 const DataSource* data_source) {
104 base::AutoLock lock(delete_lock_); 106 base::AutoLock lock(g_delete_lock.Get());
105 if (!data_sources_) 107 if (!data_sources_)
106 return false; 108 return false;
107 return std::find(data_sources_->begin(), data_sources_->end(), data_source) != 109 return std::find(data_sources_->begin(), data_sources_->end(), data_source) !=
108 data_sources_->end(); 110 data_sources_->end();
109 } 111 }
110 112
111 ChromeURLDataManager::DataSource::DataSource(const std::string& source_name, 113 ChromeURLDataManager::DataSource::DataSource(const std::string& source_name,
112 MessageLoop* message_loop) 114 MessageLoop* message_loop)
113 : source_name_(source_name), 115 : source_name_(source_name),
114 message_loop_(message_loop), 116 message_loop_(message_loop),
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 base::i18n::IsRTL() ? "rtl" : "ltr"); 173 base::i18n::IsRTL() ? "rtl" : "ltr");
172 } 174 }
173 175
174 void ChromeURLDataManager::DataSource::SendResponseOnIOThread( 176 void ChromeURLDataManager::DataSource::SendResponseOnIOThread(
175 int request_id, 177 int request_id,
176 scoped_refptr<RefCountedMemory> bytes) { 178 scoped_refptr<RefCountedMemory> bytes) {
177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
178 if (backend_) 180 if (backend_)
179 backend_->DataAvailable(request_id, bytes); 181 backend_->DataAvailable(request_id, bytes);
180 } 182 }
OLDNEW
« chrome/browser/ui/browser_list.cc ('K') | « chrome/browser/ui/webui/chrome_url_data_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698