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

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: Control via field trial. Add UMA for webstore installs. 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/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/ui/browser_list.h" 30 #include "chrome/browser/ui/browser_list.h"
29 #include "chrome/browser/ui/tabs/tab_strip_model.h" 31 #include "chrome/browser/ui/tabs/tab_strip_model.h"
32 #include "chrome/common/chrome_paths.h"
30 #include "chrome/common/chrome_switches.h" 33 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/extensions/extension.h" 34 #include "chrome/common/extensions/extension.h"
32 #include "chrome/common/extensions/extension_constants.h" 35 #include "chrome/common/extensions/extension_constants.h"
33 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" 36 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
34 #include "chrome/common/omaha_query_params/omaha_query_params.h" 37 #include "chrome/common/omaha_query_params/omaha_query_params.h"
35 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/download_manager.h" 39 #include "content/public/browser/download_manager.h"
37 #include "content/public/browser/download_save_info.h" 40 #include "content/public/browser/download_save_info.h"
38 #include "content/public/browser/download_url_parameters.h" 41 #include "content/public/browser/download_url_parameters.h"
39 #include "content/public/browser/navigation_controller.h" 42 #include "content/public/browser/navigation_controller.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 const char kDownloadInterruptedError[] = "Download interrupted"; 75 const char kDownloadInterruptedError[] = "Download interrupted";
73 const char kInvalidDownloadError[] = 76 const char kInvalidDownloadError[] =
74 "Download was not a valid extension or user script"; 77 "Download was not a valid extension or user script";
75 const char kDependencyNotFoundError[] = "Dependency not found"; 78 const char kDependencyNotFoundError[] = "Dependency not found";
76 const char kDependencyNotSharedModuleError[] = 79 const char kDependencyNotSharedModuleError[] =
77 "Dependency is not shared module"; 80 "Dependency is not shared module";
78 const char kInlineInstallSource[] = "inline"; 81 const char kInlineInstallSource[] = "inline";
79 const char kDefaultInstallSource[] = "ondemand"; 82 const char kDefaultInstallSource[] = "ondemand";
80 const char kAppLauncherInstallSource[] = "applauncher"; 83 const char kAppLauncherInstallSource[] = "applauncher";
81 84
85 // Folder for downloading crx files from the webstore. This is used so that the
86 // crx files don't go via the usual downloads folder.
87 const base::FilePath::CharType kWebstoreDownloadFolder[] =
88 FILE_PATH_LITERAL("Webstore Downloads");
89
82 base::FilePath* g_download_directory_for_tests = NULL; 90 base::FilePath* g_download_directory_for_tests = NULL;
83 91
84 // Must be executed on the FILE thread. 92 // Must be executed on the FILE thread.
85 void GetDownloadFilePath( 93 void GetDownloadFilePath(
86 const base::FilePath& download_directory, const std::string& id, 94 const base::FilePath& download_directory, const std::string& id,
87 const base::Callback<void(const base::FilePath&)>& callback) { 95 const base::Callback<void(const base::FilePath&)>& callback) {
88 base::FilePath directory(g_download_directory_for_tests ? 96 base::FilePath directory(g_download_directory_for_tests ?
89 *g_download_directory_for_tests : download_directory); 97 *g_download_directory_for_tests : download_directory);
90 98
91 #if defined(OS_CHROMEOS) 99 #if defined(OS_CHROMEOS)
(...skipping 26 matching lines...) Expand all
118 file_util::GetUniquePathNumber(file, base::FilePath::StringType()); 126 file_util::GetUniquePathNumber(file, base::FilePath::StringType());
119 if (uniquifier > 0) { 127 if (uniquifier > 0) {
120 file = file.InsertBeforeExtensionASCII( 128 file = file.InsertBeforeExtensionASCII(
121 base::StringPrintf(" (%d)", uniquifier)); 129 base::StringPrintf(" (%d)", uniquifier));
122 } 130 }
123 131
124 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 132 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
125 base::Bind(callback, file)); 133 base::Bind(callback, file));
126 } 134 }
127 135
136 bool UseSeparateWebstoreDownloadDirectory() {
137 const char kWebstoreDownloadDirectoryFieldTrialName[] =
138 "WebstoreDownloadDirectory";
139 const char kSeparateDirectoryUnderUDD[] = "SeparateDirectoryUnderUDD";
140
141 std::string field_trial_group = base::FieldTrialList::FindFullName(
142 kWebstoreDownloadDirectoryFieldTrialName);
143 return field_trial_group == kSeparateDirectoryUnderUDD;
144 }
145
128 } // namespace 146 } // namespace
129 147
130 namespace extensions { 148 namespace extensions {
131 149
132 // static 150 // static
133 GURL WebstoreInstaller::GetWebstoreInstallURL( 151 GURL WebstoreInstaller::GetWebstoreInstallURL(
134 const std::string& extension_id, InstallSource source) { 152 const std::string& extension_id, InstallSource source) {
135 std::string install_source; 153 std::string install_source;
136 switch (source) { 154 switch (source) {
137 case INSTALL_SOURCE_INLINE: 155 case INSTALL_SOURCE_INLINE:
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 DCHECK_EQ(id_, pending_modules_.front().extension_id); 498 DCHECK_EQ(id_, pending_modules_.front().extension_id);
481 DownloadCrx(id_, install_source_); 499 DownloadCrx(id_, install_source_);
482 } else { 500 } else {
483 DownloadCrx(pending_modules_.front().extension_id, INSTALL_SOURCE_OTHER); 501 DownloadCrx(pending_modules_.front().extension_id, INSTALL_SOURCE_OTHER);
484 } 502 }
485 } 503 }
486 504
487 void WebstoreInstaller::DownloadCrx( 505 void WebstoreInstaller::DownloadCrx(
488 const std::string& extension_id, InstallSource source) { 506 const std::string& extension_id, InstallSource source) {
489 download_url_ = GetWebstoreInstallURL(extension_id, source); 507 download_url_ = GetWebstoreInstallURL(extension_id, source);
490 base::FilePath download_path = DownloadPrefs::FromDownloadManager( 508
491 BrowserContext::GetDownloadManager(profile_))->DownloadPath(); 509 base::FilePath download_path;
510 if (UseSeparateWebstoreDownloadDirectory()) {
511 base::FilePath user_data_dir;
512 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
513 download_path = user_data_dir.Append(kWebstoreDownloadFolder);
514 } else {
515 download_path = DownloadPrefs::FromDownloadManager(
516 BrowserContext::GetDownloadManager(profile_))->DownloadPath();
517 }
518
492 BrowserThread::PostTask( 519 BrowserThread::PostTask(
493 BrowserThread::FILE, FROM_HERE, 520 BrowserThread::FILE, FROM_HERE,
494 base::Bind(&GetDownloadFilePath, download_path, id_, 521 base::Bind(&GetDownloadFilePath, download_path, id_,
495 base::Bind(&WebstoreInstaller::StartDownload, this))); 522 base::Bind(&WebstoreInstaller::StartDownload, this)));
496 } 523 }
497 524
498 // http://crbug.com/165634 525 // http://crbug.com/165634
499 // http://crbug.com/126013 526 // http://crbug.com/126013
500 // The current working theory is that one of the many pointers dereferenced in 527 // The current working theory is that one of the many pointers dereferenced in
501 // here is occasionally deleted before all of its referers are nullified, 528 // here is occasionally deleted before all of its referers are nullified,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 void WebstoreInstaller::ReportSuccess() { 609 void WebstoreInstaller::ReportSuccess() {
583 if (delegate_) { 610 if (delegate_) {
584 delegate_->OnExtensionInstallSuccess(id_); 611 delegate_->OnExtensionInstallSuccess(id_);
585 delegate_ = NULL; 612 delegate_ = NULL;
586 } 613 }
587 614
588 Release(); // Balanced in Start(). 615 Release(); // Balanced in Start().
589 } 616 }
590 617
591 } // namespace extensions 618 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698