| 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/extensions/webstore_installer.h" | 5 #include "chrome/browser/extensions/webstore_installer.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 int uniquifier = file_util::GetUniquePathNumber(file, FILE_PATH_LITERAL("")); | 112 int uniquifier = file_util::GetUniquePathNumber(file, FILE_PATH_LITERAL("")); |
| 113 if (uniquifier > 0) | 113 if (uniquifier > 0) |
| 114 file = file.InsertBeforeExtensionASCII(StringPrintf(" (%d)", uniquifier)); | 114 file = file.InsertBeforeExtensionASCII(StringPrintf(" (%d)", uniquifier)); |
| 115 | 115 |
| 116 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 116 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 117 base::Bind(callback, file)); | 117 base::Bind(callback, file)); |
| 118 } | 118 } |
| 119 | 119 |
| 120 } // namespace | 120 } // namespace |
| 121 | 121 |
| 122 WebstoreInstaller::Approval::Approval() |
| 123 : profile(NULL), |
| 124 use_app_installed_bubble(false), |
| 125 skip_post_install_ui(false) { |
| 126 } |
| 127 |
| 128 WebstoreInstaller::Approval::~Approval() {} |
| 129 |
| 122 const WebstoreInstaller::Approval* WebstoreInstaller::GetAssociatedApproval( | 130 const WebstoreInstaller::Approval* WebstoreInstaller::GetAssociatedApproval( |
| 123 const DownloadItem& download) { | 131 const DownloadItem& download) { |
| 124 return static_cast<const Approval*>(download.GetExternalData(kApprovalKey)); | 132 return static_cast<const Approval*>(download.GetExternalData(kApprovalKey)); |
| 125 } | 133 } |
| 126 | 134 |
| 127 WebstoreInstaller::Approval::Approval() | |
| 128 : profile(NULL), | |
| 129 use_app_installed_bubble(false), | |
| 130 skip_post_install_ui(false) {} | |
| 131 WebstoreInstaller::Approval::~Approval() {} | |
| 132 | |
| 133 WebstoreInstaller::WebstoreInstaller(Profile* profile, | 135 WebstoreInstaller::WebstoreInstaller(Profile* profile, |
| 134 Delegate* delegate, | 136 Delegate* delegate, |
| 135 NavigationController* controller, | 137 NavigationController* controller, |
| 136 const std::string& id, | 138 const std::string& id, |
| 137 scoped_ptr<Approval> approval, | 139 scoped_ptr<Approval> approval, |
| 138 int flags) | 140 int flags) |
| 139 : profile_(profile), | 141 : profile_(profile), |
| 140 delegate_(delegate), | 142 delegate_(delegate), |
| 141 controller_(controller), | 143 controller_(controller), |
| 142 id_(id), | 144 id_(id), |
| 143 download_item_(NULL), | 145 download_item_(NULL), |
| 144 flags_(flags), | 146 flags_(flags), |
| 145 approval_(approval.release()) { | 147 approval_(approval.release()) { |
| 146 download_url_ = GetWebstoreInstallURL(id, flags & FLAG_INLINE_INSTALL ? | 148 download_url_ = GetWebstoreInstallURL(id, flags & FLAG_INLINE_INSTALL ? |
| 147 kInlineInstallSource : kDefaultInstallSource); | 149 kInlineInstallSource : kDefaultInstallSource); |
| 148 | 150 |
| 149 registrar_.Add(this, chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 151 registrar_.Add(this, chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 150 content::NotificationService::AllSources()); | 152 content::NotificationService::AllSources()); |
| 151 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, | 153 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| 152 content::Source<Profile>(profile->GetOriginalProfile())); | 154 content::Source<Profile>(profile->GetOriginalProfile())); |
| 153 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, | 155 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
| 154 content::Source<CrxInstaller>(NULL)); | 156 content::Source<CrxInstaller>(NULL)); |
| 155 } | 157 } |
| 156 | 158 |
| 157 WebstoreInstaller::~WebstoreInstaller() { | |
| 158 if (download_item_) { | |
| 159 download_item_->RemoveObserver(this); | |
| 160 download_item_ = NULL; | |
| 161 } | |
| 162 } | |
| 163 | |
| 164 void WebstoreInstaller::Start() { | 159 void WebstoreInstaller::Start() { |
| 165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 166 AddRef(); // Balanced in ReportSuccess and ReportFailure. | 161 AddRef(); // Balanced in ReportSuccess and ReportFailure. |
| 167 | 162 |
| 168 if (!Extension::IdIsValid(id_)) { | 163 if (!Extension::IdIsValid(id_)) { |
| 169 ReportFailure(kInvalidIdError); | 164 ReportFailure(kInvalidIdError); |
| 170 return; | 165 return; |
| 171 } | 166 } |
| 172 | 167 |
| 173 FilePath download_path = DownloadPrefs::FromDownloadManager( | 168 FilePath download_path = DownloadPrefs::FromDownloadManager( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 217 |
| 223 default: | 218 default: |
| 224 NOTREACHED(); | 219 NOTREACHED(); |
| 225 } | 220 } |
| 226 } | 221 } |
| 227 | 222 |
| 228 void WebstoreInstaller::SetDownloadDirectoryForTests(FilePath* directory) { | 223 void WebstoreInstaller::SetDownloadDirectoryForTests(FilePath* directory) { |
| 229 g_download_directory_for_tests = directory; | 224 g_download_directory_for_tests = directory; |
| 230 } | 225 } |
| 231 | 226 |
| 227 WebstoreInstaller::~WebstoreInstaller() { |
| 228 if (download_item_) { |
| 229 download_item_->RemoveObserver(this); |
| 230 download_item_ = NULL; |
| 231 } |
| 232 } |
| 233 |
| 232 void WebstoreInstaller::OnDownloadStarted(DownloadId id, net::Error error) { | 234 void WebstoreInstaller::OnDownloadStarted(DownloadId id, net::Error error) { |
| 233 if (error != net::OK) { | 235 if (error != net::OK) { |
| 234 ReportFailure(net::ErrorToString(error)); | 236 ReportFailure(net::ErrorToString(error)); |
| 235 return; | 237 return; |
| 236 } | 238 } |
| 237 | 239 |
| 238 CHECK(id.IsValid()); | 240 CHECK(id.IsValid()); |
| 239 | 241 |
| 240 content::DownloadManager* download_manager = profile_->GetDownloadManager(); | 242 content::DownloadManager* download_manager = profile_->GetDownloadManager(); |
| 241 download_item_ = download_manager->GetActiveDownloadItem(id.local()); | 243 download_item_ = download_manager->GetActiveDownloadItem(id.local()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 } | 316 } |
| 315 | 317 |
| 316 void WebstoreInstaller::ReportSuccess() { | 318 void WebstoreInstaller::ReportSuccess() { |
| 317 if (delegate_) { | 319 if (delegate_) { |
| 318 delegate_->OnExtensionInstallSuccess(id_); | 320 delegate_->OnExtensionInstallSuccess(id_); |
| 319 delegate_ = NULL; | 321 delegate_ = NULL; |
| 320 } | 322 } |
| 321 | 323 |
| 322 Release(); // Balanced in Start(). | 324 Release(); // Balanced in Start(). |
| 323 } | 325 } |
| OLD | NEW |