0

Cleanup dead code in base/ as found by Scythe.

Some parts just needed to be ifdefed.

Review URL: https://codereview.chromium.org/853903003

Cr-Commit-Position: refs/heads/master@{#312576}
This commit is contained in:
thestig
2015-01-21 23:09:45 -08:00
committed by Commit bot
parent eba5a5efbe
commit 88c7b3339b
13 changed files with 28 additions and 438 deletions

@ -186,9 +186,6 @@ component("base") {
"deferred_sequenced_task_runner.h",
"environment.cc",
"environment.h",
"event_recorder.h",
"event_recorder_stubs.cc",
"event_recorder_win.cc",
"file_descriptor_posix.h",
"file_version_info.h",
"file_version_info_mac.h",
@ -859,7 +856,6 @@ component("base") {
# Windows.
if (is_win) {
sources -= [
"event_recorder_stubs.cc",
"message_loop/message_pump_libevent.cc",
"strings/string16.cc",

@ -230,15 +230,10 @@
}],
],
'sources': [
'third_party/xdg_user_dirs/xdg_user_dir_lookup.cc',
'third_party/xdg_user_dirs/xdg_user_dir_lookup.h',
'async_socket_io_handler.h',
'async_socket_io_handler_posix.cc',
'async_socket_io_handler_win.cc',
'auto_reset.h',
'event_recorder.h',
'event_recorder_stubs.cc',
'event_recorder_win.cc',
'linux_util.cc',
'linux_util.h',
'message_loop/message_pump_android.cc',
@ -256,8 +251,10 @@
'posix/file_descriptor_shuffle.cc',
'posix/file_descriptor_shuffle.h',
'sync_socket.h',
'sync_socket_win.cc',
'sync_socket_posix.cc',
'sync_socket_win.cc',
'third_party/xdg_user_dirs/xdg_user_dir_lookup.cc',
'third_party/xdg_user_dirs/xdg_user_dir_lookup.h',
],
'includes': [
'../build/android/increase_size_for_speed.gypi',
@ -1166,15 +1163,10 @@
4267,
],
'sources': [
'third_party/xdg_user_dirs/xdg_user_dir_lookup.cc',
'third_party/xdg_user_dirs/xdg_user_dir_lookup.h',
'async_socket_io_handler.h',
'async_socket_io_handler_posix.cc',
'async_socket_io_handler_win.cc',
'auto_reset.h',
'event_recorder.h',
'event_recorder_stubs.cc',
'event_recorder_win.cc',
'linux_util.cc',
'linux_util.h',
'md5.cc',
@ -1186,8 +1178,10 @@
'posix/file_descriptor_shuffle.cc',
'posix/file_descriptor_shuffle.h',
'sync_socket.h',
'sync_socket_win.cc',
'sync_socket_posix.cc',
'sync_socket_win.cc',
'third_party/xdg_user_dirs/xdg_user_dir_lookup.cc',
'third_party/xdg_user_dirs/xdg_user_dir_lookup.h',
],
},
{

@ -929,7 +929,6 @@
'<(DEPTH)/third_party/wtl/include',
],
'sources!': [
'event_recorder_stubs.cc',
'files/file_path_watcher_fsevents.cc',
'files/file_path_watcher_fsevents.h',
'files/file_path_watcher_kqueue.cc',

@ -745,7 +745,6 @@ class BASE_EXPORT TraceLog {
// This lock protects accesses to thread_names_, thread_event_start_times_
// and thread_colors_.
Lock thread_info_lock_;
int locked_line_;
Mode mode_;
int num_traces_recorded_;
scoped_ptr<TraceBuffer> logged_events_;

@ -1,109 +0,0 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_EVENT_RECORDER_H_
#define BASE_EVENT_RECORDER_H_
#include "base/base_export.h"
#include "base/basictypes.h"
#include "build/build_config.h"
#if defined(OS_WIN)
#include <stdio.h>
#include <string.h>
#include <windows.h>
#endif
namespace base {
class FilePath;
// A class for recording and playing back keyboard and mouse input events.
//
// Note - if you record events, and the playback with the windows in
// different sizes or positions, the playback will fail. When
// recording and playing, you should move the relevant windows
// to constant sizes and locations.
// TODO(mbelshe) For now this is a singleton. I believe that this class
// could be easily modified to:
// support two simultaneous recorders
// be playing back events while already recording events.
// Why? Imagine if the product had a "record a macro" feature.
// You might be recording globally, while recording or playing back
// a macro. I don't think two playbacks make sense.
class BASE_EXPORT EventRecorder {
public:
// Get the singleton EventRecorder.
// We can only handle one recorder/player at a time.
static EventRecorder* current() {
if (!current_)
current_ = new EventRecorder();
return current_;
}
// Starts recording events.
// Will clobber the file if it already exists.
// Returns true on success, or false if an error occurred.
bool StartRecording(const FilePath& filename);
// Stops recording.
void StopRecording();
// Is the EventRecorder currently recording.
bool is_recording() const { return is_recording_; }
// Plays events previously recorded.
// Returns true on success, or false if an error occurred.
bool StartPlayback(const FilePath& filename);
// Stops playback.
void StopPlayback();
// Is the EventRecorder currently playing.
bool is_playing() const { return is_playing_; }
#if defined(OS_WIN)
// C-style callbacks for the EventRecorder.
// Used for internal purposes only.
LRESULT RecordWndProc(int nCode, WPARAM wParam, LPARAM lParam);
LRESULT PlaybackWndProc(int nCode, WPARAM wParam, LPARAM lParam);
#endif
private:
// Create a new EventRecorder. Events are saved to the file filename.
// If the file already exists, it will be deleted before recording
// starts.
EventRecorder()
: is_recording_(false),
is_playing_(false),
#if defined(OS_WIN)
journal_hook_(NULL),
file_(NULL),
#endif
playback_first_msg_time_(0),
playback_start_time_(0) {
#if defined(OS_WIN)
memset(&playback_msg_, 0, sizeof(playback_msg_));
#endif
}
~EventRecorder();
static EventRecorder* current_; // Our singleton.
bool is_recording_;
bool is_playing_;
#if defined(OS_WIN)
HHOOK journal_hook_;
FILE* file_;
EVENTMSG playback_msg_;
#endif
int playback_first_msg_time_;
int playback_start_time_;
DISALLOW_COPY_AND_ASSIGN(EventRecorder);
};
} // namespace base
#endif // BASE_EVENT_RECORDER_H_

@ -1,28 +0,0 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/event_recorder.h"
// This file implements a link stub for EventRecorder that can be used on
// platforms that don't have a working EventRecorder implementation.
namespace base {
EventRecorder* EventRecorder::current_; // Our singleton.
bool EventRecorder::StartRecording(const FilePath& filename) {
return true;
}
void EventRecorder::StopRecording() {
}
bool EventRecorder::StartPlayback(const FilePath& filename) {
return false;
}
void EventRecorder::StopPlayback() {
}
} // namespace

@ -1,258 +0,0 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include <windows.h>
#include <mmsystem.h>
#include "base/event_recorder.h"
#include "base/files/file_util.h"
#include "base/logging.h"
// A note about time.
// For perfect playback of events, you'd like a very accurate timer
// so that events are played back at exactly the same time that
// they were recorded. However, windows has a clock which is only
// granular to ~15ms. We see more consistent event playback when
// using a higher resolution timer. To do this, we use the
// timeGetTime API instead of the default GetTickCount() API.
namespace base {
EventRecorder* EventRecorder::current_ = NULL;
LRESULT CALLBACK StaticRecordWndProc(int nCode, WPARAM wParam,
LPARAM lParam) {
DCHECK(EventRecorder::current());
return EventRecorder::current()->RecordWndProc(nCode, wParam, lParam);
}
LRESULT CALLBACK StaticPlaybackWndProc(int nCode, WPARAM wParam,
LPARAM lParam) {
DCHECK(EventRecorder::current());
return EventRecorder::current()->PlaybackWndProc(nCode, wParam, lParam);
}
EventRecorder::~EventRecorder() {
// Try to assert early if the caller deletes the recorder
// while it is still in use.
DCHECK(!journal_hook_);
DCHECK(!is_recording_ && !is_playing_);
}
bool EventRecorder::StartRecording(const FilePath& filename) {
if (journal_hook_ != NULL)
return false;
if (is_recording_ || is_playing_)
return false;
// Open the recording file.
DCHECK(!file_);
file_ = OpenFile(filename, "wb+");
if (!file_) {
DLOG(ERROR) << "EventRecorder could not open log file";
return false;
}
// Set the faster clock, if possible.
::timeBeginPeriod(1);
// Set the recording hook. JOURNALRECORD can only be used as a global hook.
journal_hook_ = ::SetWindowsHookEx(WH_JOURNALRECORD, StaticRecordWndProc,
GetModuleHandle(NULL), 0);
if (!journal_hook_) {
DLOG(ERROR) << "EventRecorder Record Hook failed";
CloseFile(file_);
return false;
}
is_recording_ = true;
return true;
}
void EventRecorder::StopRecording() {
if (is_recording_) {
DCHECK(journal_hook_ != NULL);
if (!::UnhookWindowsHookEx(journal_hook_)) {
DLOG(ERROR) << "EventRecorder Unhook failed";
// Nothing else we can really do here.
return;
}
::timeEndPeriod(1);
DCHECK(file_ != NULL);
CloseFile(file_);
file_ = NULL;
journal_hook_ = NULL;
is_recording_ = false;
}
}
bool EventRecorder::StartPlayback(const FilePath& filename) {
if (journal_hook_ != NULL)
return false;
if (is_recording_ || is_playing_)
return false;
// Open the recording file.
DCHECK(!file_);
file_ = OpenFile(filename, "rb");
if (!file_) {
DLOG(ERROR) << "EventRecorder Playback could not open log file";
return false;
}
// Read the first event from the record.
if (fread(&playback_msg_, sizeof(EVENTMSG), 1, file_) != 1) {
DLOG(ERROR) << "EventRecorder Playback has no records!";
CloseFile(file_);
return false;
}
// Set the faster clock, if possible.
::timeBeginPeriod(1);
// Playback time is tricky. When playing back, we read a series of events,
// each with timeouts. Simply subtracting the delta between two timers will
// lead to fast playback (about 2x speed). The API has two events, one
// which advances to the next event (HC_SKIP), and another that requests the
// event (HC_GETNEXT). The same event will be requested multiple times.
// Each time the event is requested, we must calculate the new delay.
// To do this, we track the start time of the playback, and constantly
// re-compute the delay. I mention this only because I saw two examples
// of how to use this code on the net, and both were broken :-)
playback_start_time_ = timeGetTime();
playback_first_msg_time_ = playback_msg_.time;
// Set the hook. JOURNALPLAYBACK can only be used as a global hook.
journal_hook_ = ::SetWindowsHookEx(WH_JOURNALPLAYBACK, StaticPlaybackWndProc,
GetModuleHandle(NULL), 0);
if (!journal_hook_) {
DLOG(ERROR) << "EventRecorder Playback Hook failed";
return false;
}
is_playing_ = true;
return true;
}
void EventRecorder::StopPlayback() {
if (is_playing_) {
DCHECK(journal_hook_ != NULL);
if (!::UnhookWindowsHookEx(journal_hook_)) {
DLOG(ERROR) << "EventRecorder Unhook failed";
// Nothing else we can really do here.
}
DCHECK(file_ != NULL);
CloseFile(file_);
file_ = NULL;
::timeEndPeriod(1);
journal_hook_ = NULL;
is_playing_ = false;
}
}
// Windows callback hook for the recorder.
LRESULT EventRecorder::RecordWndProc(int nCode, WPARAM wParam, LPARAM lParam) {
static bool recording_enabled = true;
EVENTMSG* msg_ptr = NULL;
// The API says we have to do this.
// See http://msdn2.microsoft.com/en-us/library/ms644983(VS.85).aspx
if (nCode < 0)
return ::CallNextHookEx(journal_hook_, nCode, wParam, lParam);
// Check for the break key being pressed and stop recording.
if (::GetKeyState(VK_CANCEL) & 0x8000) {
StopRecording();
return ::CallNextHookEx(journal_hook_, nCode, wParam, lParam);
}
// The Journal Recorder must stop recording events when system modal
// dialogs are present. (see msdn link above)
switch (nCode) {
case HC_SYSMODALON:
recording_enabled = false;
break;
case HC_SYSMODALOFF:
recording_enabled = true;
break;
}
if (nCode == HC_ACTION && recording_enabled) {
// Aha - we have an event to record.
msg_ptr = reinterpret_cast<EVENTMSG*>(lParam);
msg_ptr->time = timeGetTime();
fwrite(msg_ptr, sizeof(EVENTMSG), 1, file_);
fflush(file_);
}
return CallNextHookEx(journal_hook_, nCode, wParam, lParam);
}
// Windows callback for the playback mode.
LRESULT EventRecorder::PlaybackWndProc(int nCode, WPARAM wParam,
LPARAM lParam) {
static bool playback_enabled = true;
int delay = 0;
switch (nCode) {
// A system modal dialog box is being displayed. Stop playing back
// messages.
case HC_SYSMODALON:
playback_enabled = false;
break;
// A system modal dialog box is destroyed. We can start playing back
// messages again.
case HC_SYSMODALOFF:
playback_enabled = true;
break;
// Prepare to copy the next mouse or keyboard event to playback.
case HC_SKIP:
if (!playback_enabled)
break;
// Read the next event from the record.
if (fread(&playback_msg_, sizeof(EVENTMSG), 1, file_) != 1)
this->StopPlayback();
break;
// Copy the mouse or keyboard event to the EVENTMSG structure in lParam.
case HC_GETNEXT:
if (!playback_enabled)
break;
memcpy(reinterpret_cast<void*>(lParam), &playback_msg_,
sizeof(playback_msg_));
// The return value is the amount of time (in milliseconds) to wait
// before playing back the next message in the playback queue. Each
// time this is called, we recalculate the delay relative to our current
// wall clock.
delay = (playback_msg_.time - playback_first_msg_time_) -
(timeGetTime() - playback_start_time_);
if (delay < 0)
delay = 0;
return delay;
// An application has called PeekMessage with wRemoveMsg set to PM_NOREMOVE
// indicating that the message is not removed from the message queue after
// PeekMessage processing.
case HC_NOREMOVE:
break;
}
return CallNextHookEx(journal_hook_, nCode, wParam, lParam);
}
} // namespace base

@ -19,8 +19,6 @@ class FileUtilProxyTest : public testing::Test {
FileUtilProxyTest()
: file_thread_("FileUtilProxyTestFileThread"),
error_(File::FILE_OK),
created_(false),
bytes_written_(-1),
weak_factory_(this) {}
void SetUp() override {
@ -52,11 +50,9 @@ class FileUtilProxyTest : public testing::Test {
ScopedTempDir dir_;
File::Error error_;
bool created_;
FilePath path_;
File::Info file_info_;
std::vector<char> buffer_;
int bytes_written_;
WeakPtrFactory<FileUtilProxyTest> weak_factory_;
};

@ -8,8 +8,6 @@ namespace base {
const char kCodepageLatin1[] = "ISO-8859-1";
const char kCodepageUTF8[] = "UTF-8";
const char kCodepageUTF16BE[] = "UTF-16BE";
const char kCodepageUTF16LE[] = "UTF-16LE";
} // namespace base

@ -12,8 +12,9 @@ namespace base {
// Names of codepages (charsets) understood by icu.
BASE_I18N_EXPORT extern const char kCodepageLatin1[]; // a.k.a. ISO 8859-1
BASE_I18N_EXPORT extern const char kCodepageUTF8[];
BASE_I18N_EXPORT extern const char kCodepageUTF16BE[];
BASE_I18N_EXPORT extern const char kCodepageUTF16LE[];
// The other possible options are UTF-16BE and UTF-16LE, but they are unused in
// Chromium as of this writing.
} // namespace base

@ -117,8 +117,10 @@ MessageLoop::DestructionObserver::~DestructionObserver() {
MessageLoop::MessageLoop(Type type)
: type_(type),
#if defined(OS_WIN)
pending_high_res_tasks_(0),
in_high_res_mode_(false),
#endif
nestable_tasks_allowed_(true),
#if defined(OS_WIN)
os_modal_loop_(false),
@ -133,8 +135,10 @@ MessageLoop::MessageLoop(Type type)
MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump)
: pump_(pump.Pass()),
type_(TYPE_CUSTOM),
#if defined(OS_WIN)
pending_high_res_tasks_(0),
in_high_res_mode_(false),
#endif
nestable_tasks_allowed_(true),
#if defined(OS_WIN)
os_modal_loop_(false),
@ -422,10 +426,13 @@ bool MessageLoop::ProcessNextDelayedNonNestableTask() {
void MessageLoop::RunTask(const PendingTask& pending_task) {
DCHECK(nestable_tasks_allowed_);
#if defined(OS_WIN)
if (pending_task.is_high_res) {
pending_high_res_tasks_--;
CHECK(pending_high_res_tasks_ >= 0);
CHECK_GE(pending_high_res_tasks_, 0);
}
#endif
// Execute the task and assume the worst: It is probably not reentrant.
nestable_tasks_allowed_ = false;
@ -495,8 +502,12 @@ void MessageLoop::ReloadWorkQueue() {
// load. That reduces the number of locks-per-task significantly when our
// queues get large.
if (work_queue_.empty()) {
#if defined(OS_WIN)
pending_high_res_tasks_ +=
incoming_task_queue_->ReloadWorkQueue(&work_queue_);
#else
incoming_task_queue_->ReloadWorkQueue(&work_queue_);
#endif
}
}
@ -692,8 +703,8 @@ bool MessageLoopForIO::WaitForIOCompletion(DWORD timeout, IOHandler* filter) {
bool MessageLoopForIO::WatchFileDescriptor(int fd,
bool persistent,
Mode mode,
FileDescriptorWatcher *controller,
Watcher *delegate) {
FileDescriptorWatcher* controller,
Watcher* delegate) {
return ToPumpIO(pump_.get())->WatchFileDescriptor(
fd,
persistent,

@ -106,7 +106,7 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
TYPE_IO,
#if defined(OS_ANDROID)
TYPE_JAVA,
#endif // defined(OS_ANDROID)
#endif // defined(OS_ANDROID)
};
// Normally, it is not necessary to instantiate a MessageLoop. Instead, it
@ -452,6 +452,7 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
// this queue is only accessed (push/pop) by our current thread.
TaskQueue work_queue_;
#if defined(OS_WIN)
// How many high resolution tasks are in the pending task queue. This value
// increases by N every time we call ReloadWorkQueue() and decreases by 1
// every time we call RunTask() if the task needs a high resolution timer.
@ -459,6 +460,7 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
// Tracks if we have requested high resolution timers. Its only use is to
// turn off the high resolution timer upon loop destruction.
bool in_high_res_mode_;
#endif
// Contains delayed tasks, sorted by their 'delayed_run_time' property.
DelayedTaskQueue delayed_work_queue_;
@ -639,8 +641,8 @@ class BASE_EXPORT MessageLoopForIO : public MessageLoop {
bool WatchFileDescriptor(int fd,
bool persistent,
Mode mode,
FileDescriptorWatcher *controller,
Watcher *delegate);
FileDescriptorWatcher* controller,
Watcher* delegate);
#endif // defined(OS_IOS) || defined(OS_POSIX)
#endif // !defined(OS_NACL_SFI)
};

@ -85,17 +85,6 @@ struct CommittedKBytes {
size_t image;
};
// Free memory (Megabytes marked as free) in the 2G process address space.
// total : total amount in megabytes marked as free. Maximum value is 2048.
// largest : size of the largest contiguous amount of memory found. It is
// always smaller or equal to FreeMBytes::total.
// largest_ptr: starting address of the largest memory block.
struct FreeMBytes {
size_t total;
size_t largest;
void* largest_ptr;
};
// Convert a POSIX timeval to microseconds.
BASE_EXPORT int64 TimeValToMicroseconds(const struct timeval& tv);