diff options
author | georged@chromium.org <georged@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-01 23:33:45 +0000 |
---|---|---|
committer | georged@chromium.org <georged@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-01 23:33:45 +0000 |
commit | 8f78375f6e69a6d39dcb820fb10fd7c61408c4e1 (patch) | |
tree | abcb9df6c48ac9a4be3f9e894b7ce8dda2c7f4e5 /chrome/browser/download | |
parent | 3b0c80b47eaf1b98e34bfc5dc37c26a503f1d072 (diff) | |
download | chromium_src-8f78375f6e69a6d39dcb820fb10fd7c61408c4e1.zip chromium_src-8f78375f6e69a6d39dcb820fb10fd7c61408c4e1.tar.gz chromium_src-8f78375f6e69a6d39dcb820fb10fd7c61408c4e1.tar.bz2 |
Installing extensions (drag/drop, download crx file) will now be
handled by the Chrome instance w/o shell execute. This will install
the extension in the proper profile using the running bits.
Review URL: http://codereview.chromium.org/55046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13000 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r-- | chrome/browser/download/download_file.cc | 11 | ||||
-rw-r--r-- | chrome/browser/download/download_file.h | 3 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.cc | 45 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.h | 20 | ||||
-rw-r--r-- | chrome/browser/download/download_util.cc | 2 |
5 files changed, 73 insertions, 8 deletions
diff --git a/chrome/browser/download/download_file.cc b/chrome/browser/download/download_file.cc index 5411662..dddac9a 100644 --- a/chrome/browser/download/download_file.cc +++ b/chrome/browser/download/download_file.cc @@ -550,7 +550,8 @@ void DownloadFileManager::OnOpenDownloadInShell(const FilePath& full_path, // download specified by 'id'. Rename the in progress download, and remove it // from our table if it has been completed or cancelled already. void DownloadFileManager::OnFinalDownloadName(int id, - const FilePath& full_path) { + const FilePath& full_path, + DownloadManager* manager) { DCHECK(MessageLoop::current() == file_loop_); DownloadFileMap::iterator it = downloads_.find(id); if (it == downloads_.end()) @@ -559,7 +560,13 @@ void DownloadFileManager::OnFinalDownloadName(int id, file_util::CreateDirectory(full_path.DirName()); DownloadFile* download = it->second; - if (!download->Rename(full_path)) { + if (download->Rename(full_path)) { + ui_loop_->PostTask(FROM_HERE, + NewRunnableMethod(manager, + &DownloadManager::DownloadRenamedToFinalName, + id, + full_path)); + } else { // Error. Between the time the UI thread generated 'full_path' to the time // this code runs, something happened that prevents us from renaming. DownloadManagerMap::iterator dmit = managers_.find(download->id()); diff --git a/chrome/browser/download/download_file.h b/chrome/browser/download/download_file.h index 5e897eae..82f7597 100644 --- a/chrome/browser/download/download_file.h +++ b/chrome/browser/download/download_file.h @@ -205,7 +205,8 @@ class DownloadFileManager // The download manager has provided a final name for a download. Sent from // the UI thread and run on the download thread. - void OnFinalDownloadName(int id, const FilePath& full_path); + void OnFinalDownloadName(int id, const FilePath& full_path, + DownloadManager* download_manager); // Timer notifications. void UpdateInProgressDownloads(); diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index f7f7864..9574096 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -18,6 +18,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/download/download_file.h" #include "chrome/browser/extensions/extension.h" +#include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" @@ -688,7 +689,8 @@ void DownloadManager::ContinueStartDownload(DownloadCreateInfo* info, NewRunnableMethod(file_manager_, &DownloadFileManager::OnFinalDownloadName, download->id(), - target_path)); + target_path, + this)); // If the download already completed by the time we reached this point, then // notify observers that it did. @@ -815,6 +817,18 @@ void DownloadManager::DownloadFinished(int32 download_id, int64 size) { ContinueDownloadFinished(download); } +void DownloadManager::DownloadRenamedToFinalName(int download_id, + const FilePath& full_path) { + FilePath::StringType extension = full_path.Extension(); + // Drop the leading period. + if (extension.size() > 0) + extension = extension.substr(1); + + if (extension == chrome::kExtensionFileExtension) { + OpenChromeExtension(full_path); + } +} + void DownloadManager::ContinueDownloadFinished(DownloadItem* download) { // If this was a dangerous download, it has now been approved and must be // removed from dangerous_finished_ so it does not get deleted on shutdown. @@ -831,6 +845,14 @@ void DownloadManager::ContinueDownloadFinished(DownloadItem* download) { // Drop the leading period. if (extension.size() > 0) extension = extension.substr(1); + + // Handle chrome extensions explicitly and skip the shell execute. + if (extension == chrome::kExtensionFileExtension) { + // Skip the shell execute. This will be handled in + // DownloadRenamedToFinalName + return; + } + if (download->open_when_complete() || ShouldOpenFileExtension(extension)) OpenDownloadInShell(download, NULL); } @@ -1194,6 +1216,27 @@ void DownloadManager::ShowDownloadInShell(const DownloadItem* download) { FilePath(download->full_path()))); } +void DownloadManager::OpenDownload(const DownloadItem* download, + gfx::NativeView parent_window) { + FilePath::StringType extension = download->full_path().Extension(); + // Drop the leading period. + if (extension.size() > 0) + extension = extension.substr(1); + + // Open Chrome extensions with ExtenstionsService. For everthing else do shell + // execute. + if (extension == chrome::kExtensionFileExtension) { + OpenChromeExtension(download->full_path()); + } else { + OpenDownloadInShell(download, parent_window); + } +} + +void DownloadManager::OpenChromeExtension(const FilePath& full_path) { + ExtensionsService* extensions_service = profile_->GetExtensionsService(); + extensions_service->InstallExtension(full_path); +} + void DownloadManager::OpenDownloadInShell(const DownloadItem* download, gfx::NativeView parent_window) { DCHECK(file_manager_); diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h index 630e933..5712d95 100644 --- a/chrome/browser/download/download_manager.h +++ b/chrome/browser/download/download_manager.h @@ -335,6 +335,9 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, void PauseDownload(int32 download_id, bool pause); void RemoveDownload(int64 download_handle); + // Called when the download is renamed to its final name. + void DownloadRenamedToFinalName(int download_id, const FilePath& full_path); + // Remove downloads after remove_begin (inclusive) and before remove_end // (exclusive). You may pass in null Time values to do an unbounded delete // in either direction. @@ -364,10 +367,14 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, void OnSearchComplete(HistoryService::Handle handle, std::vector<int64>* results); - // Show or Open a download via the Windows shell. + // Opens a download. For Chrome extensions call + // ExtensionsServices::InstallExtension, for everything else call + // OpenDownloadInShell. + void OpenDownload(const DownloadItem* download, + gfx::NativeView parent_window); + + // Show a download via the Windows shell. void ShowDownloadInShell(const DownloadItem* download); - void OpenDownloadInShell(const DownloadItem* download, - gfx::NativeView parent_window); // The number of in progress (including paused) downloads. int in_progress_count() const { @@ -420,6 +427,13 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, FilePath* file_name); private: + // Opens a download via the Windows shell. + void OpenDownloadInShell(const DownloadItem* download, + gfx::NativeView parent_window); + + // Opens downloaded Chrome extension file (*.crx). + void OpenChromeExtension(const FilePath& full_path); + // Shutdown the download manager. This call is needed only after Init. void Shutdown(); diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index 27e078e..ad670ab 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -51,7 +51,7 @@ void OpenDownload(DownloadItem* download) { if (download->state() == DownloadItem::IN_PROGRESS) download->set_open_when_complete(!download->open_when_complete()); else if (download->state() == DownloadItem::COMPLETE) - download->manager()->OpenDownloadInShell(download, NULL); + download->manager()->OpenDownload(download, NULL); } // Download progress painting -------------------------------------------------- |