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

Side by Side Diff: chrome/test/perf/generate_profile.cc

Issue 94013004: Add base:: to string16s in chrome/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: try again Created 7 years 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 | « chrome/test/chromedriver/util.cc ('k') | chrome/test/perf/startup_test.cc » ('j') | 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/test/perf/generate_profile.h" 5 #include "chrome/test/perf/generate_profile.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_enumerator.h" 10 #include "base/files/file_enumerator.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 inline float RandomFloat() { 48 inline float RandomFloat() {
49 return rand() / static_cast<float>(RAND_MAX); 49 return rand() / static_cast<float>(RAND_MAX);
50 } 50 }
51 51
52 // Return an integer uniformly in [min,max). 52 // Return an integer uniformly in [min,max).
53 inline int RandomInt(int min, int max) { 53 inline int RandomInt(int min, int max) {
54 return min + (rand() % (max-min)); 54 return min + (rand() % (max-min));
55 } 55 }
56 56
57 // Return a string of |count| lowercase random characters. 57 // Return a string of |count| lowercase random characters.
58 string16 RandomChars(int count) { 58 base::string16 RandomChars(int count) {
59 string16 str; 59 base::string16 str;
60 for (int i = 0; i < count; ++i) 60 for (int i = 0; i < count; ++i)
61 str += L'a' + rand() % 26; 61 str += L'a' + rand() % 26;
62 return str; 62 return str;
63 } 63 }
64 64
65 string16 RandomWord() { 65 base::string16 RandomWord() {
66 // TODO(evanm): should we instead use the markov chain based 66 // TODO(evanm): should we instead use the markov chain based
67 // version of this that I already wrote? 67 // version of this that I already wrote?
68 68
69 // Sample a word length from kWordLengthProbabilities. 69 // Sample a word length from kWordLengthProbabilities.
70 float sample = RandomFloat(); 70 float sample = RandomFloat();
71 size_t i; 71 size_t i;
72 for (i = 0; i < arraysize(kWordLengthProbabilities); ++i) { 72 for (i = 0; i < arraysize(kWordLengthProbabilities); ++i) {
73 sample -= kWordLengthProbabilities[i]; 73 sample -= kWordLengthProbabilities[i];
74 if (sample < 0) break; 74 if (sample < 0) break;
75 } 75 }
76 const int word_length = i + 1; 76 const int word_length = i + 1;
77 return RandomChars(word_length); 77 return RandomChars(word_length);
78 } 78 }
79 79
80 // Return a string of |count| random words. 80 // Return a string of |count| random words.
81 string16 RandomWords(int count) { 81 base::string16 RandomWords(int count) {
82 string16 str; 82 base::string16 str;
83 for (int i = 0; i < count; ++i) { 83 for (int i = 0; i < count; ++i) {
84 if (!str.empty()) 84 if (!str.empty())
85 str += L' '; 85 str += L' ';
86 str += RandomWord(); 86 str += RandomWord();
87 } 87 }
88 return str; 88 return str;
89 } 89 }
90 90
91 // Return a random URL-looking string. 91 // Return a random URL-looking string.
92 GURL ConstructRandomURL() { 92 GURL ConstructRandomURL() {
93 return GURL(ASCIIToUTF16("http://") + RandomChars(3) + ASCIIToUTF16(".com/") + 93 return GURL(ASCIIToUTF16("http://") + RandomChars(3) + ASCIIToUTF16(".com/") +
94 RandomChars(RandomInt(5, 20))); 94 RandomChars(RandomInt(5, 20)));
95 } 95 }
96 96
97 // Return a random page title-looking string. 97 // Return a random page title-looking string.
98 string16 ConstructRandomTitle() { 98 base::string16 ConstructRandomTitle() {
99 return RandomWords(RandomInt(3, 15)); 99 return RandomWords(RandomInt(3, 15));
100 } 100 }
101 101
102 // Insert a batch of |batch_size| URLs, starting at pageid |page_id|. 102 // Insert a batch of |batch_size| URLs, starting at pageid |page_id|.
103 void InsertURLBatch(Profile* profile, 103 void InsertURLBatch(Profile* profile,
104 int page_id, 104 int page_id,
105 int batch_size, 105 int batch_size,
106 int types) { 106 int types) {
107 HistoryService* history_service = 107 HistoryService* history_service =
108 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); 108 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 path = file_iterator.Next(); 244 path = file_iterator.Next();
245 } 245 }
246 246
247 printf("Finished creating profiles for testing.\n"); 247 printf("Finished creating profiles for testing.\n");
248 248
249 // Restore the random seed. 249 // Restore the random seed.
250 srand(static_cast<unsigned int>(Time::Now().ToInternalValue())); 250 srand(static_cast<unsigned int>(Time::Now().ToInternalValue()));
251 251
252 return true; 252 return true;
253 } 253 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/util.cc ('k') | chrome/test/perf/startup_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698