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 "chrome/browser/content_settings/content_settings_pref_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/prefs/default_pref_store.h" | 11 #include "base/prefs/default_pref_store.h" |
12 #include "base/prefs/overlay_user_pref_store.h" | 12 #include "base/prefs/overlay_user_pref_store.h" |
13 #include "base/prefs/public/pref_change_registrar.h" | 13 #include "base/prefs/public/pref_change_registrar.h" |
14 #include "base/prefs/public/pref_observer.h" | |
15 #include "base/prefs/testing_pref_store.h" | 14 #include "base/prefs/testing_pref_store.h" |
16 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
17 #include "base/values.h" | 16 #include "base/values.h" |
18 #include "chrome/browser/content_settings/content_settings_mock_observer.h" | 17 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
19 #include "chrome/browser/content_settings/content_settings_utils.h" | 18 #include "chrome/browser/content_settings/content_settings_utils.h" |
20 #include "chrome/browser/prefs/browser_prefs.h" | 19 #include "chrome/browser/prefs/browser_prefs.h" |
21 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
22 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 21 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
23 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 22 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
24 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
(...skipping 21 matching lines...) Expand all Loading... |
46 if (got_lock) | 45 if (got_lock) |
47 provider_->lock_.Release(); | 46 provider_->lock_.Release(); |
48 } | 47 } |
49 private: | 48 private: |
50 PrefProvider* provider_; | 49 PrefProvider* provider_; |
51 DISALLOW_COPY_AND_ASSIGN(DeadlockCheckerThread); | 50 DISALLOW_COPY_AND_ASSIGN(DeadlockCheckerThread); |
52 }; | 51 }; |
53 | 52 |
54 // A helper for observing an preference changes and testing whether | 53 // A helper for observing an preference changes and testing whether |
55 // |PrefProvider| holds a lock when the preferences change. | 54 // |PrefProvider| holds a lock when the preferences change. |
56 class DeadlockCheckerObserver : public PrefObserver { | 55 class DeadlockCheckerObserver { |
57 public: | 56 public: |
58 // |DeadlockCheckerObserver| doesn't take the ownership of |prefs| or | 57 // |DeadlockCheckerObserver| doesn't take the ownership of |prefs| or |
59 // ||provider|. | 58 // ||provider|. |
60 DeadlockCheckerObserver(PrefService* prefs, PrefProvider* provider) | 59 DeadlockCheckerObserver(PrefService* prefs, PrefProvider* provider) |
61 : provider_(provider), | 60 : provider_(provider), |
62 notification_received_(false) { | 61 notification_received_(false) { |
63 pref_change_registrar_.Init(prefs); | 62 pref_change_registrar_.Init(prefs); |
64 pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, this); | 63 pref_change_registrar_.Add( |
| 64 prefs::kContentSettingsPatternPairs, |
| 65 base::Bind( |
| 66 &DeadlockCheckerObserver::OnContentSettingsPatternPairsChanged, |
| 67 base::Unretained(this))); |
65 } | 68 } |
66 virtual ~DeadlockCheckerObserver() {} | 69 virtual ~DeadlockCheckerObserver() {} |
67 | 70 |
68 virtual void OnPreferenceChanged(PrefServiceBase* service, | 71 bool notification_received() const { |
69 const std::string& pref_name) { | 72 return notification_received_; |
| 73 } |
| 74 |
| 75 private: |
| 76 void OnContentSettingsPatternPairsChanged() { |
70 // Check whether |provider_| holds its lock. For this, we need a | 77 // Check whether |provider_| holds its lock. For this, we need a |
71 // separate thread. | 78 // separate thread. |
72 DeadlockCheckerThread thread(provider_); | 79 DeadlockCheckerThread thread(provider_); |
73 base::PlatformThreadHandle handle = base::kNullThreadHandle; | 80 base::PlatformThreadHandle handle = base::kNullThreadHandle; |
74 ASSERT_TRUE(base::PlatformThread::Create(0, &thread, &handle)); | 81 ASSERT_TRUE(base::PlatformThread::Create(0, &thread, &handle)); |
75 base::PlatformThread::Join(handle); | 82 base::PlatformThread::Join(handle); |
76 notification_received_ = true; | 83 notification_received_ = true; |
77 } | 84 } |
78 | 85 |
79 bool notification_received() const { | |
80 return notification_received_; | |
81 } | |
82 | |
83 private: | |
84 PrefProvider* provider_; | 86 PrefProvider* provider_; |
85 PrefChangeRegistrar pref_change_registrar_; | 87 PrefChangeRegistrar pref_change_registrar_; |
86 bool notification_received_; | 88 bool notification_received_; |
87 DISALLOW_COPY_AND_ASSIGN(DeadlockCheckerObserver); | 89 DISALLOW_COPY_AND_ASSIGN(DeadlockCheckerObserver); |
88 }; | 90 }; |
89 | 91 |
90 class PrefProviderTest : public testing::Test { | 92 class PrefProviderTest : public testing::Test { |
91 public: | 93 public: |
92 PrefProviderTest() : ui_thread_( | 94 PrefProviderTest() : ui_thread_( |
93 BrowserThread::UI, &message_loop_) { | 95 BrowserThread::UI, &message_loop_) { |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 DictionaryValue* mutable_settings = update.Get(); | 570 DictionaryValue* mutable_settings = update.Get(); |
569 mutable_settings->SetWithoutPathExpansion("www.example.com,*", | 571 mutable_settings->SetWithoutPathExpansion("www.example.com,*", |
570 new base::DictionaryValue()); | 572 new base::DictionaryValue()); |
571 } | 573 } |
572 EXPECT_TRUE(observer.notification_received()); | 574 EXPECT_TRUE(observer.notification_received()); |
573 | 575 |
574 provider.ShutdownOnUIThread(); | 576 provider.ShutdownOnUIThread(); |
575 } | 577 } |
576 | 578 |
577 } // namespace content_settings | 579 } // namespace content_settings |
OLD | NEW |