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

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

Issue 46583007: Download webstore CRXs into separate directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 1 month 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
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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/metrics/field_trial.h"
14 #include "base/path_service.h"
13 #include "base/rand_util.h" 15 #include "base/rand_util.h"
14 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
18 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chrome_notification_types.h" 21 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/download/download_crx_util.h" 22 #include "chrome/browser/download/download_crx_util.h"
21 #include "chrome/browser/download/download_prefs.h" 23 #include "chrome/browser/download/download_prefs.h"
22 #include "chrome/browser/download/download_stats.h" 24 #include "chrome/browser/download/download_stats.h"
23 #include "chrome/browser/extensions/crx_installer.h" 25 #include "chrome/browser/extensions/crx_installer.h"
24 #include "chrome/browser/extensions/extension_system.h" 26 #include "chrome/browser/extensions/extension_system.h"
25 #include "chrome/browser/extensions/install_tracker.h" 27 #include "chrome/browser/extensions/install_tracker.h"
26 #include "chrome/browser/extensions/install_tracker_factory.h" 28 #include "chrome/browser/extensions/install_tracker_factory.h"
27 #include "chrome/browser/extensions/install_verifier.h" 29 #include "chrome/browser/extensions/install_verifier.h"
28 #include "chrome/browser/profiles/profile.h" 30 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/ui/browser_list.h" 31 #include "chrome/browser/ui/browser_list.h"
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" 32 #include "chrome/browser/ui/tabs/tab_strip_model.h"
33 #include "chrome/common/chrome_paths.h"
31 #include "chrome/common/chrome_switches.h" 34 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/extensions/extension.h" 35 #include "chrome/common/extensions/extension.h"
33 #include "chrome/common/extensions/extension_constants.h" 36 #include "chrome/common/extensions/extension_constants.h"
34 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" 37 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
35 #include "chrome/common/omaha_query_params/omaha_query_params.h" 38 #include "chrome/common/omaha_query_params/omaha_query_params.h"
36 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
37 #include "content/public/browser/download_manager.h" 40 #include "content/public/browser/download_manager.h"
38 #include "content/public/browser/download_save_info.h" 41 #include "content/public/browser/download_save_info.h"
39 #include "content/public/browser/download_url_parameters.h" 42 #include "content/public/browser/download_url_parameters.h"
40 #include "content/public/browser/navigation_controller.h" 43 #include "content/public/browser/navigation_controller.h"
(...skipping 27 matching lines...) Expand all
68 71
69 const char kInvalidIdError[] = "Invalid id"; 72 const char kInvalidIdError[] = "Invalid id";
70 const char kDownloadDirectoryError[] = "Could not create download directory"; 73 const char kDownloadDirectoryError[] = "Could not create download directory";
71 const char kDownloadCanceledError[] = "Download canceled"; 74 const char kDownloadCanceledError[] = "Download canceled";
72 const char kInstallCanceledError[] = "Install canceled"; 75 const char kInstallCanceledError[] = "Install canceled";
73 const char kDownloadInterruptedError[] = "Download interrupted"; 76 const char kDownloadInterruptedError[] = "Download interrupted";
74 const char kInvalidDownloadError[] = 77 const char kInvalidDownloadError[] =
75 "Download was not a valid extension or user script"; 78 "Download was not a valid extension or user script";
76 const char kDependencyNotFoundError[] = "Dependency not found"; 79 const char kDependencyNotFoundError[] = "Dependency not found";
77 const char kDependencyNotSharedModuleError[] = 80 const char kDependencyNotSharedModuleError[] =
78 "Dependency is not shared module"; 81 "Dependency is not shared module";
79 const char kInlineInstallSource[] = "inline"; 82 const char kInlineInstallSource[] = "inline";
80 const char kDefaultInstallSource[] = "ondemand"; 83 const char kDefaultInstallSource[] = "ondemand";
81 const char kAppLauncherInstallSource[] = "applauncher"; 84 const char kAppLauncherInstallSource[] = "applauncher";
82 85
86 // Folder for downloading crx files from the webstore. This is used so that the
87 // crx files don't go via the usual downloads folder.
88 const base::FilePath::CharType kWebstoreDownloadFolder[] =
89 FILE_PATH_LITERAL("Webstore Downloads");
90
83 base::FilePath* g_download_directory_for_tests = NULL; 91 base::FilePath* g_download_directory_for_tests = NULL;
84 92
85 // Must be executed on the FILE thread. 93 // Must be executed on the FILE thread.
86 void GetDownloadFilePath( 94 void GetDownloadFilePath(
87 const base::FilePath& download_directory, const std::string& id, 95 const base::FilePath& download_directory,
96 const std::string& id,
88 const base::Callback<void(const base::FilePath&)>& callback) { 97 const base::Callback<void(const base::FilePath&)>& callback) {
89 base::FilePath directory(g_download_directory_for_tests ? 98 base::FilePath directory(g_download_directory_for_tests ?
90 *g_download_directory_for_tests : download_directory); 99 *g_download_directory_for_tests : download_directory);
91 100
92 #if defined(OS_CHROMEOS) 101 #if defined(OS_CHROMEOS)
93 // Do not use drive for extension downloads. 102 // Do not use drive for extension downloads.
94 if (drive::util::IsUnderDriveMountPoint(directory)) 103 if (drive::util::IsUnderDriveMountPoint(directory))
95 directory = DownloadPrefs::GetDefaultDownloadDirectory(); 104 directory = DownloadPrefs::GetDefaultDownloadDirectory();
96 #endif 105 #endif
97 106
98 // Ensure the download directory exists. TODO(asargent) - make this use 107 // Ensure the download directory exists. TODO(asargent) - make this use
99 // common code from the downloads system. 108 // common code from the downloads system.
100 if (!base::DirectoryExists(directory)) { 109 if (!base::DirectoryExists(directory)) {
(...skipping 18 matching lines...) Expand all
119 file_util::GetUniquePathNumber(file, base::FilePath::StringType()); 128 file_util::GetUniquePathNumber(file, base::FilePath::StringType());
120 if (uniquifier > 0) { 129 if (uniquifier > 0) {
121 file = file.InsertBeforeExtensionASCII( 130 file = file.InsertBeforeExtensionASCII(
122 base::StringPrintf(" (%d)", uniquifier)); 131 base::StringPrintf(" (%d)", uniquifier));
123 } 132 }
124 133
125 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 134 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
126 base::Bind(callback, file)); 135 base::Bind(callback, file));
127 } 136 }
128 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
129 } // namespace 147 } // namespace
130 148
131 namespace extensions { 149 namespace extensions {
132 150
133 // static 151 // static
134 GURL WebstoreInstaller::GetWebstoreInstallURL( 152 GURL WebstoreInstaller::GetWebstoreInstallURL(
135 const std::string& extension_id, InstallSource source) { 153 const std::string& extension_id,
154 InstallSource source) {
136 std::string install_source; 155 std::string install_source;
137 switch (source) { 156 switch (source) {
138 case INSTALL_SOURCE_INLINE: 157 case INSTALL_SOURCE_INLINE:
139 install_source = kInlineInstallSource; 158 install_source = kInlineInstallSource;
140 break; 159 break;
141 case INSTALL_SOURCE_APP_LAUNCHER: 160 case INSTALL_SOURCE_APP_LAUNCHER:
142 install_source = kAppLauncherInstallSource; 161 install_source = kAppLauncherInstallSource;
143 break; 162 break;
144 case INSTALL_SOURCE_OTHER: 163 case INSTALL_SOURCE_OTHER:
145 install_source = kDefaultInstallSource; 164 install_source = kDefaultInstallSource;
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 CHECK(!pending_modules_.empty()); 505 CHECK(!pending_modules_.empty());
487 if (pending_modules_.size() == 1) { 506 if (pending_modules_.size() == 1) {
488 DCHECK_EQ(id_, pending_modules_.front().extension_id); 507 DCHECK_EQ(id_, pending_modules_.front().extension_id);
489 DownloadCrx(id_, install_source_); 508 DownloadCrx(id_, install_source_);
490 } else { 509 } else {
491 DownloadCrx(pending_modules_.front().extension_id, INSTALL_SOURCE_OTHER); 510 DownloadCrx(pending_modules_.front().extension_id, INSTALL_SOURCE_OTHER);
492 } 511 }
493 } 512 }
494 513
495 void WebstoreInstaller::DownloadCrx( 514 void WebstoreInstaller::DownloadCrx(
496 const std::string& extension_id, InstallSource source) { 515 const std::string& extension_id,
516 InstallSource source) {
497 download_url_ = GetWebstoreInstallURL(extension_id, source); 517 download_url_ = GetWebstoreInstallURL(extension_id, source);
498 base::FilePath download_path = DownloadPrefs::FromDownloadManager( 518
499 BrowserContext::GetDownloadManager(profile_))->DownloadPath(); 519 base::FilePath download_path;
520 if (UseSeparateWebstoreDownloadDirectory()) {
521 base::FilePath user_data_dir;
522 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
523 download_path = user_data_dir.Append(kWebstoreDownloadFolder);
524 } else {
525 download_path = DownloadPrefs::FromDownloadManager(
526 BrowserContext::GetDownloadManager(profile_))->DownloadPath();
527 }
528
500 BrowserThread::PostTask( 529 BrowserThread::PostTask(
501 BrowserThread::FILE, FROM_HERE, 530 BrowserThread::FILE, FROM_HERE,
502 base::Bind(&GetDownloadFilePath, download_path, id_, 531 base::Bind(&GetDownloadFilePath, download_path, id_,
503 base::Bind(&WebstoreInstaller::StartDownload, this))); 532 base::Bind(&WebstoreInstaller::StartDownload, this)));
504 } 533 }
505 534
506 // http://crbug.com/165634 535 // http://crbug.com/165634
507 // http://crbug.com/126013 536 // http://crbug.com/126013
508 // The current working theory is that one of the many pointers dereferenced in 537 // The current working theory is that one of the many pointers dereferenced in
509 // here is occasionally deleted before all of its referers are nullified, 538 // here is occasionally deleted before all of its referers are nullified,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 void WebstoreInstaller::ReportSuccess() { 619 void WebstoreInstaller::ReportSuccess() {
591 if (delegate_) { 620 if (delegate_) {
592 delegate_->OnExtensionInstallSuccess(id_); 621 delegate_->OnExtensionInstallSuccess(id_);
593 delegate_ = NULL; 622 delegate_ = NULL;
594 } 623 }
595 624
596 Release(); // Balanced in Start(). 625 Release(); // Balanced in Start().
597 } 626 }
598 627
599 } // namespace extensions 628 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/webstore_private/webstore_private_api.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698