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

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

Issue 10535026: Move creation and ownership of DownloadManager from the embedder to content. This matches all the o… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 6 months 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/chrome_download_manager_delegate.h" 5 #include "chrome/browser/download/chrome_download_manager_delegate.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "chrome/browser/ui/browser.h" 50 #include "chrome/browser/ui/browser.h"
51 #include "chrome/browser/ui/browser_finder.h" 51 #include "chrome/browser/ui/browser_finder.h"
52 #endif 52 #endif
53 53
54 #if defined(OS_CHROMEOS) 54 #if defined(OS_CHROMEOS)
55 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" 55 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h"
56 #include "chrome/browser/download/download_file_picker_chromeos.h" 56 #include "chrome/browser/download/download_file_picker_chromeos.h"
57 #include "chrome/browser/download/save_package_file_picker_chromeos.h" 57 #include "chrome/browser/download/save_package_file_picker_chromeos.h"
58 #endif 58 #endif
59 59
60 using content::BrowserContext;
60 using content::BrowserThread; 61 using content::BrowserThread;
61 using content::DownloadId; 62 using content::DownloadId;
62 using content::DownloadItem; 63 using content::DownloadItem;
63 using content::DownloadManager; 64 using content::DownloadManager;
64 using content::WebContents; 65 using content::WebContents;
65 using safe_browsing::DownloadProtectionService; 66 using safe_browsing::DownloadProtectionService;
66 67
67 namespace { 68 namespace {
68 69
69 // String pointer used for identifying safebrowing data associated with 70 // String pointer used for identifying safebrowing data associated with
(...skipping 27 matching lines...) Expand all
97 }; 98 };
98 99
99 SafeBrowsingState::~SafeBrowsingState() {} 100 SafeBrowsingState::~SafeBrowsingState() {}
100 101
101 } // namespace 102 } // namespace
102 103
103 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) 104 ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile)
104 : profile_(profile), 105 : profile_(profile),
105 next_download_id_(0), 106 next_download_id_(0),
106 download_prefs_(new DownloadPrefs(profile->GetPrefs())) { 107 download_prefs_(new DownloadPrefs(profile->GetPrefs())) {
108 download_manager_ = BrowserContext::GetDownloadManager(profile_);
109 download_history_.reset(new DownloadHistory(profile_));
110 download_history_->Load(
111 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete,
112 base::Unretained(download_manager_.get())));
107 } 113 }
108 114
109 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { 115 ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() {
110 } 116 }
111 117
112 void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) {
113 download_manager_ = dm;
114 download_history_.reset(new DownloadHistory(profile_));
115 download_history_->Load(
116 base::Bind(&DownloadManager::OnPersistentStoreQueryComplete,
117 base::Unretained(dm)));
118 }
119
120 void ChromeDownloadManagerDelegate::Shutdown() { 118 void ChromeDownloadManagerDelegate::Shutdown() {
121 download_history_.reset(); 119 download_history_.reset();
122 download_prefs_.reset(); 120 download_prefs_.reset();
123 } 121 }
124 122
125 DownloadId ChromeDownloadManagerDelegate::GetNextId() { 123 DownloadId ChromeDownloadManagerDelegate::GetNextId() {
126 if (!profile_->IsOffTheRecord()) 124 if (!profile_->IsOffTheRecord())
127 return DownloadId(this, next_download_id_++); 125 return DownloadId(this, next_download_id_++);
128 126
129 return profile_->GetOriginalProfile()->GetDownloadManager()->delegate()-> 127 return BrowserContext::GetDownloadManager(profile_->GetOriginalProfile())->
130 GetNextId(); 128 delegate()->GetNextId();
131 } 129 }
132 130
133 bool ChromeDownloadManagerDelegate::ShouldStartDownload(int32 download_id) { 131 bool ChromeDownloadManagerDelegate::ShouldStartDownload(int32 download_id) {
134 // We create a download item and store it in our download map, and inform the 132 // We create a download item and store it in our download map, and inform the
135 // history system of a new download. Since this method can be called while the 133 // history system of a new download. Since this method can be called while the
136 // history service thread is still reading the persistent state, we do not 134 // history service thread is still reading the persistent state, we do not
137 // insert the new DownloadItem into 'history_downloads_' or inform our 135 // insert the new DownloadItem into 'history_downloads_' or inform our
138 // observers at this point. OnCreateDownloadEntryComplete() handles that 136 // observers at this point. OnCreateDownloadEntryComplete() handles that
139 // finalization of the the download creation as a callback from the history 137 // finalization of the the download creation as a callback from the history
140 // thread. 138 // thread.
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 int32 download_id, int64 db_handle) { 801 int32 download_id, int64 db_handle) {
804 // It's not immediately obvious, but HistoryBackend::CreateDownload() can 802 // It's not immediately obvious, but HistoryBackend::CreateDownload() can
805 // call this function with an invalid |db_handle|. For instance, this can 803 // call this function with an invalid |db_handle|. For instance, this can
806 // happen when the history database is offline. We cannot have multiple 804 // happen when the history database is offline. We cannot have multiple
807 // DownloadItems with the same invalid db_handle, so we need to assign a 805 // DownloadItems with the same invalid db_handle, so we need to assign a
808 // unique |db_handle| here. 806 // unique |db_handle| here.
809 if (db_handle == DownloadItem::kUninitializedHandle) 807 if (db_handle == DownloadItem::kUninitializedHandle)
810 db_handle = download_history_->GetNextFakeDbHandle(); 808 db_handle = download_history_->GetNextFakeDbHandle();
811 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle); 809 download_manager_->OnItemAddedToPersistentStore(download_id, db_handle);
812 } 810 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698