| OLD | NEW |
| 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 "content/browser/webui/url_data_manager.h" | 5 #include "content/browser/webui/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/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 context->SetUserData(kURLDataManagerKeyName, new URLDataManager(context)); | 32 context->SetUserData(kURLDataManagerKeyName, new URLDataManager(context)); |
| 33 } | 33 } |
| 34 return static_cast<URLDataManager*>( | 34 return static_cast<URLDataManager*>( |
| 35 context->GetUserData(kURLDataManagerKeyName)); | 35 context->GetUserData(kURLDataManagerKeyName)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // 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. |
| 39 static void AddDataSourceOnIOThread( | 39 static void AddDataSourceOnIOThread( |
| 40 ResourceContext* resource_context, | 40 ResourceContext* resource_context, |
| 41 scoped_refptr<URLDataSourceImpl> data_source) { | 41 scoped_refptr<URLDataSourceImpl> data_source) { |
| 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 42 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 43 GetURLDataManagerForResourceContext(resource_context)->AddDataSource( | 43 GetURLDataManagerForResourceContext(resource_context)->AddDataSource( |
| 44 data_source.get()); | 44 data_source.get()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 // static | 49 // static |
| 50 URLDataManager::URLDataSources* URLDataManager::data_sources_ = NULL; | 50 URLDataManager::URLDataSources* URLDataManager::data_sources_ = NULL; |
| 51 | 51 |
| 52 URLDataManager::URLDataManager(BrowserContext* browser_context) | 52 URLDataManager::URLDataManager(BrowserContext* browser_context) |
| 53 : browser_context_(browser_context) { | 53 : browser_context_(browser_context) { |
| 54 } | 54 } |
| 55 | 55 |
| 56 URLDataManager::~URLDataManager() { | 56 URLDataManager::~URLDataManager() { |
| 57 } | 57 } |
| 58 | 58 |
| 59 void URLDataManager::AddDataSource(URLDataSourceImpl* source) { | 59 void URLDataManager::AddDataSource(URLDataSourceImpl* source) { |
| 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 60 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 61 BrowserThread::PostTask( | 61 BrowserThread::PostTask( |
| 62 BrowserThread::IO, FROM_HERE, | 62 BrowserThread::IO, FROM_HERE, |
| 63 base::Bind(&AddDataSourceOnIOThread, | 63 base::Bind(&AddDataSourceOnIOThread, |
| 64 browser_context_->GetResourceContext(), | 64 browser_context_->GetResourceContext(), |
| 65 make_scoped_refptr(source))); | 65 make_scoped_refptr(source))); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // static | 68 // static |
| 69 void URLDataManager::DeleteDataSources() { | 69 void URLDataManager::DeleteDataSources() { |
| 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 70 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 71 URLDataSources sources; | 71 URLDataSources sources; |
| 72 { | 72 { |
| 73 base::AutoLock lock(g_delete_lock.Get()); | 73 base::AutoLock lock(g_delete_lock.Get()); |
| 74 if (!data_sources_) | 74 if (!data_sources_) |
| 75 return; | 75 return; |
| 76 data_sources_->swap(sources); | 76 data_sources_->swap(sources); |
| 77 } | 77 } |
| 78 for (size_t i = 0; i < sources.size(); ++i) | 78 for (size_t i = 0; i < sources.size(); ++i) |
| 79 delete sources[i]; | 79 delete sources[i]; |
| 80 } | 80 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 bool URLDataManager::IsScheduledForDeletion( | 124 bool URLDataManager::IsScheduledForDeletion( |
| 125 const URLDataSourceImpl* data_source) { | 125 const URLDataSourceImpl* data_source) { |
| 126 base::AutoLock lock(g_delete_lock.Get()); | 126 base::AutoLock lock(g_delete_lock.Get()); |
| 127 if (!data_sources_) | 127 if (!data_sources_) |
| 128 return false; | 128 return false; |
| 129 return std::find(data_sources_->begin(), data_sources_->end(), data_source) != | 129 return std::find(data_sources_->begin(), data_sources_->end(), data_source) != |
| 130 data_sources_->end(); | 130 data_sources_->end(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 } // namespace content | 133 } // namespace content |
| OLD | NEW |