| Index: chrome/test/perf/generate_profile.cc
|
| diff --git a/chrome/tools/profiles/generate_profile.cc b/chrome/test/perf/generate_profile.cc
|
| similarity index 75%
|
| rename from chrome/tools/profiles/generate_profile.cc
|
| rename to chrome/test/perf/generate_profile.cc
|
| index fbd761eed7db0f2a3ea836de9016fbd78f6ecbac..e3dd38e6a43e45e7298374a0e66c1f246bc7aecf 100644
|
| --- a/chrome/tools/profiles/generate_profile.cc
|
| +++ b/chrome/test/perf/generate_profile.cc
|
| @@ -2,10 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -// This program generates a user profile and history by randomly generating
|
| -// data and feeding it to the history service.
|
| -
|
| -#include "chrome/tools/profiles/thumbnail-inl.h"
|
| +#include "chrome/test/perf/generate_profile.h"
|
|
|
| #include "base/at_exit.h"
|
| #include "base/command_line.h"
|
| @@ -26,27 +23,19 @@
|
| #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 "chrome/tools/profiles/thumbnail-inl.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/notification_service.h"
|
| +#include "content/public/test/test_browser_thread.h"
|
| #include "third_party/skia/include/core/SkBitmap.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
| #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;
|
|
|
| -// Addition types data can be generated for. By default only urls/visits are
|
| -// added.
|
| -enum Types {
|
| - TOP_SITES = 1 << 0,
|
| - FULL_TEXT = 1 << 1
|
| -};
|
| +namespace {
|
|
|
| // RAII for initializing and shutting down the TestBrowserProcess
|
| class InitBrowserProcess {
|
| @@ -71,12 +60,12 @@ const float kWordLengthProbabilities[] = { 0.069f, 0.132f, 0.199f,
|
|
|
| // Return a float uniformly in [0,1].
|
| // Useful for making probabilistic decisions.
|
| -float RandomFloat() {
|
| +inline float RandomFloat() {
|
| return rand() / static_cast<float>(RAND_MAX);
|
| }
|
|
|
| // Return an integer uniformly in [min,max).
|
| -int RandomInt(int min, int max) {
|
| +inline int RandomInt(int min, int max) {
|
| return min + (rand() % (max-min));
|
| }
|
|
|
| @@ -154,10 +143,12 @@ void InsertURLBatch(Profile* profile,
|
| // Scoping value for page IDs (required by the history service).
|
| void* id_scope = reinterpret_cast<void*>(1);
|
|
|
| - scoped_ptr<SkBitmap> google_bitmap(
|
| - gfx::JPEGCodec::Decode(kGoogleThumbnail, sizeof(kGoogleThumbnail)));
|
| - scoped_ptr<SkBitmap> weewar_bitmap(
|
| - gfx::JPEGCodec::Decode(kWeewarThumbnail, sizeof(kWeewarThumbnail)));
|
| + scoped_refptr<base::RefCountedMemory> google_bitmap(
|
| + new base::RefCountedStaticMemory(kGoogleThumbnail,
|
| + sizeof(kGoogleThumbnail)));
|
| + scoped_refptr<base::RefCountedMemory> weewar_bitmap(
|
| + new base::RefCountedStaticMemory(kWeewarThumbnail,
|
| + sizeof(kWeewarThumbnail)));
|
|
|
| printf("Inserting %d URLs...\n", batch_size);
|
| GURL previous_url;
|
| @@ -203,10 +194,10 @@ void InsertURLBatch(Profile* profile,
|
| if (types & FULL_TEXT)
|
| history_service->SetPageContents(url, ConstructRandomPage());
|
| if (types & TOP_SITES && top_sites) {
|
| - const SkBitmap& bitmap = (RandomInt(0, 2) == 0) ? *google_bitmap :
|
| - *weewar_bitmap;
|
| - gfx::Image image = gfx::Image::CreateFrom1xBitmap(bitmap);
|
| - top_sites->SetPageThumbnail(url, image, score);
|
| + top_sites->SetPageThumbnailToJPEGBytes(
|
| + url,
|
| + (RandomInt(0, 2) == 0) ? google_bitmap.get() : weewar_bitmap.get(),
|
| + score);
|
| }
|
|
|
| previous_url = url;
|
| @@ -216,53 +207,26 @@ void InsertURLBatch(Profile* profile,
|
| }
|
| }
|
|
|
| -int main(int argc, char* argv[]) {
|
| - CommandLine::Init(argc, argv);
|
| - base::EnableTerminationOnHeapCorruption();
|
| - base::AtExitManager exit_manager;
|
| - CommandLine* cl = CommandLine::ForCurrentProcess();
|
| -
|
| - int types = 0;
|
| - if (cl->HasSwitch("top-sites"))
|
| - types |= TOP_SITES;
|
| - if (cl->HasSwitch("full-text"))
|
| - types |= FULL_TEXT;
|
| -
|
| - // We require two arguments: urlcount and profiledir.
|
| - const CommandLine::StringVector& args = cl->GetArgs();
|
| - if (args.size() < 2) {
|
| - printf("usage: %s [--top-sites] [--full-text] <urlcount> "
|
| - "<profiledir>\n", argv[0]);
|
| - printf("\n --top-sites Generate thumbnails\n");
|
| - printf("\n --full-text Generate full text index\n");
|
| - return -1;
|
| - }
|
| +} // namespace
|
|
|
| - int url_count = 0;
|
| - base::StringToInt(args[0], &url_count);
|
| - base::FilePath dst_dir(args[1]);
|
| - if (!dst_dir.IsAbsolute()) {
|
| - base::FilePath current_dir;
|
| - file_util::GetCurrentDirectory(¤t_dir);
|
| - dst_dir = current_dir.Append(dst_dir);
|
| - }
|
| +bool GenerateProfile(GenerateProfileTypes types,
|
| + int url_count,
|
| + const base::FilePath& dst_dir) {
|
| if (!file_util::CreateDirectory(dst_dir)) {
|
| PLOG(ERROR) << "Unable to create directory " << dst_dir.value().c_str();
|
| + return false;
|
| }
|
|
|
| - icu_util::Initialize();
|
| - // Copied from base/test/test_suite.cc.
|
| -#if defined(TOOLKIT_GTK)
|
| - gtk_init_check(&argc, &argv);
|
| -#endif
|
| + // We want this profile to be as deterministic as possible, so seed the
|
| + // random number generator with the number of urls we're generating.
|
| + srand(static_cast<unsigned int>(url_count));
|
| +
|
| + printf("Creating profiles for testing...\n");
|
|
|
| InitBrowserProcess initialize_browser_process;
|
| - chrome::RegisterPathProvider();
|
| - ui::RegisterPathProvider();
|
| - MessageLoopForUI message_loop;
|
| - content::BrowserThreadImpl ui_thread(BrowserThread::UI, &message_loop);
|
| - content::BrowserThreadImpl db_thread(BrowserThread::DB, &message_loop);
|
| - ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL);
|
| + base::MessageLoopForUI message_loop;
|
| + content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
|
| + content::TestBrowserThread db_thread(BrowserThread::DB, &message_loop);
|
| TestingProfile profile;
|
| profile.CreateHistoryService(false, false);
|
| if (types & TOP_SITES) {
|
| @@ -270,8 +234,6 @@ int main(int argc, char* argv[]) {
|
| profile.BlockUntilTopSitesLoaded();
|
| }
|
|
|
| - srand(static_cast<unsigned int>(Time::Now().ToInternalValue()));
|
| -
|
| // The maximum number of URLs to insert into history in one batch.
|
| const int kBatchSize = 2000;
|
| int page_id = 0;
|
| @@ -283,8 +245,6 @@ int main(int argc, char* argv[]) {
|
| page_id += batch_size;
|
| }
|
|
|
| - printf("Writing to disk\n");
|
| -
|
| profile.DestroyTopSites();
|
| profile.DestroyHistoryService();
|
|
|
| @@ -296,15 +256,17 @@ int main(int argc, char* argv[]) {
|
| while (!path.empty()) {
|
| base::FilePath dst_file = dst_dir.Append(path.BaseName());
|
| file_util::Delete(dst_file, false);
|
| - printf("Copying file %" PRFilePath " to "
|
| - "%" PRFilePath "\n", path.value().c_str(),
|
| - dst_file.value().c_str());
|
| if (!file_util::CopyFile(path, dst_file)) {
|
| PLOG(ERROR) << "Copying file failed";
|
| - return -1;
|
| + return false;
|
| }
|
| path = file_iterator.Next();
|
| }
|
|
|
| - return 0;
|
| + printf("Finished creating profiles for testing.\n");
|
| +
|
| + // Restore the random seed.
|
| + srand(static_cast<unsigned int>(Time::Now().ToInternalValue()));
|
| +
|
| + return true;
|
| }
|
|
|