Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
Deprecate wstring version of PathService::Get() in webkit.
Browse files Browse the repository at this point in the history
Review URL: http://codereview.chromium.org/99266

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15032 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
thestig@chromium.org committed May 1, 2009
1 parent 7fd3029 commit c4ad98c
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 42 deletions.
4 changes: 2 additions & 2 deletions base/event_recorder.cc
Expand Up @@ -42,7 +42,7 @@ EventRecorder::~EventRecorder() {
DCHECK(!is_recording_ && !is_playing_);
}

bool EventRecorder::StartRecording(const std::wstring& filename) {
bool EventRecorder::StartRecording(const FilePath& filename) {
if (journal_hook_ != NULL)
return false;
if (is_recording_ || is_playing_)
Expand Down Expand Up @@ -93,7 +93,7 @@ void EventRecorder::StopRecording() {
}
}

bool EventRecorder::StartPlayback(const std::wstring& filename) {
bool EventRecorder::StartPlayback(const FilePath& filename) {
if (journal_hook_ != NULL)
return false;
if (is_recording_ || is_playing_)
Expand Down
6 changes: 4 additions & 2 deletions base/event_recorder.h
Expand Up @@ -11,6 +11,8 @@
#endif
#include "base/basictypes.h"

class FilePath;

namespace base {

// A class for recording and playing back keyboard and mouse input events.
Expand Down Expand Up @@ -39,7 +41,7 @@ class EventRecorder {
// Starts recording events.
// Will clobber the file if it already exists.
// Returns true on success, or false if an error occurred.
bool StartRecording(const std::wstring& filename);
bool StartRecording(const FilePath& filename);

// Stops recording.
void StopRecording();
Expand All @@ -49,7 +51,7 @@ class EventRecorder {

// Plays events previously recorded.
// Returns true on success, or false if an error occurred.
bool StartPlayback(const std::wstring& filename);
bool StartPlayback(const FilePath& filename);

// Stops playback.
void StopPlayback();
Expand Down
4 changes: 2 additions & 2 deletions base/event_recorder_stubs.cc
Expand Up @@ -11,14 +11,14 @@ namespace base {

EventRecorder* EventRecorder::current_; // Our singleton.

bool EventRecorder::StartRecording(const std::wstring& filename) {
bool EventRecorder::StartRecording(const FilePath& filename) {
return true;
}

void EventRecorder::StopRecording() {
}

bool EventRecorder::StartPlayback(const std::wstring& filename) {
bool EventRecorder::StartPlayback(const FilePath& filename) {
return false;
}

Expand Down
7 changes: 4 additions & 3 deletions chrome/browser/browser_init.cc
Expand Up @@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/event_recorder.h"
#include "base/file_path.h"
#include "base/histogram.h"
#include "base/path_service.h"
#include "base/string_util.h"
Expand Down Expand Up @@ -97,10 +98,10 @@ void SetOverrideHomePage(const CommandLine& command_line,
PrefService* prefs) {
// If homepage is specified on the command line, canonify & store it.
if (command_line.HasSwitch(switches::kHomePage)) {
std::wstring browser_directory;
FilePath browser_directory;
PathService::Get(base::DIR_CURRENT, &browser_directory);
std::wstring new_homepage = URLFixerUpper::FixupRelativeFile(
browser_directory,
browser_directory.ToWStringHack(),
command_line.GetSwitchValue(switches::kHomePage));
prefs->transient()->SetString(prefs::kHomePage, new_homepage);
prefs->transient()->SetBoolean(prefs::kHomePageIsNewTabPage, false);
Expand Down Expand Up @@ -250,7 +251,7 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile,
// If we're recording or playing back, startup the EventRecorder now
// unless otherwise specified.
if (!command_line_.HasSwitch(switches::kNoEvents)) {
std::wstring script_path;
FilePath script_path;
PathService::Get(chrome::FILE_RECORDED_SCRIPT, &script_path);

bool record_mode = command_line_.HasSwitch(switches::kRecordMode);
Expand Down
5 changes: 4 additions & 1 deletion webkit/tools/test_shell/image_decoder_unittest.cc
Expand Up @@ -6,6 +6,7 @@

#include "webkit/tools/test_shell/image_decoder_unittest.h"

#include "base/file_path.h"
#include "base/file_util.h"
#include "base/md5.h"
#include "base/path_service.h"
Expand Down Expand Up @@ -78,7 +79,9 @@ void VerifyImage(WebCore::ImageDecoder* decoder,
#endif

void ImageDecoderTest::SetUp() {
ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_dir_));
FilePath data_dir;
ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &data_dir));
data_dir_ = data_dir.ToWStringHack();
file_util::AppendToPath(&data_dir_, L"webkit");
file_util::AppendToPath(&data_dir_, L"data");
file_util::AppendToPath(&data_dir_, format_ + L"_decoder");
Expand Down
8 changes: 4 additions & 4 deletions webkit/tools/test_shell/layout_test_controller.cc
Expand Up @@ -9,7 +9,7 @@
#include "webkit/tools/test_shell/layout_test_controller.h"

#include "base/basictypes.h"
#include "base/file_util.h"
#include "base/file_path.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/path_service.h"
Expand Down Expand Up @@ -596,10 +596,10 @@ void LayoutTestController::pathToLocalResource(
std::string url = args[0].ToString();
if (StartsWithASCII(url, "/tmp/", true)) {
// We want a temp file.
std::wstring path;
FilePath path;
PathService::Get(base::DIR_TEMP, &path);
file_util::AppendToPath(&path, UTF8ToWide(url.substr(5)));
result->Set(WideToUTF8(path));
path = path.AppendASCII(url.substr(5));
result->Set(WideToUTF8(path.ToWStringHack()));
return;
}

Expand Down
10 changes: 5 additions & 5 deletions webkit/tools/test_shell/node_leak_test.cc
Expand Up @@ -3,7 +3,7 @@
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/file_util.h"
#include "base/file_path.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "net/http/http_cache.h"
Expand Down Expand Up @@ -37,11 +37,11 @@ class NodeLeakTest : public TestShellTest {
js_flags += L" --expose-gc";
webkit_glue::SetJavaScriptFlags(js_flags);

std::wstring cache_path =
parsed_command_line.GetSwitchValue(test_shell::kCacheDir);
FilePath cache_path = FilePath::FromWStringHack(
parsed_command_line.GetSwitchValue(test_shell::kCacheDir));
if (cache_path.empty()) {
PathService::Get(base::DIR_EXE, &cache_path);
file_util::AppendToPath(&cache_path, L"cache");
cache_path = cache_path.AppendASCII("cache");
}

if (parsed_command_line.HasSwitch(test_shell::kTestShellTimeOut)) {
Expand All @@ -58,7 +58,7 @@ class NodeLeakTest : public TestShellTest {
parsed_command_line.HasSwitch(test_shell::kPlaybackMode) ?
net::HttpCache::PLAYBACK : net::HttpCache::NORMAL;
SimpleResourceLoaderBridge::Init(
new TestShellRequestContext(cache_path, mode, false));
new TestShellRequestContext(cache_path.ToWStringHack(), mode, false));

TestShellTest::SetUp();
}
Expand Down
19 changes: 11 additions & 8 deletions webkit/tools/test_shell/test_shell.cc
Expand Up @@ -66,13 +66,12 @@ class URLRequestTestShellFileJob : public URLRequestFileJob {

static URLRequestJob* InspectorFactory(URLRequest* request,
const std::string& scheme) {
std::wstring path;
FilePath path;
PathService::Get(base::DIR_EXE, &path);
file_util::AppendToPath(&path, L"resources");
file_util::AppendToPath(&path, L"inspector");
file_util::AppendToPath(&path, UTF8ToWide(request->url().path()));
return new URLRequestTestShellFileJob(request,
FilePath::FromWStringHack(path));
path = path.AppendASCII("resources");
path = path.AppendASCII("inspector");
path = path.AppendASCII(request->url().path());
return new URLRequestTestShellFileJob(request, path);
}

private:
Expand Down Expand Up @@ -583,7 +582,11 @@ void AppendToLog(const char* file, int line, const char* msg) {
}

bool GetApplicationDirectory(std::wstring *path) {
return PathService::Get(base::DIR_EXE, path);
bool r;
FilePath fp;
r = PathService::Get(base::DIR_EXE, &fp);
*path = fp.ToWStringHack();
return r;
}

GURL GetInspectorURL() {
Expand All @@ -595,7 +598,7 @@ std::string GetUIResourceProtocol() {
}

bool GetExeDirectory(std::wstring *path) {
return PathService::Get(base::DIR_EXE, path);
return GetApplicationDirectory(path);
}

bool SpellCheckWord(const wchar_t* word, int word_len,
Expand Down
32 changes: 17 additions & 15 deletions webkit/tools/test_shell/test_shell_main.cc
Expand Up @@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/event_recorder.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/icu_util.h"
#include "base/memory_debug.h"
Expand Down Expand Up @@ -122,20 +123,21 @@ int main(int argc, char* argv[]) {
parsed_command_line.HasSwitch(test_shell::kEnableFileCookies))
net::CookieMonster::EnableFileScheme();

std::wstring cache_path =
parsed_command_line.GetSwitchValue(test_shell::kCacheDir);
FilePath cache_path = FilePath::FromWStringHack(
parsed_command_line.GetSwitchValue(test_shell::kCacheDir));
// If the cache_path is empty and it's layout_test_mode, leave it empty
// so we use an in-memory cache. This makes running multiple test_shells
// in parallel less flaky.
if (cache_path.empty() && !layout_test_mode) {
PathService::Get(base::DIR_EXE, &cache_path);
file_util::AppendToPath(&cache_path, L"cache");
cache_path = cache_path.AppendASCII("cache");
}

// Initializing with a default context, which means no on-disk cookie DB,
// and no support for directory listings.
SimpleResourceLoaderBridge::Init(
new TestShellRequestContext(cache_path, cache_mode, layout_test_mode));
new TestShellRequestContext(cache_path.ToWStringHack(),
cache_mode, layout_test_mode));

// Load ICU data tables
icu_util::Initialize();
Expand Down Expand Up @@ -169,20 +171,20 @@ int main(int argc, char* argv[]) {
}

// Treat the first loose value as the initial URL to open.
std::wstring uri;
FilePath uri;

// Default to a homepage if we're interactive.
if (!layout_test_mode) {
PathService::Get(base::DIR_SOURCE_ROOT, &uri);
file_util::AppendToPath(&uri, L"webkit");
file_util::AppendToPath(&uri, L"data");
file_util::AppendToPath(&uri, L"test_shell");
file_util::AppendToPath(&uri, L"index.html");
uri = uri.AppendASCII("webkit");
uri = uri.AppendASCII("data");
uri = uri.AppendASCII("test_shell");
uri = uri.AppendASCII("index.html");
}

std::vector<std::wstring> loose_values = parsed_command_line.GetLooseValues();
if (loose_values.size() > 0)
uri = loose_values[0];
uri = FilePath::FromWStringHack(loose_values[0]);

std::wstring js_flags =
parsed_command_line.GetSwitchValue(test_shell::kJavaScriptFlags);
Expand All @@ -207,7 +209,7 @@ int main(int argc, char* argv[]) {
StatsTable::set_current(table);

TestShell* shell;
if (TestShell::CreateNewWindow(uri, &shell)) {
if (TestShell::CreateNewWindow(uri.ToWStringHack(), &shell)) {
if (record_mode || playback_mode) {
platform.SetWindowPositionForRecording(shell);
WebKit::registerExtension(extensions_v8::PlaybackExtension::Get());
Expand All @@ -220,10 +222,10 @@ int main(int argc, char* argv[]) {

bool no_events = parsed_command_line.HasSwitch(test_shell::kNoEvents);
if ((record_mode || playback_mode) && !no_events) {
std::wstring script_path = cache_path;
FilePath script_path = cache_path;
// Create the cache directory in case it doesn't exist.
file_util::CreateDirectory(cache_path);
file_util::AppendToPath(&script_path, L"script.log");
script_path = script_path.AppendASCII("script.log");
if (record_mode)
base::EventRecorder::current()->StartRecording(script_path);
if (playback_mode)
Expand Down Expand Up @@ -259,7 +261,7 @@ int main(int argc, char* argv[]) {
params.dump_tree = false;
}

if (uri.length() == 0) {
if (uri.empty()) {
// Watch stdin for URLs.
char filenameBuffer[kPathBufSize];
while (fgets(filenameBuffer, sizeof(filenameBuffer), stdin)) {
Expand Down Expand Up @@ -293,7 +295,7 @@ int main(int argc, char* argv[]) {
} else {
// TODO(ojan): Provide a way for run-singly tests to pass
// in a hash and then set params.pixel_hash here.
params.test_url = WideToUTF8(uri).c_str();
params.test_url = WideToUTF8(uri.ToWStringHack()).c_str();
TestShell::RunFileTest(params);
}

Expand Down

0 comments on commit c4ad98c

Please sign in to comment.