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 <stdint.h> | |
8 | |
9 #include <limits> | |
10 #include <set> | 7 #include <set> |
11 #include <vector> | 8 #include <vector> |
12 | 9 |
| 10 #include "base/basictypes.h" |
13 #include "base/bind.h" | 11 #include "base/bind.h" |
14 #include "base/command_line.h" | 12 #include "base/command_line.h" |
15 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
16 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
17 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
18 #include "base/metrics/sparse_histogram.h" | 16 #include "base/metrics/sparse_histogram.h" |
19 #include "base/path_service.h" | 17 #include "base/path_service.h" |
20 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
21 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 114 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
117 base::Bind(callback, base::FilePath())); | 115 base::Bind(callback, base::FilePath())); |
118 return; | 116 return; |
119 } | 117 } |
120 } | 118 } |
121 | 119 |
122 // This is to help avoid a race condition between when we generate this | 120 // This is to help avoid a race condition between when we generate this |
123 // filename and when the download starts writing to it (think concurrently | 121 // filename and when the download starts writing to it (think concurrently |
124 // running sharded browser tests installing the same test file, for | 122 // running sharded browser tests installing the same test file, for |
125 // instance). | 123 // instance). |
126 std::string random_number = base::Uint64ToString( | 124 std::string random_number = |
127 base::RandGenerator(std::numeric_limits<uint16_t>::max())); | 125 base::Uint64ToString(base::RandGenerator(kuint16max)); |
128 | 126 |
129 base::FilePath file = | 127 base::FilePath file = |
130 download_directory.AppendASCII(id + "_" + random_number + ".crx"); | 128 download_directory.AppendASCII(id + "_" + random_number + ".crx"); |
131 | 129 |
132 int uniquifier = | 130 int uniquifier = |
133 base::GetUniquePathNumber(file, base::FilePath::StringType()); | 131 base::GetUniquePathNumber(file, base::FilePath::StringType()); |
134 if (uniquifier > 0) { | 132 if (uniquifier > 0) { |
135 file = file.InsertBeforeExtensionASCII( | 133 file = file.InsertBeforeExtensionASCII( |
136 base::StringPrintf(" (%d)", uniquifier)); | 134 base::StringPrintf(" (%d)", uniquifier)); |
137 } | 135 } |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 | 761 |
764 Release(); // Balanced in Start(). | 762 Release(); // Balanced in Start(). |
765 } | 763 } |
766 | 764 |
767 void WebstoreInstaller::RecordInterrupt(const DownloadItem* download) const { | 765 void WebstoreInstaller::RecordInterrupt(const DownloadItem* download) const { |
768 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.WebstoreDownload.InterruptReason", | 766 UMA_HISTOGRAM_SPARSE_SLOWLY("Extensions.WebstoreDownload.InterruptReason", |
769 download->GetLastReason()); | 767 download->GetLastReason()); |
770 | 768 |
771 // Use logarithmic bin sizes up to 1 TB. | 769 // Use logarithmic bin sizes up to 1 TB. |
772 const int kNumBuckets = 30; | 770 const int kNumBuckets = 30; |
773 const int64_t kMaxSizeKb = 1 << kNumBuckets; | 771 const int64 kMaxSizeKb = 1 << kNumBuckets; |
774 UMA_HISTOGRAM_CUSTOM_COUNTS( | 772 UMA_HISTOGRAM_CUSTOM_COUNTS( |
775 "Extensions.WebstoreDownload.InterruptReceivedKBytes", | 773 "Extensions.WebstoreDownload.InterruptReceivedKBytes", |
776 download->GetReceivedBytes() / 1024, | 774 download->GetReceivedBytes() / 1024, |
777 1, | 775 1, |
778 kMaxSizeKb, | 776 kMaxSizeKb, |
779 kNumBuckets); | 777 kNumBuckets); |
780 int64_t total_bytes = download->GetTotalBytes(); | 778 int64 total_bytes = download->GetTotalBytes(); |
781 if (total_bytes >= 0) { | 779 if (total_bytes >= 0) { |
782 UMA_HISTOGRAM_CUSTOM_COUNTS( | 780 UMA_HISTOGRAM_CUSTOM_COUNTS( |
783 "Extensions.WebstoreDownload.InterruptTotalKBytes", | 781 "Extensions.WebstoreDownload.InterruptTotalKBytes", |
784 total_bytes / 1024, | 782 total_bytes / 1024, |
785 1, | 783 1, |
786 kMaxSizeKb, | 784 kMaxSizeKb, |
787 kNumBuckets); | 785 kNumBuckets); |
788 } | 786 } |
789 UMA_HISTOGRAM_BOOLEAN( | 787 UMA_HISTOGRAM_BOOLEAN( |
790 "Extensions.WebstoreDownload.InterruptTotalSizeUnknown", | 788 "Extensions.WebstoreDownload.InterruptTotalSizeUnknown", |
791 total_bytes <= 0); | 789 total_bytes <= 0); |
792 } | 790 } |
793 | 791 |
794 } // namespace extensions | 792 } // namespace extensions |
OLD | NEW |