diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-22 19:26:03 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-22 19:26:03 +0000 |
commit | 6d0c9fb2106237d6e2e1b0b069bf4d5cefd3f796 (patch) | |
tree | a01dc8e9a55f27c2692fb808ea34fbd6d06bed68 /chrome/browser/ui/webui | |
parent | f8807b2dd6f9b6306a18db9af6e830a7bfb1239c (diff) | |
download | chromium_src-6d0c9fb2106237d6e2e1b0b069bf4d5cefd3f796.zip chromium_src-6d0c9fb2106237d6e2e1b0b069bf4d5cefd3f796.tar.gz chromium_src-6d0c9fb2106237d6e2e1b0b069bf4d5cefd3f796.tar.bz2 |
Get rid of Profile usage in the content download code, and switch to BrowserContext instead. I removed GetCurrentDownloads which isn't used anymore except in a test. I replaced that call with SearchDownloads.I had to convert from BrowserContext to Profile for history and extension related code, which is moving out and inherently needs it.BUG=82782
Review URL: http://codereview.chromium.org/7694022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97707 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/webui')
-rw-r--r-- | chrome/browser/ui/webui/downloads_dom_handler.cc | 59 | ||||
-rw-r--r-- | chrome/browser/ui/webui/downloads_dom_handler.h | 7 |
2 files changed, 65 insertions, 1 deletions
diff --git a/chrome/browser/ui/webui/downloads_dom_handler.cc b/chrome/browser/ui/webui/downloads_dom_handler.cc index 61ba8b2..6c9b208 100644 --- a/chrome/browser/ui/webui/downloads_dom_handler.cc +++ b/chrome/browser/ui/webui/downloads_dom_handler.cc @@ -50,12 +50,46 @@ class DownloadItemSorter : public std::binary_function<DownloadItem*, } // namespace +class DownloadsDOMHandler::OriginalDownloadManagerObserver + : public DownloadManager::Observer { + public: + explicit OriginalDownloadManagerObserver( + DownloadManager::Observer* observer, + Profile* original_profile) + : observer_(observer) { + original_profile_download_manager_ = original_profile->GetDownloadManager(); + original_profile_download_manager_->AddObserver(this); + } + + virtual ~OriginalDownloadManagerObserver() { + if (original_profile_download_manager_) + original_profile_download_manager_->RemoveObserver(this); + } + + // Observer interface. + virtual void ModelChanged() { + observer_->ModelChanged(); + } + + virtual void ManagerGoingDown() { + original_profile_download_manager_ = NULL; + } + + private: + // The DownloadsDOMHandler for the off-the-record profile. + DownloadManager::Observer* observer_; + + // The original profile's download manager. + DownloadManager* original_profile_download_manager_; +}; + DownloadsDOMHandler::DownloadsDOMHandler(DownloadManager* dlm) : search_text_(), download_manager_(dlm), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { // Create our fileicon data source. - dlm->profile()->GetChromeURLDataManager()->AddDataSource( + Profile::FromBrowserContext(dlm->browser_context())-> + GetChromeURLDataManager()->AddDataSource( #if defined(OS_CHROMEOS) new FileIconSourceCros()); #else @@ -72,6 +106,14 @@ DownloadsDOMHandler::~DownloadsDOMHandler() { void DownloadsDOMHandler::Init() { download_manager_->AddObserver(this); + + Profile* profile = + Profile::FromBrowserContext(download_manager_->browser_context()); + Profile* original_profile = profile->GetOriginalProfile(); + if (original_profile != profile) { + original_download_manager_observer_.reset( + new OriginalDownloadManagerObserver(this, original_profile)); + } } void DownloadsDOMHandler::RegisterMessages() { @@ -135,6 +177,14 @@ void DownloadsDOMHandler::ModelChanged() { ClearDownloadItems(); download_manager_->SearchDownloads(WideToUTF16(search_text_), &download_items_); + // If we have a parent profile, let it add its downloads to the results. + Profile* profile = + Profile::FromBrowserContext(download_manager_->browser_context()); + if (profile->GetOriginalProfile() != profile) { + profile->GetOriginalProfile()->GetDownloadManager()->SearchDownloads( + WideToUTF16(search_text_), &download_items_); + } + sort(download_items_.begin(), download_items_.end(), DownloadItemSorter()); // Add ourself to all download items as an observer. @@ -229,6 +279,13 @@ void DownloadsDOMHandler::HandleCancel(const ListValue* args) { void DownloadsDOMHandler::HandleClearAll(const ListValue* args) { download_manager_->RemoveAllDownloads(); + + Profile* profile = + Profile::FromBrowserContext(download_manager_->browser_context()); + // If this is an incognito downloader, clear All should clear main download + // manager as well. + if (profile->GetOriginalProfile() != profile) + profile->GetOriginalProfile()->GetDownloadManager()->RemoveAllDownloads(); } void DownloadsDOMHandler::HandleOpenDownloadsFolder(const ListValue* args) { diff --git a/chrome/browser/ui/webui/downloads_dom_handler.h b/chrome/browser/ui/webui/downloads_dom_handler.h index 7f64b9a..20c4d47 100644 --- a/chrome/browser/ui/webui/downloads_dom_handler.h +++ b/chrome/browser/ui/webui/downloads_dom_handler.h @@ -76,6 +76,8 @@ class DownloadsDOMHandler : public WebUIMessageHandler, void HandleOpenDownloadsFolder(const base::ListValue* args); private: + class OriginalDownloadManagerObserver; + // Send the current list of downloads to the page. void SendCurrentDownloads(); @@ -94,6 +96,11 @@ class DownloadsDOMHandler : public WebUIMessageHandler, // Our model DownloadManager* download_manager_; + // The downloads webui for an off-the-record window also shows downloads from + // the parent profile. + scoped_ptr<OriginalDownloadManagerObserver> + original_download_manager_observer_; + // The current set of visible DownloadItems for this view received from the // DownloadManager. DownloadManager owns the DownloadItems. The vector is // kept in order, sorted by ascending start time. |