Chromium Code Reviews| Index: chrome/tools/profiles/generate_profile.cc |
| diff --git a/chrome/tools/profiles/generate_profile.cc b/chrome/tools/profiles/generate_profile.cc |
| index ca4ee3e01339f09af6221865efe06139f8de48d8..06cc0e639ea07cbf1da9bf189efe7cd4dbbeff21 100644 |
| --- a/chrome/tools/profiles/generate_profile.cc |
| +++ b/chrome/tools/profiles/generate_profile.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/file_path.h" |
| #include "base/file_util.h" |
| #include "base/i18n/icu_util.h" |
| +#include "base/logging.h" |
| #include "base/message_loop.h" |
| #include "base/path_service.h" |
| #include "base/process_util.h" |
| @@ -23,6 +24,7 @@ |
| #include "chrome/browser/history/top_sites.h" |
| #include "chrome/common/chrome_paths.h" |
| #include "chrome/common/thumbnail_score.h" |
| +#include "chrome/test/base/testing_browser_process.h" |
| #include "chrome/test/base/testing_profile.h" |
| #include "content/browser/browser_thread_impl.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -32,9 +34,20 @@ |
| #include "ui/base/ui_base_paths.h" |
| #include "ui/gfx/codec/jpeg_codec.h" |
| +#if defined(TOOLKIT_GTK) |
| +#include <gtk/gtk.h> |
| +#endif |
| + |
| using base::Time; |
| using content::BrowserThread; |
| +// This is unfortunately dependent on the definition of FilePath::StringType. |
|
Mark Mentovai
2012/12/19 19:11:26
You can use |"%" PRFilePath|, apparently. I didn’t
Randy Smith (Not in Mondays)
2012/12/19 19:46:47
The more you know! Thank you. Done.
|
| +#if defined(OS_WIN) |
| +#define FILE_PATH_VALUE_PRINTF "%ls" |
| +#else |
| +#define FILE_PATH_VALUE_PRINTF "%s" |
| +#endif |
| + |
| // Addition types data can be generated for. By default only urls/visits are |
| // added. |
| enum Types { |
| @@ -42,6 +55,21 @@ enum Types { |
| FULL_TEXT = 1 << 1 |
| }; |
| +// RAII for initializing and shutting down the TestBrowserProcess |
| +class InitBrowserProcess { |
| + public: |
| + InitBrowserProcess() { |
| + DCHECK(!g_browser_process); |
| + g_browser_process = new TestingBrowserProcess; |
| + } |
| + |
| + ~InitBrowserProcess() { |
| + DCHECK(g_browser_process); |
| + delete g_browser_process; |
| + g_browser_process = NULL; |
| + } |
| +}; |
| + |
| // Probabilities of different word lengths, as measured from Darin's profile. |
| // kWordLengthProbabilities[n-1] = P(word of length n) |
| const float kWordLengthProbabilities[] = { 0.069f, 0.132f, 0.199f, |
| @@ -60,20 +88,20 @@ int RandomInt(int min, int max) { |
| } |
| // Return a string of |count| lowercase random characters. |
| -std::wstring RandomChars(int count) { |
| - std::wstring str; |
| +string16 RandomChars(int count) { |
| + string16 str; |
| for (int i = 0; i < count; ++i) |
| str += L'a' + rand() % 26; |
| return str; |
| } |
| -std::wstring RandomWord() { |
| +string16 RandomWord() { |
| // TODO(evanm): should we instead use the markov chain based |
| // version of this that I already wrote? |
| // Sample a word length from kWordLengthProbabilities. |
| float sample = RandomFloat(); |
| - int i; |
| + size_t i; |
| for (i = 0; i < arraysize(kWordLengthProbabilities); ++i) { |
| sample -= kWordLengthProbabilities[i]; |
| if (sample < 0) break; |
| @@ -83,8 +111,8 @@ std::wstring RandomWord() { |
| } |
| // Return a string of |count| random words. |
| -std::wstring RandomWords(int count) { |
| - std::wstring str; |
| +string16 RandomWords(int count) { |
| + string16 str; |
| for (int i = 0; i < count; ++i) { |
| if (!str.empty()) |
| str += L' '; |
| @@ -95,17 +123,17 @@ std::wstring RandomWords(int count) { |
| // Return a random URL-looking string. |
| GURL ConstructRandomURL() { |
| - return GURL(std::wstring(L"http://") + RandomChars(3) + L".com/" + |
| + return GURL(ASCIIToUTF16("http://") + RandomChars(3) + ASCIIToUTF16(".com/") + |
| RandomChars(RandomInt(5, 20))); |
| } |
| // Return a random page title-looking string. |
| -std::wstring ConstructRandomTitle() { |
| +string16 ConstructRandomTitle() { |
| return RandomWords(RandomInt(3, 15)); |
| } |
| // Return a random string that could function as page contents. |
| -std::wstring ConstructRandomPage() { |
| +string16 ConstructRandomPage() { |
| return RandomWords(RandomInt(10, 4000)); |
| } |
| @@ -195,7 +223,7 @@ void InsertURLBatch(Profile* profile, |
| } |
| } |
| -int main(int argc, const char* argv[]) { |
| +int main(int argc, char* argv[]) { |
| CommandLine::Init(argc, argv); |
| base::EnableTerminationOnHeapCorruption(); |
| base::AtExitManager exit_manager; |
| @@ -208,7 +236,7 @@ int main(int argc, const char* argv[]) { |
| types |= FULL_TEXT; |
| // We require two arguments: urlcount and profiledir. |
| - const CommandLine::StringVector& args = cl->GetArgs(); |
| + const CommandLine::StringVector& args = cl->GetArgs(); |
|
Mark Mentovai
2012/12/19 19:11:26
Fix the indentation.
Randy Smith (Not in Mondays)
2012/12/19 19:46:47
Whoops; done.
|
| if (args.size() < 2) { |
| printf("usage: %s [--top-sites] [--full-text] <urlcount> " |
| "<profiledir>\n", argv[0]); |
| @@ -218,7 +246,7 @@ int main(int argc, const char* argv[]) { |
| } |
| int url_count = 0; |
| - base::StringToInt(WideToUTF8(args[0]), &url_count); |
| + base::StringToInt(args[0], &url_count); |
| FilePath dst_dir(args[1]); |
| if (!dst_dir.IsAbsolute()) { |
| FilePath current_dir; |
| @@ -226,21 +254,22 @@ int main(int argc, const char* argv[]) { |
| dst_dir = current_dir.Append(dst_dir); |
| } |
| if (!file_util::CreateDirectory(dst_dir)) { |
| - printf("Unable to create directory %ls: %d\n", |
| - dst_dir.value().c_str(), |
| - ::GetLastError()); |
| + PLOG(ERROR) << "Unable to create directory " << dst_dir.value().c_str(); |
| } |
| icu_util::Initialize(); |
| + // Copied from base/test/test_suite.cc. |
| +#if defined(TOOLKIT_GTK) |
| + gtk_init_check(&argc, &argv); |
| +#endif |
| + InitBrowserProcess initialize_browser_process; |
| chrome::RegisterPathProvider(); |
| ui::RegisterPathProvider(); |
| - ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); |
| - scoped_ptr<content::NotificationService> notification_service( |
| - content::NotificationService::Create()); |
| MessageLoopForUI message_loop; |
| content::BrowserThreadImpl ui_thread(BrowserThread::UI, &message_loop); |
| content::BrowserThreadImpl db_thread(BrowserThread::DB, &message_loop); |
| + ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); |
| TestingProfile profile; |
| profile.CreateHistoryService(false, false); |
| if (types & TOP_SITES) { |
| @@ -274,10 +303,11 @@ int main(int argc, const char* argv[]) { |
| while (!path.empty()) { |
| FilePath dst_file = dst_dir.Append(path.BaseName()); |
| file_util::Delete(dst_file, false); |
| - printf("Copying file %ls to %ls\n", path.value().c_str(), |
| + printf("Copying file " FILE_PATH_VALUE_PRINTF " to " |
|
Mark Mentovai
2012/12/19 19:11:26
Is it even necessary to use printf instead of, say
Randy Smith (Not in Mondays)
2012/12/19 19:46:47
Hmmm. I'm torn on this. That would be simpler fr
|
| + FILE_PATH_VALUE_PRINTF "\n", path.value().c_str(), |
| dst_file.value().c_str()); |
| if (!file_util::CopyFile(path, dst_file)) { |
| - printf("Copying file failed: %d\n", ::GetLastError()); |
| + PLOG(ERROR) << "Copying file failed"; |
| return -1; |
| } |
| path = file_iterator.Next(); |