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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 base::GetUniquePathNumber(file, base::FilePath::StringType()); | 128 base::GetUniquePathNumber(file, base::FilePath::StringType()); |
129 if (uniquifier > 0) { | 129 if (uniquifier > 0) { |
130 file = file.InsertBeforeExtensionASCII( | 130 file = file.InsertBeforeExtensionASCII( |
131 base::StringPrintf(" (%d)", uniquifier)); | 131 base::StringPrintf(" (%d)", uniquifier)); |
132 } | 132 } |
133 | 133 |
134 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 134 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
135 base::Bind(callback, file)); | 135 base::Bind(callback, file)); |
136 } | 136 } |
137 | 137 |
138 bool UseSeparateWebstoreDownloadDirectory() { | |
139 const char kFieldTrial[] = "WebstoreDownloadDirectory"; | |
140 const char kSeparateDirectoryUnderUDD[] = "SeparateDirectoryUnderUDD"; | |
141 | |
142 std::string field_trial_group = | |
143 base::FieldTrialList::FindFullName(kFieldTrial); | |
144 return field_trial_group == kSeparateDirectoryUnderUDD; | |
145 } | |
146 | |
147 void MaybeAppendAuthUserParameter(const std::string& authuser, GURL* url) { | 138 void MaybeAppendAuthUserParameter(const std::string& authuser, GURL* url) { |
148 if (authuser.empty()) | 139 if (authuser.empty()) |
149 return; | 140 return; |
150 std::string old_query = url->query(); | 141 std::string old_query = url->query(); |
151 url::Component query(0, old_query.length()); | 142 url::Component query(0, old_query.length()); |
152 url::Component key, value; | 143 url::Component key, value; |
153 // Ensure that the URL doesn't already specify an authuser parameter. | 144 // Ensure that the URL doesn't already specify an authuser parameter. |
154 while (url::ExtractQueryKeyValue( | 145 while (url::ExtractQueryKeyValue( |
155 old_query.c_str(), &query, &key, &value)) { | 146 old_query.c_str(), &query, &key, &value)) { |
156 std::string key_string = old_query.substr(key.begin, key.len); | 147 std::string key_string = old_query.substr(key.begin, key.len); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 DownloadCrx(pending_modules_.front().extension_id, INSTALL_SOURCE_OTHER); | 549 DownloadCrx(pending_modules_.front().extension_id, INSTALL_SOURCE_OTHER); |
559 } | 550 } |
560 } | 551 } |
561 | 552 |
562 void WebstoreInstaller::DownloadCrx( | 553 void WebstoreInstaller::DownloadCrx( |
563 const std::string& extension_id, | 554 const std::string& extension_id, |
564 InstallSource source) { | 555 InstallSource source) { |
565 download_url_ = GetWebstoreInstallURL(extension_id, source); | 556 download_url_ = GetWebstoreInstallURL(extension_id, source); |
566 MaybeAppendAuthUserParameter(approval_->authuser, &download_url_); | 557 MaybeAppendAuthUserParameter(approval_->authuser, &download_url_); |
567 | 558 |
568 base::FilePath download_path; | 559 base::FilePath user_data_dir; |
569 if (UseSeparateWebstoreDownloadDirectory()) { | 560 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
570 base::FilePath user_data_dir; | 561 base::FilePath download_path = user_data_dir.Append(kWebstoreDownloadFolder); |
571 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | |
572 download_path = user_data_dir.Append(kWebstoreDownloadFolder); | |
573 } else { | |
574 download_path = DownloadPrefs::FromDownloadManager( | |
575 BrowserContext::GetDownloadManager(profile_))->DownloadPath(); | |
576 } | |
577 | 562 |
578 base::FilePath download_directory(g_download_directory_for_tests ? | 563 base::FilePath download_directory(g_download_directory_for_tests ? |
579 *g_download_directory_for_tests : download_path); | 564 *g_download_directory_for_tests : download_path); |
580 | 565 |
581 #if defined(OS_CHROMEOS) | 566 #if defined(OS_CHROMEOS) |
582 // Do not use drive for extension downloads. | 567 // Do not use drive for extension downloads. |
583 if (drive::util::IsUnderDriveMountPoint(download_directory)) { | 568 if (drive::util::IsUnderDriveMountPoint(download_directory)) { |
584 download_directory = DownloadPrefs::FromBrowserContext( | 569 download_directory = DownloadPrefs::FromBrowserContext( |
585 profile_)->GetDefaultDownloadDirectoryForProfile(); | 570 profile_)->GetDefaultDownloadDirectoryForProfile(); |
586 } | 571 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 1, | 747 1, |
763 kMaxSizeKb, | 748 kMaxSizeKb, |
764 kNumBuckets); | 749 kNumBuckets); |
765 } | 750 } |
766 UMA_HISTOGRAM_BOOLEAN( | 751 UMA_HISTOGRAM_BOOLEAN( |
767 "Extensions.WebstoreDownload.InterruptTotalSizeUnknown", | 752 "Extensions.WebstoreDownload.InterruptTotalSizeUnknown", |
768 total_bytes <= 0); | 753 total_bytes <= 0); |
769 } | 754 } |
770 | 755 |
771 } // namespace extensions | 756 } // namespace extensions |
OLD | NEW |