| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | |
| 12 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 13 #include "base/task.h" | 12 #include "base/task.h" |
| 14 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
| 15 | 14 |
| 16 class ChromeURLDataManagerBackend; | 15 class ChromeURLDataManagerBackend; |
| 17 class FilePath; | 16 class FilePath; |
| 18 class MessageLoop; | 17 class MessageLoop; |
| 19 class Profile; | 18 class Profile; |
| 20 class RefCountedMemory; | 19 class RefCountedMemory; |
| 21 | 20 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // This field is set and maintained by ChromeURLDataManagerBackend. It is | 133 // This field is set and maintained by ChromeURLDataManagerBackend. It is |
| 135 // set when the DataSource is added, and unset if the DataSource is removed. | 134 // set when the DataSource is added, and unset if the DataSource is removed. |
| 136 // A DataSource can be removed in two ways: the ChromeURLDataManagerBackend | 135 // A DataSource can be removed in two ways: the ChromeURLDataManagerBackend |
| 137 // is deleted, or another DataSource is registered with the same | 136 // is deleted, or another DataSource is registered with the same |
| 138 // name. backend_ should only be accessed on the IO thread. | 137 // name. backend_ should only be accessed on the IO thread. |
| 139 // This reference can't be via a scoped_refptr else there would be a cycle | 138 // This reference can't be via a scoped_refptr else there would be a cycle |
| 140 // between the backend and data source. | 139 // between the backend and data source. |
| 141 ChromeURLDataManagerBackend* backend_; | 140 ChromeURLDataManagerBackend* backend_; |
| 142 }; | 141 }; |
| 143 | 142 |
| 144 explicit ChromeURLDataManager( | 143 explicit ChromeURLDataManager(Profile* profile); |
| 145 const base::Callback<ChromeURLDataManagerBackend*(void)>& backend); | |
| 146 ~ChromeURLDataManager(); | 144 ~ChromeURLDataManager(); |
| 147 | 145 |
| 148 // Adds a DataSource to the collection of data sources. This *must* be invoked | 146 // Adds a DataSource to the collection of data sources. This *must* be invoked |
| 149 // on the UI thread. | 147 // on the UI thread. |
| 150 // | 148 // |
| 151 // If |AddDataSource| is called more than once for a particular name it will | 149 // If |AddDataSource| is called more than once for a particular name it will |
| 152 // release the old |DataSource|, most likely resulting in it getting deleted | 150 // release the old |DataSource|, most likely resulting in it getting deleted |
| 153 // as there are no other references to it. |DataSource| uses the | 151 // as there are no other references to it. |DataSource| uses the |
| 154 // |DeleteOnUIThread| trait to insure that the destructor is called on the UI | 152 // |DeleteOnUIThread| trait to insure that the destructor is called on the UI |
| 155 // thread. This is necessary as some |DataSource|s notably |FileIconSource| | 153 // thread. This is necessary as some |DataSource|s notably |FileIconSource| |
| (...skipping 10 matching lines...) Expand all Loading... |
| 166 | 164 |
| 167 // If invoked on the UI thread the DataSource is deleted immediatlye, | 165 // If invoked on the UI thread the DataSource is deleted immediatlye, |
| 168 // otherwise it is added to |data_sources_| and a task is scheduled to handle | 166 // otherwise it is added to |data_sources_| and a task is scheduled to handle |
| 169 // deletion on the UI thread. See note abouve DeleteDataSource for more info. | 167 // deletion on the UI thread. See note abouve DeleteDataSource for more info. |
| 170 static void DeleteDataSource(const DataSource* data_source); | 168 static void DeleteDataSource(const DataSource* data_source); |
| 171 | 169 |
| 172 // Returns true if |data_source| is scheduled for deletion (|DeleteDataSource| | 170 // Returns true if |data_source| is scheduled for deletion (|DeleteDataSource| |
| 173 // was invoked). | 171 // was invoked). |
| 174 static bool IsScheduledForDeletion(const DataSource* data_source); | 172 static bool IsScheduledForDeletion(const DataSource* data_source); |
| 175 | 173 |
| 176 // A callback that returns the ChromeURLDataManagerBackend. Only accessible on | 174 Profile* profile_; |
| 177 // the IO thread. This is necessary because ChromeURLDataManager is created on | |
| 178 // the UI thread, but ChromeURLDataManagerBackend lives on the IO thread. | |
| 179 const base::Callback<ChromeURLDataManagerBackend*(void)> backend_; | |
| 180 | 175 |
| 181 // Lock used when accessing |data_sources_|. | 176 // Lock used when accessing |data_sources_|. |
| 182 static base::Lock delete_lock_; | 177 static base::Lock delete_lock_; |
| 183 | 178 |
| 184 // |data_sources_| that are no longer referenced and scheduled for deletion. | 179 // |data_sources_| that are no longer referenced and scheduled for deletion. |
| 185 static DataSources* data_sources_; | 180 static DataSources* data_sources_; |
| 186 | 181 |
| 187 DISALLOW_COPY_AND_ASSIGN(ChromeURLDataManager); | 182 DISALLOW_COPY_AND_ASSIGN(ChromeURLDataManager); |
| 188 }; | 183 }; |
| 189 | 184 |
| 190 #endif // CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ | 185 #endif // CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ |
| OLD | NEW |