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 #include "chrome/browser/extensions/test_extension_prefs.h" | 5 #include "chrome/browser/extensions/test_extension_prefs.h" |
6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
7 #include "base/file_util.h" | 9 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
10 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
11 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
12 #include "base/test/signaling_task.h" | |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "chrome/browser/extensions/extension_pref_store.h" | 15 #include "chrome/browser/extensions/extension_pref_store.h" |
15 #include "chrome/browser/extensions/extension_pref_value_map.h" | 16 #include "chrome/browser/extensions/extension_pref_value_map.h" |
16 #include "chrome/browser/extensions/extension_prefs.h" | 17 #include "chrome/browser/extensions/extension_prefs.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
18 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 19 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
19 #include "chrome/browser/prefs/pref_value_store.h" | 20 #include "chrome/browser/prefs/pref_value_store.h" |
20 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
21 #include "chrome/common/extensions/extension_constants.h" | 22 #include "chrome/common/extensions/extension_constants.h" |
22 #include "chrome/common/json_pref_store.h" | 23 #include "chrome/common/json_pref_store.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 void TestExtensionPrefs::RecreateExtensionPrefs() { | 67 void TestExtensionPrefs::RecreateExtensionPrefs() { |
67 // We persist and reload the PrefService's PrefStores because this process | 68 // We persist and reload the PrefService's PrefStores because this process |
68 // deletes all empty dictionaries. The ExtensionPrefs implementation | 69 // deletes all empty dictionaries. The ExtensionPrefs implementation |
69 // needs to be able to handle this situation. | 70 // needs to be able to handle this situation. |
70 if (pref_service_.get()) { | 71 if (pref_service_.get()) { |
71 // The PrefService writes its persistent file on the file thread, so we | 72 // The PrefService writes its persistent file on the file thread, so we |
72 // need to wait for any pending I/O to complete before creating a new | 73 // need to wait for any pending I/O to complete before creating a new |
73 // PrefService. | 74 // PrefService. |
74 base::WaitableEvent io_finished(false, false); | 75 base::WaitableEvent io_finished(false, false); |
75 pref_service_->SavePersistentPrefs(); | 76 pref_service_->SavePersistentPrefs(); |
76 EXPECT_TRUE(BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 77 EXPECT_TRUE(BrowserThread::PostTask( |
77 new base::SignalingTask(&io_finished))); | 78 BrowserThread::FILE, |
| 79 FROM_HERE, |
| 80 base::Bind(&base::WaitableEvent::Signal, |
| 81 base::Unretained(&io_finished)))); |
78 | 82 |
79 // If the FILE thread is in fact the current thread (possible in testing | 83 // If the FILE thread is in fact the current thread (possible in testing |
80 // scenarios), we have to ensure the task has a chance to run. If the FILE | 84 // scenarios), we have to ensure the task has a chance to run. If the FILE |
81 // thread is a different thread, the test must ensure that thread is running | 85 // thread is a different thread, the test must ensure that thread is running |
82 // (otherwise the Wait below will hang). | 86 // (otherwise the Wait below will hang). |
83 MessageLoop::current()->RunAllPending(); | 87 MessageLoop::current()->RunAllPending(); |
84 | 88 |
85 io_finished.Wait(); | 89 io_finished.Wait(); |
86 } | 90 } |
87 | 91 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 153 } |
150 | 154 |
151 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { | 155 PrefService* TestExtensionPrefs::CreateIncognitoPrefService() const { |
152 return pref_service_->CreateIncognitoPrefService( | 156 return pref_service_->CreateIncognitoPrefService( |
153 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); | 157 new ExtensionPrefStore(extension_pref_value_map_.get(), true)); |
154 } | 158 } |
155 | 159 |
156 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) { | 160 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) { |
157 extensions_disabled_ = extensions_disabled; | 161 extensions_disabled_ = extensions_disabled; |
158 } | 162 } |
OLD | NEW |