OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/safe_browsing/incident_reporting/last_download_finder.h
" | 5 #include "chrome/browser/safe_browsing/incident_reporting/last_download_finder.h
" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 class LastDownloadFinderTest : public testing::Test { | 67 class LastDownloadFinderTest : public testing::Test { |
68 public: | 68 public: |
69 void NeverCalled(scoped_ptr<ClientIncidentReport_DownloadDetails> download) { | 69 void NeverCalled(scoped_ptr<ClientIncidentReport_DownloadDetails> download) { |
70 FAIL(); | 70 FAIL(); |
71 } | 71 } |
72 | 72 |
73 // Creates a new profile that participates in safe browsing and adds a | 73 // Creates a new profile that participates in safe browsing and adds a |
74 // download to its history. | 74 // download to its history. |
75 void CreateProfileWithDownload() { | 75 void CreateProfileWithDownload() { |
76 TestingProfile* profile = CreateProfile(SAFE_BROWSING_OPT_IN); | 76 TestingProfile* profile = CreateProfile(SAFE_BROWSING_OPT_IN); |
77 HistoryService* history_service = | 77 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
78 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); | 78 profile, ServiceAccessType::EXPLICIT_ACCESS); |
79 history_service->CreateDownload( | 79 history_service->CreateDownload( |
80 CreateTestDownloadRow(), | 80 CreateTestDownloadRow(), |
81 base::Bind(&LastDownloadFinderTest::OnDownloadCreated, | 81 base::Bind(&LastDownloadFinderTest::OnDownloadCreated, |
82 base::Unretained(this))); | 82 base::Unretained(this))); |
83 } | 83 } |
84 | 84 |
85 // LastDownloadFinder::LastDownloadCallback implementation that | 85 // LastDownloadFinder::LastDownloadCallback implementation that |
86 // passes the found download to |result| and then runs a closure. | 86 // passes the found download to |result| and then runs a closure. |
87 void OnLastDownload( | 87 void OnLastDownload( |
88 scoped_ptr<ClientIncidentReport_DownloadDetails>* result, | 88 scoped_ptr<ClientIncidentReport_DownloadDetails>* result, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 155 } |
156 | 156 |
157 LastDownloadFinder::DownloadDetailsGetter GetDownloadDetailsGetter() { | 157 LastDownloadFinder::DownloadDetailsGetter GetDownloadDetailsGetter() { |
158 return base::Bind(&LastDownloadFinderTest::GetDownloadDetails, | 158 return base::Bind(&LastDownloadFinderTest::GetDownloadDetails, |
159 base::Unretained(this)); | 159 base::Unretained(this)); |
160 } | 160 } |
161 | 161 |
162 void AddDownload(Profile* profile, const history::DownloadRow& download) { | 162 void AddDownload(Profile* profile, const history::DownloadRow& download) { |
163 base::RunLoop run_loop; | 163 base::RunLoop run_loop; |
164 | 164 |
165 HistoryService* history_service = | 165 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
166 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); | 166 profile, ServiceAccessType::EXPLICIT_ACCESS); |
167 history_service->CreateDownload( | 167 history_service->CreateDownload( |
168 download, | 168 download, |
169 base::Bind(&LastDownloadFinderTest::ContinueOnDownloadCreated, | 169 base::Bind(&LastDownloadFinderTest::ContinueOnDownloadCreated, |
170 base::Unretained(this), | 170 base::Unretained(this), |
171 run_loop.QuitClosure())); | 171 run_loop.QuitClosure())); |
172 run_loop.Run(); | 172 run_loop.Run(); |
173 } | 173 } |
174 | 174 |
175 // Wait for the history backend thread to process any outstanding tasks. | 175 // Wait for the history backend thread to process any outstanding tasks. |
176 // This is needed because HistoryService::QueryDownloads uses PostTaskAndReply | 176 // This is needed because HistoryService::QueryDownloads uses PostTaskAndReply |
177 // to do work on the backend thread and then invoke the caller's callback on | 177 // to do work on the backend thread and then invoke the caller's callback on |
178 // the originating thread. The PostTaskAndReplyRelay holds a reference to the | 178 // the originating thread. The PostTaskAndReplyRelay holds a reference to the |
179 // backend until its RunReplyAndSelfDestruct is called on the originating | 179 // backend until its RunReplyAndSelfDestruct is called on the originating |
180 // thread. This reference MUST be released (on the originating thread, | 180 // thread. This reference MUST be released (on the originating thread, |
181 // remember) _before_ calling DestroyHistoryService in TearDown(). See the | 181 // remember) _before_ calling DestroyHistoryService in TearDown(). See the |
182 // giant comment in HistoryService::Cleanup explaining where the backend's | 182 // giant comment in HistoryService::Cleanup explaining where the backend's |
183 // dtor must be run. | 183 // dtor must be run. |
184 void FlushHistoryBackend(Profile* profile) { | 184 void FlushHistoryBackend(Profile* profile) { |
185 base::RunLoop run_loop; | 185 base::RunLoop run_loop; |
186 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) | 186 HistoryServiceFactory::GetForProfile(profile, |
| 187 ServiceAccessType::EXPLICIT_ACCESS) |
187 ->FlushForTest(run_loop.QuitClosure()); | 188 ->FlushForTest(run_loop.QuitClosure()); |
188 run_loop.Run(); | 189 run_loop.Run(); |
189 // Then make sure anything bounced back to the main thread has been handled. | 190 // Then make sure anything bounced back to the main thread has been handled. |
190 base::RunLoop().RunUntilIdle(); | 191 base::RunLoop().RunUntilIdle(); |
191 } | 192 } |
192 | 193 |
193 // Runs the last download finder on all loaded profiles, returning the found | 194 // Runs the last download finder on all loaded profiles, returning the found |
194 // download or an empty pointer if none was found. | 195 // download or an empty pointer if none was found. |
195 scoped_ptr<ClientIncidentReport_DownloadDetails> RunLastDownloadFinder() { | 196 scoped_ptr<ClientIncidentReport_DownloadDetails> RunLastDownloadFinder() { |
196 base::RunLoop run_loop; | 197 base::RunLoop run_loop; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 base::Unretained(this), | 335 base::Unretained(this), |
335 &last_download, | 336 &last_download, |
336 run_loop.QuitClosure()))); | 337 run_loop.QuitClosure()))); |
337 | 338 |
338 run_loop.Run(); | 339 run_loop.Run(); |
339 | 340 |
340 ExpectFoundTestDownload(last_download.Pass()); | 341 ExpectFoundTestDownload(last_download.Pass()); |
341 } | 342 } |
342 | 343 |
343 } // namespace safe_browsing | 344 } // namespace safe_browsing |
OLD | NEW |