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 23 matching lines...) Expand all Loading... |
45 } | 48 } |
46 download_manager_created_ = true; | 49 download_manager_created_ = true; |
47 | 50 |
48 // In case the delegate has already been set by | 51 // In case the delegate has already been set by |
49 // SetDownloadManagerDelegateForTesting. | 52 // SetDownloadManagerDelegateForTesting. |
50 if (!manager_delegate_.get()) | 53 if (!manager_delegate_.get()) |
51 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); | 54 manager_delegate_ = new ChromeDownloadManagerDelegate(profile_); |
52 | 55 |
53 manager_delegate_->SetDownloadManager(manager); | 56 manager_delegate_->SetDownloadManager(manager); |
54 | 57 |
| 58 if (!profile_->IsOffTheRecord()) { |
| 59 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 60 profile_, Profile::EXPLICIT_ACCESS); |
| 61 if (hs) |
| 62 download_history_.reset(new DownloadHistory(manager, hs)); |
| 63 } |
| 64 |
55 // Include this download manager in the set monitored by the | 65 // Include this download manager in the set monitored by the |
56 // global status updater. | 66 // global status updater. |
57 g_browser_process->download_status_updater()->AddManager(manager); | 67 g_browser_process->download_status_updater()->AddManager(manager); |
58 | 68 |
59 download_manager_created_ = true; | |
60 for (std::vector<OnManagerCreatedCallback>::iterator cb = | 69 for (std::vector<OnManagerCreatedCallback>::iterator cb = |
61 on_manager_created_callbacks_.begin(); | 70 on_manager_created_callbacks_.begin(); |
62 cb != on_manager_created_callbacks_.end(); ++cb) { | 71 cb != on_manager_created_callbacks_.end(); ++cb) { |
63 cb->Run(manager); | 72 cb->Run(manager); |
64 } | 73 } |
65 on_manager_created_callbacks_.clear(); | 74 on_manager_created_callbacks_.clear(); |
66 | 75 |
67 return manager_delegate_.get(); | 76 return manager_delegate_.get(); |
68 } | 77 } |
69 | 78 |
| 79 DownloadHistory* DownloadService::GetDownloadHistory() { |
| 80 if (!download_manager_created_) { |
| 81 GetDownloadManagerDelegate(); |
| 82 } |
| 83 DCHECK(download_manager_created_); |
| 84 return download_history_.get(); |
| 85 } |
| 86 |
70 bool DownloadService::HasCreatedDownloadManager() { | 87 bool DownloadService::HasCreatedDownloadManager() { |
71 return download_manager_created_; | 88 return download_manager_created_; |
72 } | 89 } |
73 | 90 |
74 int DownloadService::DownloadCount() const { | 91 int DownloadService::DownloadCount() const { |
75 if (!download_manager_created_) | 92 if (!download_manager_created_) |
76 return 0; | 93 return 0; |
77 return BrowserContext::GetDownloadManager(profile_)->InProgressCount(); | 94 return BrowserContext::GetDownloadManager(profile_)->InProgressCount(); |
78 } | 95 } |
79 | 96 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 void DownloadService::Shutdown() { | 128 void DownloadService::Shutdown() { |
112 if (download_manager_created_) { | 129 if (download_manager_created_) { |
113 // Normally the DownloadManager would be shutdown later, after the Profile | 130 // Normally the DownloadManager would be shutdown later, after the Profile |
114 // goes away and BrowserContext's destructor runs. But that would be too | 131 // goes away and BrowserContext's destructor runs. But that would be too |
115 // late for us since we need to use the profile (indirectly through history | 132 // late for us since we need to use the profile (indirectly through history |
116 // code) when the DownloadManager is shutting down. So we shut it down | 133 // code) when the DownloadManager is shutting down. So we shut it down |
117 // manually earlier. See http://crbug.com/131692 | 134 // manually earlier. See http://crbug.com/131692 |
118 BrowserContext::GetDownloadManager(profile_)->Shutdown(); | 135 BrowserContext::GetDownloadManager(profile_)->Shutdown(); |
119 } | 136 } |
120 manager_delegate_ = NULL; | 137 manager_delegate_ = NULL; |
| 138 download_history_.reset(); |
121 } | 139 } |
OLD | NEW |