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" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/history/chrome_history_client.h" | 17 #include "chrome/browser/history/chrome_history_client.h" |
17 #include "chrome/browser/history/chrome_history_client_factory.h" | 18 #include "chrome/browser/history/chrome_history_client_factory.h" |
18 #include "chrome/browser/history/history_service_factory.h" | 19 #include "chrome/browser/history/history_service_factory.h" |
19 #include "chrome/browser/history/web_history_service_factory.h" | 20 #include "chrome/browser/history/web_history_service_factory.h" |
20 #include "chrome/browser/prefs/browser_prefs.h" | 21 #include "chrome/browser/prefs/browser_prefs.h" |
21 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
22 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
(...skipping 12 matching lines...) Expand all Loading... |
35 #include "components/history/core/browser/history_database_params.h" | 36 #include "components/history/core/browser/history_database_params.h" |
36 #include "components/history/core/browser/history_service.h" | 37 #include "components/history/core/browser/history_service.h" |
37 #include "content/public/test/test_browser_thread_bundle.h" | 38 #include "content/public/test/test_browser_thread_bundle.h" |
38 #include "content/public/test/test_utils.h" | 39 #include "content/public/test/test_utils.h" |
39 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
40 | 41 |
41 namespace { | 42 namespace { |
42 | 43 |
43 // A BrowserContextKeyedServiceFactory::TestingFactoryFunction that creates a | 44 // A BrowserContextKeyedServiceFactory::TestingFactoryFunction that creates a |
44 // HistoryService for a TestingProfile. | 45 // HistoryService for a TestingProfile. |
45 KeyedService* BuildHistoryService(content::BrowserContext* context) { | 46 scoped_ptr<KeyedService> BuildHistoryService(content::BrowserContext* context) { |
46 TestingProfile* profile = static_cast<TestingProfile*>(context); | 47 TestingProfile* profile = static_cast<TestingProfile*>(context); |
47 | 48 |
48 // Delete the file before creating the service. | 49 // Delete the file before creating the service. |
49 base::FilePath history_path( | 50 base::FilePath history_path( |
50 profile->GetPath().Append(history::kHistoryFilename)); | 51 profile->GetPath().Append(history::kHistoryFilename)); |
51 if (!base::DeleteFile(history_path, false) || | 52 if (!base::DeleteFile(history_path, false) || |
52 base::PathExists(history_path)) { | 53 base::PathExists(history_path)) { |
53 ADD_FAILURE() << "failed to delete history db file " | 54 ADD_FAILURE() << "failed to delete history db file " |
54 << history_path.value(); | 55 << history_path.value(); |
55 return NULL; | 56 return nullptr; |
56 } | 57 } |
57 | 58 |
58 history::HistoryService* history_service = new history::HistoryService( | 59 scoped_ptr<history::HistoryService> history_service( |
59 ChromeHistoryClientFactory::GetForProfile(profile), | 60 new history::HistoryService( |
60 scoped_ptr<history::VisitDelegate>()); | 61 ChromeHistoryClientFactory::GetForProfile(profile), |
| 62 scoped_ptr<history::VisitDelegate>())); |
61 if (history_service->Init( | 63 if (history_service->Init( |
62 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), | 64 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), |
63 history::HistoryDatabaseParamsForPath(profile->GetPath()))) { | 65 history::HistoryDatabaseParamsForPath(profile->GetPath()))) { |
64 return history_service; | 66 return history_service.Pass(); |
65 } | 67 } |
66 | 68 |
67 ADD_FAILURE() << "failed to initialize history service"; | 69 ADD_FAILURE() << "failed to initialize history service"; |
68 delete history_service; | 70 return nullptr; |
69 return NULL; | |
70 } | 71 } |
71 | 72 |
72 } // namespace | 73 } // namespace |
73 | 74 |
74 namespace safe_browsing { | 75 namespace safe_browsing { |
75 | 76 |
76 class LastDownloadFinderTest : public testing::Test { | 77 class LastDownloadFinderTest : public testing::Test { |
77 public: | 78 public: |
78 void NeverCalled(scoped_ptr<ClientIncidentReport_DownloadDetails> download) { | 79 void NeverCalled(scoped_ptr<ClientIncidentReport_DownloadDetails> download) { |
79 FAIL(); | 80 FAIL(); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 base::Unretained(this), | 348 base::Unretained(this), |
348 &last_download, | 349 &last_download, |
349 run_loop.QuitClosure()))); | 350 run_loop.QuitClosure()))); |
350 | 351 |
351 run_loop.Run(); | 352 run_loop.Run(); |
352 | 353 |
353 ExpectFoundTestDownload(last_download.Pass()); | 354 ExpectFoundTestDownload(last_download.Pass()); |
354 } | 355 } |
355 | 356 |
356 } // namespace safe_browsing | 357 } // namespace safe_browsing |
OLD | NEW |