Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1037)

Side by Side Diff: chrome/browser/download/download_service.cc

Issue 10915180: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r166680 Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(
63 manager,
64 scoped_ptr<DownloadHistory::HistoryAdapter>(
65 new DownloadHistory::HistoryAdapter(hs))));
66 }
67
55 // Include this download manager in the set monitored by the 68 // Include this download manager in the set monitored by the
56 // global status updater. 69 // global status updater.
57 g_browser_process->download_status_updater()->AddManager(manager); 70 g_browser_process->download_status_updater()->AddManager(manager);
58 71
59 download_manager_created_ = true;
60 for (std::vector<OnManagerCreatedCallback>::iterator cb = 72 for (std::vector<OnManagerCreatedCallback>::iterator cb =
61 on_manager_created_callbacks_.begin(); 73 on_manager_created_callbacks_.begin();
62 cb != on_manager_created_callbacks_.end(); ++cb) { 74 cb != on_manager_created_callbacks_.end(); ++cb) {
63 cb->Run(manager); 75 cb->Run(manager);
64 } 76 }
65 on_manager_created_callbacks_.clear(); 77 on_manager_created_callbacks_.clear();
66 78
67 return manager_delegate_.get(); 79 return manager_delegate_.get();
68 } 80 }
69 81
82 DownloadHistory* DownloadService::GetDownloadHistory() {
83 if (!download_manager_created_) {
84 GetDownloadManagerDelegate();
85 }
86 DCHECK(download_manager_created_);
87 return download_history_.get();
88 }
89
70 bool DownloadService::HasCreatedDownloadManager() { 90 bool DownloadService::HasCreatedDownloadManager() {
71 return download_manager_created_; 91 return download_manager_created_;
72 } 92 }
73 93
74 int DownloadService::DownloadCount() const { 94 int DownloadService::DownloadCount() const {
75 if (!download_manager_created_) 95 if (!download_manager_created_)
76 return 0; 96 return 0;
77 return BrowserContext::GetDownloadManager(profile_)->InProgressCount(); 97 return BrowserContext::GetDownloadManager(profile_)->InProgressCount();
78 } 98 }
79 99
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 void DownloadService::Shutdown() { 131 void DownloadService::Shutdown() {
112 if (download_manager_created_) { 132 if (download_manager_created_) {
113 // Normally the DownloadManager would be shutdown later, after the Profile 133 // Normally the DownloadManager would be shutdown later, after the Profile
114 // goes away and BrowserContext's destructor runs. But that would be too 134 // 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 135 // 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 136 // code) when the DownloadManager is shutting down. So we shut it down
117 // manually earlier. See http://crbug.com/131692 137 // manually earlier. See http://crbug.com/131692
118 BrowserContext::GetDownloadManager(profile_)->Shutdown(); 138 BrowserContext::GetDownloadManager(profile_)->Shutdown();
119 } 139 }
120 manager_delegate_ = NULL; 140 manager_delegate_ = NULL;
141 download_history_.reset();
121 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698