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/download/download_service.h" | 5 #include "chrome/browser/download/download_service.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 9 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 10 #include "chrome/browser/download/download_history.h" |
10 #include "chrome/browser/download/download_service_factory.h" | 11 #include "chrome/browser/download/download_service_factory.h" |
11 #include "chrome/browser/download/download_status_updater.h" | 12 #include "chrome/browser/download/download_status_updater.h" |
| 13 #include "chrome/browser/history/history.h" |
| 14 #include "chrome/browser/history/history_service_factory.h" |
12 #include "chrome/browser/net/chrome_net_log.h" | 15 #include "chrome/browser/net/chrome_net_log.h" |
13 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "content/public/browser/download_manager.h" | 18 #include "content/public/browser/download_manager.h" |
16 | 19 |
17 using content::BrowserContext; | 20 using content::BrowserContext; |
18 using content::DownloadManager; | 21 using content::DownloadManager; |
19 using content::DownloadManagerDelegate; | 22 using content::DownloadManagerDelegate; |
20 | 23 |
21 DownloadService::DownloadService(Profile* profile) | 24 DownloadService::DownloadService(Profile* profile) |
(...skipping 13 matching lines...) Expand all Loading... |
35 } | 38 } |
36 download_manager_created_ = true; | 39 download_manager_created_ = true; |
37 | 40 |
38 // In case the delegate has already been set by | 41 // In case the delegate has already been set by |
39 // SetDownloadManagerDelegateForTesting. | 42 // SetDownloadManagerDelegateForTesting. |
40 if (!manager_delegate_.get()) | 43 if (!manager_delegate_.get()) |
41 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); | 44 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); |
42 | 45 |
43 manager_delegate_->SetDownloadManager(manager); | 46 manager_delegate_->SetDownloadManager(manager); |
44 | 47 |
| 48 if (!profile_->IsOffTheRecord()) { |
| 49 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 50 profile_, Profile::EXPLICIT_ACCESS); |
| 51 if (hs) |
| 52 download_history_.reset(new DownloadHistory( |
| 53 manager, |
| 54 scoped_ptr<DownloadHistory::HistoryAdapter>( |
| 55 new DownloadHistory::HistoryAdapter(hs)))); |
| 56 } |
| 57 |
45 // Include this download manager in the set monitored by the | 58 // Include this download manager in the set monitored by the |
46 // global status updater. | 59 // global status updater. |
47 g_browser_process->download_status_updater()->AddManager(manager); | 60 g_browser_process->download_status_updater()->AddManager(manager); |
48 | 61 |
49 return manager_delegate_.get(); | 62 return manager_delegate_.get(); |
50 } | 63 } |
51 | 64 |
| 65 DownloadHistory* DownloadService::GetDownloadHistory() { |
| 66 if (!download_manager_created_) { |
| 67 GetDownloadManagerDelegate(); |
| 68 } |
| 69 DCHECK(download_manager_created_); |
| 70 return download_history_.get(); |
| 71 } |
| 72 |
52 bool DownloadService::HasCreatedDownloadManager() { | 73 bool DownloadService::HasCreatedDownloadManager() { |
53 return download_manager_created_; | 74 return download_manager_created_; |
54 } | 75 } |
55 | 76 |
56 int DownloadService::DownloadCount() const { | 77 int DownloadService::DownloadCount() const { |
57 if (!download_manager_created_) | 78 if (!download_manager_created_) |
58 return 0; | 79 return 0; |
59 return BrowserContext::GetDownloadManager(profile_)->InProgressCount(); | 80 return BrowserContext::GetDownloadManager(profile_)->InProgressCount(); |
60 } | 81 } |
61 | 82 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 void DownloadService::Shutdown() { | 114 void DownloadService::Shutdown() { |
94 if (download_manager_created_) { | 115 if (download_manager_created_) { |
95 // Normally the DownloadManager would be shutdown later, after the Profile | 116 // Normally the DownloadManager would be shutdown later, after the Profile |
96 // goes away and BrowserContext's destructor runs. But that would be too | 117 // goes away and BrowserContext's destructor runs. But that would be too |
97 // late for us since we need to use the profile (indirectly through history | 118 // late for us since we need to use the profile (indirectly through history |
98 // code) when the DownloadManager is shutting down. So we shut it down | 119 // code) when the DownloadManager is shutting down. So we shut it down |
99 // manually earlier. See http://crbug.com/131692 | 120 // manually earlier. See http://crbug.com/131692 |
100 BrowserContext::GetDownloadManager(profile_)->Shutdown(); | 121 BrowserContext::GetDownloadManager(profile_)->Shutdown(); |
101 } | 122 } |
102 manager_delegate_ = NULL; | 123 manager_delegate_ = NULL; |
| 124 download_history_.reset(); |
103 } | 125 } |
OLD | NEW |