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

Side by Side Diff: chrome/browser/extensions/webstore_installer.cc

Issue 294893002: Download webstore CRXs into separate directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698