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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <limits> | 9 #include <limits> |
10 #include <set> | 10 #include <set> |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Must be executed on the FILE thread. | 111 // Must be executed on the FILE thread. |
112 void GetDownloadFilePath( | 112 void GetDownloadFilePath( |
113 const base::FilePath& download_directory, | 113 const base::FilePath& download_directory, |
114 const std::string& id, | 114 const std::string& id, |
115 const base::Callback<void(const base::FilePath&)>& callback) { | 115 const base::Callback<void(const base::FilePath&)>& callback) { |
116 // Ensure the download directory exists. TODO(asargent) - make this use | 116 // Ensure the download directory exists. TODO(asargent) - make this use |
117 // common code from the downloads system. | 117 // common code from the downloads system. |
118 if (!base::DirectoryExists(download_directory)) { | 118 if (!base::DirectoryExists(download_directory)) { |
119 if (!base::CreateDirectory(download_directory)) { | 119 if (!base::CreateDirectory(download_directory)) { |
120 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 120 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
121 base::Bind(callback, base::FilePath())); | 121 base::BindOnce(callback, base::FilePath())); |
122 return; | 122 return; |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 // This is to help avoid a race condition between when we generate this | 126 // This is to help avoid a race condition between when we generate this |
127 // filename and when the download starts writing to it (think concurrently | 127 // filename and when the download starts writing to it (think concurrently |
128 // running sharded browser tests installing the same test file, for | 128 // running sharded browser tests installing the same test file, for |
129 // instance). | 129 // instance). |
130 std::string random_number = base::Uint64ToString( | 130 std::string random_number = base::Uint64ToString( |
131 base::RandGenerator(std::numeric_limits<uint16_t>::max())); | 131 base::RandGenerator(std::numeric_limits<uint16_t>::max())); |
132 | 132 |
133 base::FilePath file = | 133 base::FilePath file = |
134 download_directory.AppendASCII(id + "_" + random_number + ".crx"); | 134 download_directory.AppendASCII(id + "_" + random_number + ".crx"); |
135 | 135 |
136 int uniquifier = | 136 int uniquifier = |
137 base::GetUniquePathNumber(file, base::FilePath::StringType()); | 137 base::GetUniquePathNumber(file, base::FilePath::StringType()); |
138 if (uniquifier > 0) { | 138 if (uniquifier > 0) { |
139 file = file.InsertBeforeExtensionASCII( | 139 file = file.InsertBeforeExtensionASCII( |
140 base::StringPrintf(" (%d)", uniquifier)); | 140 base::StringPrintf(" (%d)", uniquifier)); |
141 } | 141 } |
142 | 142 |
143 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 143 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
144 base::Bind(callback, file)); | 144 base::BindOnce(callback, file)); |
145 } | 145 } |
146 | 146 |
147 void MaybeAppendAuthUserParameter(const std::string& authuser, GURL* url) { | 147 void MaybeAppendAuthUserParameter(const std::string& authuser, GURL* url) { |
148 if (authuser.empty()) | 148 if (authuser.empty()) |
149 return; | 149 return; |
150 std::string old_query = url->query(); | 150 std::string old_query = url->query(); |
151 url::Component query(0, old_query.length()); | 151 url::Component query(0, old_query.length()); |
152 url::Component key, value; | 152 url::Component key, value; |
153 // Ensure that the URL doesn't already specify an authuser parameter. | 153 // Ensure that the URL doesn't already specify an authuser parameter. |
154 while (url::ExtractQueryKeyValue( | 154 while (url::ExtractQueryKeyValue( |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 #if defined(OS_CHROMEOS) | 595 #if defined(OS_CHROMEOS) |
596 // Do not use drive for extension downloads. | 596 // Do not use drive for extension downloads. |
597 if (drive::util::IsUnderDriveMountPoint(download_directory)) { | 597 if (drive::util::IsUnderDriveMountPoint(download_directory)) { |
598 download_directory = DownloadPrefs::FromBrowserContext( | 598 download_directory = DownloadPrefs::FromBrowserContext( |
599 profile_)->GetDefaultDownloadDirectoryForProfile(); | 599 profile_)->GetDefaultDownloadDirectoryForProfile(); |
600 } | 600 } |
601 #endif | 601 #endif |
602 | 602 |
603 BrowserThread::PostTask( | 603 BrowserThread::PostTask( |
604 BrowserThread::FILE, FROM_HERE, | 604 BrowserThread::FILE, FROM_HERE, |
605 base::Bind(&GetDownloadFilePath, download_directory, extension_id, | 605 base::BindOnce( |
606 base::Bind(&WebstoreInstaller::StartDownload, this, extension_id))); | 606 &GetDownloadFilePath, download_directory, extension_id, |
| 607 base::Bind(&WebstoreInstaller::StartDownload, this, extension_id))); |
607 } | 608 } |
608 | 609 |
609 // http://crbug.com/165634 | 610 // http://crbug.com/165634 |
610 // http://crbug.com/126013 | 611 // http://crbug.com/126013 |
611 // The current working theory is that one of the many pointers dereferenced in | 612 // The current working theory is that one of the many pointers dereferenced in |
612 // here is occasionally deleted before all of its referers are nullified, | 613 // here is occasionally deleted before all of its referers are nullified, |
613 // probably in a callback race. After this comment is released, the crash | 614 // probably in a callback race. After this comment is released, the crash |
614 // reports should narrow down exactly which pointer it is. Collapsing all the | 615 // reports should narrow down exactly which pointer it is. Collapsing all the |
615 // early-returns into a single branch makes it hard to see exactly which pointer | 616 // early-returns into a single branch makes it hard to see exactly which pointer |
616 // it is. | 617 // it is. |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 1, | 790 1, |
790 kMaxSizeKb, | 791 kMaxSizeKb, |
791 kNumBuckets); | 792 kNumBuckets); |
792 } | 793 } |
793 UMA_HISTOGRAM_BOOLEAN( | 794 UMA_HISTOGRAM_BOOLEAN( |
794 "Extensions.WebstoreDownload.InterruptTotalSizeUnknown", | 795 "Extensions.WebstoreDownload.InterruptTotalSizeUnknown", |
795 total_bytes <= 0); | 796 total_bytes <= 0); |
796 } | 797 } |
797 | 798 |
798 } // namespace extensions | 799 } // namespace extensions |
OLD | NEW |