| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 static const int kWebDataServiceTimeoutSeconds = 8; | 51 static const int kWebDataServiceTimeoutSeconds = 8; |
| 52 | 52 |
| 53 ACTION_P(SignalEvent, event) { | 53 ACTION_P(SignalEvent, event) { |
| 54 event->Signal(); | 54 event->Signal(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 class AutofillDBThreadObserverHelper : public DBThreadObserverHelper { | 57 class AutofillDBThreadObserverHelper : public DBThreadObserverHelper { |
| 58 protected: | 58 protected: |
| 59 virtual ~AutofillDBThreadObserverHelper() {} | 59 virtual ~AutofillDBThreadObserverHelper() {} |
| 60 | 60 |
| 61 virtual void RegisterObservers() { | 61 virtual void RegisterObservers() OVERRIDE { |
| 62 registrar_.Add(&observer_, | 62 registrar_.Add(&observer_, |
| 63 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 63 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 64 content::NotificationService::AllSources()); | 64 content::NotificationService::AllSources()); |
| 65 registrar_.Add(&observer_, | 65 registrar_.Add(&observer_, |
| 66 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 66 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 67 content::NotificationService::AllSources()); | 67 content::NotificationService::AllSources()); |
| 68 registrar_.Add(&observer_, | 68 registrar_.Add(&observer_, |
| 69 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, | 69 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| 70 content::NotificationService::AllSources()); | 70 content::NotificationService::AllSources()); |
| 71 } | 71 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // MessageLoop::Quit on completion, so this call will finish at that point. | 156 // MessageLoop::Quit on completion, so this call will finish at that point. |
| 157 static void WaitUntilCalled() { | 157 static void WaitUntilCalled() { |
| 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 159 MessageLoop::current()->Run(); | 159 MessageLoop::current()->Run(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // Simple consumer for WebIntents service data. Stores the result data and | 162 // Simple consumer for WebIntents service data. Stores the result data and |
| 163 // quits UI message loop when callback is invoked. | 163 // quits UI message loop when callback is invoked. |
| 164 class WebIntentsConsumer : public WebDataServiceConsumer { | 164 class WebIntentsConsumer : public WebDataServiceConsumer { |
| 165 public: | 165 public: |
| 166 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, | 166 virtual void OnWebDataServiceRequestDone( |
| 167 const WDTypedResult* result) { | 167 WebDataService::Handle h, |
| 168 const WDTypedResult* result) OVERRIDE { |
| 168 services_.clear(); | 169 services_.clear(); |
| 169 if (result) { | 170 if (result) { |
| 170 DCHECK(result->GetType() == WEB_INTENTS_RESULT); | 171 DCHECK(result->GetType() == WEB_INTENTS_RESULT); |
| 171 services_ = static_cast< | 172 services_ = static_cast< |
| 172 const WDResult<std::vector<WebIntentServiceData> >*>(result)-> | 173 const WDResult<std::vector<WebIntentServiceData> >*>(result)-> |
| 173 GetValue(); | 174 GetValue(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 177 MessageLoop::current()->Quit(); | 178 MessageLoop::current()->Quit(); |
| 178 } | 179 } |
| 179 | 180 |
| 180 // Result data from completion callback. | 181 // Result data from completion callback. |
| 181 std::vector<WebIntentServiceData> services_; | 182 std::vector<WebIntentServiceData> services_; |
| 182 }; | 183 }; |
| 183 | 184 |
| 184 // Simple consumer for WebIntents defaults data. Stores the result data and | 185 // Simple consumer for WebIntents defaults data. Stores the result data and |
| 185 // quits UI message loop when callback is invoked. | 186 // quits UI message loop when callback is invoked. |
| 186 class WebIntentsDefaultsConsumer : public WebDataServiceConsumer { | 187 class WebIntentsDefaultsConsumer : public WebDataServiceConsumer { |
| 187 public: | 188 public: |
| 188 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, | 189 virtual void OnWebDataServiceRequestDone( |
| 189 const WDTypedResult* result) { | 190 WebDataService::Handle h, |
| 191 const WDTypedResult* result) OVERRIDE { |
| 190 services_.clear(); | 192 services_.clear(); |
| 191 if (result) { | 193 if (result) { |
| 192 DCHECK(result->GetType() == WEB_INTENTS_DEFAULTS_RESULT); | 194 DCHECK(result->GetType() == WEB_INTENTS_DEFAULTS_RESULT); |
| 193 services_ = static_cast< | 195 services_ = static_cast< |
| 194 const WDResult<std::vector<DefaultWebIntentService> >*>(result)-> | 196 const WDResult<std::vector<DefaultWebIntentService> >*>(result)-> |
| 195 GetValue(); | 197 GetValue(); |
| 196 } | 198 } |
| 197 | 199 |
| 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 199 MessageLoop::current()->Quit(); | 201 MessageLoop::current()->Quit(); |
| 200 } | 202 } |
| 201 | 203 |
| 202 // Result data from completion callback. | 204 // Result data from completion callback. |
| 203 std::vector<DefaultWebIntentService> services_; | 205 std::vector<DefaultWebIntentService> services_; |
| 204 }; | 206 }; |
| 205 | 207 |
| 206 // Simple consumer for Keywords data. Stores the result data and quits UI | 208 // Simple consumer for Keywords data. Stores the result data and quits UI |
| 207 // message loop when callback is invoked. | 209 // message loop when callback is invoked. |
| 208 class KeywordsConsumer : public WebDataServiceConsumer { | 210 class KeywordsConsumer : public WebDataServiceConsumer { |
| 209 public: | 211 public: |
| 210 KeywordsConsumer() : load_succeeded(false) {} | 212 KeywordsConsumer() : load_succeeded(false) {} |
| 211 | 213 |
| 212 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, | 214 virtual void OnWebDataServiceRequestDone( |
| 213 const WDTypedResult* result) { | 215 WebDataService::Handle h, |
| 216 const WDTypedResult* result) OVERRIDE { |
| 214 if (result) { | 217 if (result) { |
| 215 load_succeeded = true; | 218 load_succeeded = true; |
| 216 DCHECK(result->GetType() == KEYWORDS_RESULT); | 219 DCHECK(result->GetType() == KEYWORDS_RESULT); |
| 217 keywords_result = | 220 keywords_result = |
| 218 reinterpret_cast<const WDResult<WDKeywordsResult>*>( | 221 reinterpret_cast<const WDResult<WDKeywordsResult>*>( |
| 219 result)->GetValue(); | 222 result)->GetValue(); |
| 220 } | 223 } |
| 221 | 224 |
| 222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 223 MessageLoop::current()->Quit(); | 226 MessageLoop::current()->Quit(); |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 ASSERT_EQ(2U, consumer.services_.size()); | 822 ASSERT_EQ(2U, consumer.services_.size()); |
| 820 | 823 |
| 821 wds_->RemoveWebIntentServiceDefaults(service_url_0); | 824 wds_->RemoveWebIntentServiceDefaults(service_url_0); |
| 822 MessageLoop::current()->RunUntilIdle(); | 825 MessageLoop::current()->RunUntilIdle(); |
| 823 | 826 |
| 824 wds_->GetAllDefaultWebIntentServices(&consumer); | 827 wds_->GetAllDefaultWebIntentServices(&consumer); |
| 825 WaitUntilCalled(); | 828 WaitUntilCalled(); |
| 826 ASSERT_EQ(1U, consumer.services_.size()); | 829 ASSERT_EQ(1U, consumer.services_.size()); |
| 827 EXPECT_EQ(service_url_1.spec(), consumer.services_[0].service_url); | 830 EXPECT_EQ(service_url_1.spec(), consumer.services_[0].service_url); |
| 828 } | 831 } |
| OLD | NEW |