summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/file_path.cc194
-rw-r--r--base/message_loop.cc334
-rw-r--r--base/message_loop.h18
-rw-r--r--base/pickle.cc102
-rw-r--r--base/ref_counted_memory.cc16
-rw-r--r--base/task_queue.cc32
-rw-r--r--base/values.cc103
-rw-r--r--base/version.cc8
8 files changed, 395 insertions, 412 deletions
diff --git a/base/file_path.cc b/base/file_path.cc
index eba9afe..cddb17e 100644
--- a/base/file_path.cc
+++ b/base/file_path.cc
@@ -174,6 +174,23 @@ FilePath& FilePath::operator=(const FilePath& that) {
return *this;
}
+bool FilePath::operator==(const FilePath& that) const {
+#if defined(FILE_PATH_USES_DRIVE_LETTERS)
+ return EqualDriveLetterCaseInsensitive(this->path_, that.path_);
+#else // defined(FILE_PATH_USES_DRIVE_LETTERS)
+ return path_ == that.path_;
+#endif // defined(FILE_PATH_USES_DRIVE_LETTERS)
+}
+
+bool FilePath::operator!=(const FilePath& that) const {
+#if defined(FILE_PATH_USES_DRIVE_LETTERS)
+ return !EqualDriveLetterCaseInsensitive(this->path_, that.path_);
+#else // defined(FILE_PATH_USES_DRIVE_LETTERS)
+ return path_ != that.path_;
+#endif // defined(FILE_PATH_USES_DRIVE_LETTERS)
+}
+
+// static
bool FilePath::IsSeparator(CharType character) {
for (size_t i = 0; i < arraysize(kSeparators) - 1; ++i) {
if (character == kSeparators[i]) {
@@ -219,22 +236,6 @@ void FilePath::GetComponents(std::vector<StringType>* components) const {
*components = std::vector<StringType>(ret_val.rbegin(), ret_val.rend());
}
-bool FilePath::operator==(const FilePath& that) const {
-#if defined(FILE_PATH_USES_DRIVE_LETTERS)
- return EqualDriveLetterCaseInsensitive(this->path_, that.path_);
-#else // defined(FILE_PATH_USES_DRIVE_LETTERS)
- return path_ == that.path_;
-#endif // defined(FILE_PATH_USES_DRIVE_LETTERS)
-}
-
-bool FilePath::operator!=(const FilePath& that) const {
-#if defined(FILE_PATH_USES_DRIVE_LETTERS)
- return !EqualDriveLetterCaseInsensitive(this->path_, that.path_);
-#else // defined(FILE_PATH_USES_DRIVE_LETTERS)
- return path_ != that.path_;
-#endif // defined(FILE_PATH_USES_DRIVE_LETTERS)
-}
-
bool FilePath::IsParent(const FilePath& child) const {
return AppendRelativePath(child, NULL);
}
@@ -489,6 +490,87 @@ bool FilePath::IsAbsolute() const {
return IsPathAbsolute(path_);
}
+FilePath FilePath::StripTrailingSeparators() const {
+ FilePath new_path(path_);
+ new_path.StripTrailingSeparatorsInternal();
+
+ return new_path;
+}
+
+bool FilePath::ReferencesParent() const {
+ std::vector<StringType> components;
+ GetComponents(&components);
+
+ std::vector<StringType>::const_iterator it = components.begin();
+ for (; it != components.end(); ++it) {
+ const StringType& component = *it;
+ if (component == kParentDirectory)
+ return true;
+ }
+ return false;
+}
+
+#if defined(OS_POSIX)
+
+// See file_path.h for a discussion of the encoding of paths on POSIX
+// platforms. These *Hack() functions are not quite correct, but they're
+// only temporary while we fix the remainder of the code.
+// Remember to remove the #includes at the top when you remove these.
+
+// static
+FilePath FilePath::FromWStringHack(const std::wstring& wstring) {
+ return FilePath(base::SysWideToNativeMB(wstring));
+}
+std::wstring FilePath::ToWStringHack() const {
+ return base::SysNativeMBToWide(path_);
+}
+#elif defined(OS_WIN)
+// static
+FilePath FilePath::FromWStringHack(const std::wstring& wstring) {
+ return FilePath(wstring);
+}
+std::wstring FilePath::ToWStringHack() const {
+ return path_;
+}
+#endif
+
+// static.
+void FilePath::WriteStringTypeToPickle(Pickle* pickle,
+ const StringType& path) {
+#if defined(WCHAR_T_IS_UTF16)
+ pickle->WriteWString(path);
+#elif defined(WCHAR_T_IS_UTF32)
+ pickle->WriteString(path);
+#else
+ NOTIMPLEMENTED() << "Impossible encoding situation!";
+#endif
+}
+
+// static.
+bool FilePath::ReadStringTypeFromPickle(Pickle* pickle, void** iter,
+ StringType* path) {
+#if defined(WCHAR_T_IS_UTF16)
+ if (!pickle->ReadWString(iter, path))
+ return false;
+#elif defined(WCHAR_T_IS_UTF32)
+ if (!pickle->ReadString(iter, path))
+ return false;
+#else
+ NOTIMPLEMENTED() << "Impossible encoding situation!";
+ return false;
+#endif
+
+ return true;
+}
+
+void FilePath::WriteToPickle(Pickle* pickle) {
+ WriteStringTypeToPickle(pickle, value());
+}
+
+bool FilePath::ReadFromPickle(Pickle* pickle, void** iter) {
+ return ReadStringTypeFromPickle(pickle, iter, &path_);
+}
+
#if defined(OS_WIN)
// Windows specific implementation of file string comparisons
@@ -1078,73 +1160,6 @@ int FilePath::CompareIgnoreCase(const StringType& string1,
#endif // OS versions of CompareIgnoreCase()
-#if defined(OS_POSIX)
-
-// See file_path.h for a discussion of the encoding of paths on POSIX
-// platforms. These *Hack() functions are not quite correct, but they're
-// only temporary while we fix the remainder of the code.
-// Remember to remove the #includes at the top when you remove these.
-
-// static
-FilePath FilePath::FromWStringHack(const std::wstring& wstring) {
- return FilePath(base::SysWideToNativeMB(wstring));
-}
-std::wstring FilePath::ToWStringHack() const {
- return base::SysNativeMBToWide(path_);
-}
-#elif defined(OS_WIN)
-// static
-FilePath FilePath::FromWStringHack(const std::wstring& wstring) {
- return FilePath(wstring);
-}
-std::wstring FilePath::ToWStringHack() const {
- return path_;
-}
-#endif
-
-FilePath FilePath::StripTrailingSeparators() const {
- FilePath new_path(path_);
- new_path.StripTrailingSeparatorsInternal();
-
- return new_path;
-}
-
-// static.
-void FilePath::WriteStringTypeToPickle(Pickle* pickle,
- const StringType& path) {
-#if defined(WCHAR_T_IS_UTF16)
- pickle->WriteWString(path);
-#elif defined(WCHAR_T_IS_UTF32)
- pickle->WriteString(path);
-#else
- NOTIMPLEMENTED() << "Impossible encoding situation!";
-#endif
-}
-
-// static.
-bool FilePath::ReadStringTypeFromPickle(Pickle* pickle, void** iter,
- StringType* path) {
-#if defined(WCHAR_T_IS_UTF16)
- if (!pickle->ReadWString(iter, path))
- return false;
-#elif defined(WCHAR_T_IS_UTF32)
- if (!pickle->ReadString(iter, path))
- return false;
-#else
- NOTIMPLEMENTED() << "Impossible encoding situation!";
- return false;
-#endif
-
- return true;
-}
-
-void FilePath::WriteToPickle(Pickle* pickle) {
- WriteStringTypeToPickle(pickle, value());
-}
-
-bool FilePath::ReadFromPickle(Pickle* pickle, void** iter) {
- return ReadStringTypeFromPickle(pickle, iter, &path_);
-}
void FilePath::StripTrailingSeparatorsInternal() {
// If there is no drive letter, start will be 1, which will prevent stripping
@@ -1168,19 +1183,6 @@ void FilePath::StripTrailingSeparatorsInternal() {
}
}
-bool FilePath::ReferencesParent() const {
- std::vector<StringType> components;
- GetComponents(&components);
-
- std::vector<StringType>::const_iterator it = components.begin();
- for (; it != components.end(); ++it) {
- const StringType& component = *it;
- if (component == kParentDirectory)
- return true;
- }
- return false;
-}
-
#if defined(FILE_PATH_USES_WIN_SEPARATORS)
FilePath FilePath::NormalizeWindowsPathSeparators() const {
StringType copy = path_;
diff --git a/base/message_loop.cc b/base/message_loop.cc
index eec8a24..e74331a 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -113,14 +113,6 @@ MessageLoop::DestructionObserver::~DestructionObserver() {
//------------------------------------------------------------------------------
-// static
-MessageLoop* MessageLoop::current() {
- // TODO(darin): sadly, we cannot enable this yet since people call us even
- // when they have no intention of using us.
- // DCHECK(loop) << "Ouch, did you forget to initialize me?";
- return lazy_tls_ptr.Pointer()->Get();
-}
-
MessageLoop::MessageLoop(Type type)
: type_(type),
nestable_tasks_allowed_(true),
@@ -192,6 +184,19 @@ MessageLoop::~MessageLoop() {
lazy_tls_ptr.Pointer()->Set(NULL);
}
+// static
+MessageLoop* MessageLoop::current() {
+ // TODO(darin): sadly, we cannot enable this yet since people call us even
+ // when they have no intention of using us.
+ // DCHECK(loop) << "Ouch, did you forget to initialize me?";
+ return lazy_tls_ptr.Pointer()->Get();
+}
+
+// static
+void MessageLoop::EnableHistogrammer(bool enable) {
+ enable_histogrammer_ = enable;
+}
+
void MessageLoop::AddDestructionObserver(
DestructionObserver* destruction_observer) {
DCHECK_EQ(this, current());
@@ -204,14 +209,24 @@ void MessageLoop::RemoveDestructionObserver(
destruction_observers_.RemoveObserver(destruction_observer);
}
-void MessageLoop::AddTaskObserver(TaskObserver* task_observer) {
- DCHECK_EQ(this, current());
- task_observers_.AddObserver(task_observer);
+void MessageLoop::PostTask(
+ const tracked_objects::Location& from_here, Task* task) {
+ PostTask_Helper(from_here, task, 0, true);
}
-void MessageLoop::RemoveTaskObserver(TaskObserver* task_observer) {
- DCHECK_EQ(this, current());
- task_observers_.RemoveObserver(task_observer);
+void MessageLoop::PostDelayedTask(
+ const tracked_objects::Location& from_here, Task* task, int64 delay_ms) {
+ PostTask_Helper(from_here, task, delay_ms, true);
+}
+
+void MessageLoop::PostNonNestableTask(
+ const tracked_objects::Location& from_here, Task* task) {
+ PostTask_Helper(from_here, task, 0, false);
+}
+
+void MessageLoop::PostNonNestableDelayedTask(
+ const tracked_objects::Location& from_here, Task* task, int64 delay_ms) {
+ PostTask_Helper(from_here, task, delay_ms, false);
}
void MessageLoop::Run() {
@@ -225,6 +240,54 @@ void MessageLoop::RunAllPending() {
RunHandler();
}
+void MessageLoop::Quit() {
+ DCHECK_EQ(this, current());
+ if (state_) {
+ state_->quit_received = true;
+ } else {
+ NOTREACHED() << "Must be inside Run to call Quit";
+ }
+}
+
+void MessageLoop::QuitNow() {
+ DCHECK_EQ(this, current());
+ if (state_) {
+ pump_->Quit();
+ } else {
+ NOTREACHED() << "Must be inside Run to call Quit";
+ }
+}
+
+void MessageLoop::SetNestableTasksAllowed(bool allowed) {
+ if (nestable_tasks_allowed_ != allowed) {
+ nestable_tasks_allowed_ = allowed;
+ if (!nestable_tasks_allowed_)
+ return;
+ // Start the native pump if we are not already pumping.
+ pump_->ScheduleWork();
+ }
+}
+
+bool MessageLoop::NestableTasksAllowed() const {
+ return nestable_tasks_allowed_;
+}
+
+bool MessageLoop::IsNested() {
+ return state_->run_depth > 1;
+}
+
+void MessageLoop::AddTaskObserver(TaskObserver* task_observer) {
+ DCHECK_EQ(this, current());
+ task_observers_.AddObserver(task_observer);
+}
+
+void MessageLoop::RemoveTaskObserver(TaskObserver* task_observer) {
+ DCHECK_EQ(this, current());
+ task_observers_.RemoveObserver(task_observer);
+}
+
+//------------------------------------------------------------------------------
+
// Runs the loop in two different SEH modes:
// enable_SEH_restoration_ = false : any unhandled exception goes to the last
// one that calls SetUnhandledExceptionFilter().
@@ -240,7 +303,7 @@ void MessageLoop::RunHandler() {
RunInternal();
}
-//------------------------------------------------------------------------------
+
#if defined(OS_WIN)
__declspec(noinline) void MessageLoop::RunInternalInSEHFrame() {
LPTOP_LEVEL_EXCEPTION_FILTER current_filter = GetTopSEHFilter();
@@ -251,7 +314,6 @@ __declspec(noinline) void MessageLoop::RunInternalInSEHFrame() {
return;
}
#endif
-//------------------------------------------------------------------------------
void MessageLoop::RunInternal() {
DCHECK_EQ(this, current());
@@ -269,9 +331,6 @@ void MessageLoop::RunInternal() {
pump_->Run(this);
}
-//------------------------------------------------------------------------------
-// Wrapper functions for use in above message loop framework.
-
bool MessageLoop::ProcessNextDelayedNonNestableTask() {
if (state_->run_depth != 1)
return false;
@@ -286,130 +345,6 @@ bool MessageLoop::ProcessNextDelayedNonNestableTask() {
return true;
}
-//------------------------------------------------------------------------------
-
-void MessageLoop::Quit() {
- DCHECK_EQ(this, current());
- if (state_) {
- state_->quit_received = true;
- } else {
- NOTREACHED() << "Must be inside Run to call Quit";
- }
-}
-
-void MessageLoop::QuitNow() {
- DCHECK_EQ(this, current());
- if (state_) {
- pump_->Quit();
- } else {
- NOTREACHED() << "Must be inside Run to call Quit";
- }
-}
-
-void MessageLoop::PostTask(
- const tracked_objects::Location& from_here, Task* task) {
- PostTask_Helper(from_here, task, 0, true);
-}
-
-void MessageLoop::PostDelayedTask(
- const tracked_objects::Location& from_here, Task* task, int64 delay_ms) {
- PostTask_Helper(from_here, task, delay_ms, true);
-}
-
-void MessageLoop::PostNonNestableTask(
- const tracked_objects::Location& from_here, Task* task) {
- PostTask_Helper(from_here, task, 0, false);
-}
-
-void MessageLoop::PostNonNestableDelayedTask(
- const tracked_objects::Location& from_here, Task* task, int64 delay_ms) {
- PostTask_Helper(from_here, task, delay_ms, false);
-}
-
-// Possibly called on a background thread!
-void MessageLoop::PostTask_Helper(
- const tracked_objects::Location& from_here, Task* task, int64 delay_ms,
- bool nestable) {
- task->SetBirthPlace(from_here);
-
- PendingTask pending_task(task, nestable);
-
- if (delay_ms > 0) {
- pending_task.delayed_run_time =
- TimeTicks::Now() + TimeDelta::FromMilliseconds(delay_ms);
-
-#if defined(OS_WIN)
- if (high_resolution_timer_expiration_.is_null()) {
- // Windows timers are granular to 15.6ms. If we only set high-res
- // timers for those under 15.6ms, then a 18ms timer ticks at ~32ms,
- // which as a percentage is pretty inaccurate. So enable high
- // res timers for any timer which is within 2x of the granularity.
- // This is a tradeoff between accuracy and power management.
- bool needs_high_res_timers =
- delay_ms < (2 * base::Time::kMinLowResolutionThresholdMs);
- if (needs_high_res_timers) {
- base::Time::ActivateHighResolutionTimer(true);
- high_resolution_timer_expiration_ = TimeTicks::Now() +
- TimeDelta::FromMilliseconds(kHighResolutionTimerModeLeaseTimeMs);
- }
- }
-#endif
- } else {
- DCHECK_EQ(delay_ms, 0) << "delay should not be negative";
- }
-
-#if defined(OS_WIN)
- if (!high_resolution_timer_expiration_.is_null()) {
- if (TimeTicks::Now() > high_resolution_timer_expiration_) {
- base::Time::ActivateHighResolutionTimer(false);
- high_resolution_timer_expiration_ = TimeTicks();
- }
- }
-#endif
-
- // Warning: Don't try to short-circuit, and handle this thread's tasks more
- // directly, as it could starve handling of foreign threads. Put every task
- // into this queue.
-
- scoped_refptr<base::MessagePump> pump;
- {
- AutoLock locked(incoming_queue_lock_);
-
- bool was_empty = incoming_queue_.empty();
- incoming_queue_.push(pending_task);
- if (!was_empty)
- return; // Someone else should have started the sub-pump.
-
- pump = pump_;
- }
- // Since the incoming_queue_ may contain a task that destroys this message
- // loop, we cannot exit incoming_queue_lock_ until we are done with |this|.
- // We use a stack-based reference to the message pump so that we can call
- // ScheduleWork outside of incoming_queue_lock_.
-
- pump->ScheduleWork();
-}
-
-void MessageLoop::SetNestableTasksAllowed(bool allowed) {
- if (nestable_tasks_allowed_ != allowed) {
- nestable_tasks_allowed_ = allowed;
- if (!nestable_tasks_allowed_)
- return;
- // Start the native pump if we are not already pumping.
- pump_->ScheduleWork();
- }
-}
-
-bool MessageLoop::NestableTasksAllowed() const {
- return nestable_tasks_allowed_;
-}
-
-bool MessageLoop::IsNested() {
- return state_->run_depth > 1;
-}
-
-//------------------------------------------------------------------------------
-
void MessageLoop::RunTask(Task* task) {
DCHECK(nestable_tasks_allowed_);
// Execute the task and assume the worst: It is probably not reentrant.
@@ -513,6 +448,92 @@ bool MessageLoop::DeletePendingTasks() {
return did_work;
}
+// Possibly called on a background thread!
+void MessageLoop::PostTask_Helper(
+ const tracked_objects::Location& from_here, Task* task, int64 delay_ms,
+ bool nestable) {
+ task->SetBirthPlace(from_here);
+
+ PendingTask pending_task(task, nestable);
+
+ if (delay_ms > 0) {
+ pending_task.delayed_run_time =
+ TimeTicks::Now() + TimeDelta::FromMilliseconds(delay_ms);
+
+#if defined(OS_WIN)
+ if (high_resolution_timer_expiration_.is_null()) {
+ // Windows timers are granular to 15.6ms. If we only set high-res
+ // timers for those under 15.6ms, then a 18ms timer ticks at ~32ms,
+ // which as a percentage is pretty inaccurate. So enable high
+ // res timers for any timer which is within 2x of the granularity.
+ // This is a tradeoff between accuracy and power management.
+ bool needs_high_res_timers =
+ delay_ms < (2 * base::Time::kMinLowResolutionThresholdMs);
+ if (needs_high_res_timers) {
+ base::Time::ActivateHighResolutionTimer(true);
+ high_resolution_timer_expiration_ = TimeTicks::Now() +
+ TimeDelta::FromMilliseconds(kHighResolutionTimerModeLeaseTimeMs);
+ }
+ }
+#endif
+ } else {
+ DCHECK_EQ(delay_ms, 0) << "delay should not be negative";
+ }
+
+#if defined(OS_WIN)
+ if (!high_resolution_timer_expiration_.is_null()) {
+ if (TimeTicks::Now() > high_resolution_timer_expiration_) {
+ base::Time::ActivateHighResolutionTimer(false);
+ high_resolution_timer_expiration_ = TimeTicks();
+ }
+ }
+#endif
+
+ // Warning: Don't try to short-circuit, and handle this thread's tasks more
+ // directly, as it could starve handling of foreign threads. Put every task
+ // into this queue.
+
+ scoped_refptr<base::MessagePump> pump;
+ {
+ AutoLock locked(incoming_queue_lock_);
+
+ bool was_empty = incoming_queue_.empty();
+ incoming_queue_.push(pending_task);
+ if (!was_empty)
+ return; // Someone else should have started the sub-pump.
+
+ pump = pump_;
+ }
+ // Since the incoming_queue_ may contain a task that destroys this message
+ // loop, we cannot exit incoming_queue_lock_ until we are done with |this|.
+ // We use a stack-based reference to the message pump so that we can call
+ // ScheduleWork outside of incoming_queue_lock_.
+
+ pump->ScheduleWork();
+}
+
+//------------------------------------------------------------------------------
+// Method and data for histogramming events and actions taken by each instance
+// on each thread.
+
+void MessageLoop::StartHistogrammer() {
+ if (enable_histogrammer_ && !message_histogram_.get()
+ && base::StatisticsRecorder::IsActive()) {
+ DCHECK(!thread_name_.empty());
+ message_histogram_ = base::LinearHistogram::FactoryGet(
+ "MsgLoop:" + thread_name_,
+ kLeastNonZeroMessageId, kMaxMessageId,
+ kNumberOfDistinctMessagesDisplayed,
+ message_histogram_->kHexRangePrintingFlag);
+ message_histogram_->SetRangeDescriptions(event_descriptions_);
+ }
+}
+
+void MessageLoop::HistogramEvent(int event) {
+ if (message_histogram_.get())
+ message_histogram_->Add(event);
+}
+
bool MessageLoop::DoWork() {
if (!nestable_tasks_allowed_) {
// Task can't be executed right now.
@@ -629,33 +650,6 @@ bool MessageLoop::PendingTask::operator<(const PendingTask& other) const {
}
//------------------------------------------------------------------------------
-// Method and data for histogramming events and actions taken by each instance
-// on each thread.
-
-// static
-void MessageLoop::EnableHistogrammer(bool enable) {
- enable_histogrammer_ = enable;
-}
-
-void MessageLoop::StartHistogrammer() {
- if (enable_histogrammer_ && !message_histogram_.get()
- && base::StatisticsRecorder::IsActive()) {
- DCHECK(!thread_name_.empty());
- message_histogram_ = base::LinearHistogram::FactoryGet(
- "MsgLoop:" + thread_name_,
- kLeastNonZeroMessageId, kMaxMessageId,
- kNumberOfDistinctMessagesDisplayed,
- message_histogram_->kHexRangePrintingFlag);
- message_histogram_->SetRangeDescriptions(event_descriptions_);
- }
-}
-
-void MessageLoop::HistogramEvent(int event) {
- if (message_histogram_.get())
- message_histogram_->Add(event);
-}
-
-//------------------------------------------------------------------------------
// MessageLoopForUI
#if defined(OS_WIN)
diff --git a/base/message_loop.h b/base/message_loop.h
index 8058e24..d5093a9 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -103,6 +103,9 @@ class MessageLoop : public base::MessagePump::Delegate {
explicit MessageLoop(Type type = TYPE_DEFAULT);
~MessageLoop();
+ // Returns the MessageLoop object for the current thread, or null if none.
+ static MessageLoop* current();
+
static void EnableHistogrammer(bool enable_histogrammer);
// A DestructionObserver is notified when the current MessageLoop is being
@@ -229,9 +232,6 @@ class MessageLoop : public base::MessagePump::Delegate {
}
const std::string& thread_name() const { return thread_name_; }
- // Returns the MessageLoop object for the current thread, or null if none.
- static MessageLoop* current();
-
// Enables or disables the recursive task processing. This happens in the case
// of recursive message loops. Some unwanted message loop may occurs when
// using common controls or printer functions. By default, recursive task
@@ -391,18 +391,6 @@ class MessageLoop : public base::MessagePump::Delegate {
// Called to process any delayed non-nestable tasks.
bool ProcessNextDelayedNonNestableTask();
- //----------------------------------------------------------------------------
- // Run a work_queue_ task or new_task, and delete it (if it was processed by
- // PostTask). If there are queued tasks, the oldest one is executed and
- // new_task is queued. new_task is optional and can be NULL. In this NULL
- // case, the method will run one pending task (if any exist). Returns true if
- // it executes a task. Queued tasks accumulate only when there is a
- // non-nestable task currently processing, in which case the new_task is
- // appended to the list work_queue_. Such re-entrancy generally happens when
- // an unrequested message pump (typical of a native dialog) is executing in
- // the context of a task.
- bool QueueOrRunTask(Task* new_task);
-
// Runs the specified task and deletes it.
void RunTask(Task* task);
diff --git a/base/pickle.cc b/base/pickle.cc
index 3f376e3..a05df28 100644
--- a/base/pickle.cc
+++ b/base/pickle.cc
@@ -140,12 +140,6 @@ bool Pickle::ReadLong(void** iter, long* result) const {
return true;
}
-bool Pickle::ReadLength(void** iter, int* result) const {
- if (!ReadInt(iter, result))
- return false;
- return ((*result) >= 0);
-}
-
bool Pickle::ReadSize(void** iter, size_t* result) const {
DCHECK(iter);
if (!*iter)
@@ -256,22 +250,6 @@ bool Pickle::ReadString16(void** iter, string16* result) const {
return true;
}
-bool Pickle::ReadBytes(void** iter, const char** data, int length) const {
- DCHECK(iter);
- DCHECK(data);
- *data = 0;
- if (!*iter)
- *iter = const_cast<char*>(payload());
-
- if (!IteratorHasRoomFor(*iter, length))
- return false;
-
- *data = reinterpret_cast<const char*>(*iter);
-
- UpdateIter(iter, length);
- return true;
-}
-
bool Pickle::ReadData(void** iter, const char** data, int* length) const {
DCHECK(iter);
DCHECK(data);
@@ -285,41 +263,26 @@ bool Pickle::ReadData(void** iter, const char** data, int* length) const {
return ReadBytes(iter, data, *length);
}
-char* Pickle::BeginWrite(size_t length) {
- // write at a uint32-aligned offset from the beginning of the header
- size_t offset = AlignInt(header_->payload_size, sizeof(uint32));
-
- size_t new_size = offset + length;
- size_t needed_size = header_size_ + new_size;
- if (needed_size > capacity_ && !Resize(std::max(capacity_ * 2, needed_size)))
- return NULL;
+bool Pickle::ReadBytes(void** iter, const char** data, int length) const {
+ DCHECK(iter);
+ DCHECK(data);
+ *data = 0;
+ if (!*iter)
+ *iter = const_cast<char*>(payload());
-#ifdef ARCH_CPU_64_BITS
- DCHECK_LE(length, std::numeric_limits<uint32>::max());
-#endif
+ if (!IteratorHasRoomFor(*iter, length))
+ return false;
- header_->payload_size = static_cast<uint32>(new_size);
- return payload() + offset;
-}
+ *data = reinterpret_cast<const char*>(*iter);
-void Pickle::EndWrite(char* dest, int length) {
- // Zero-pad to keep tools like purify from complaining about uninitialized
- // memory.
- if (length % sizeof(uint32))
- memset(dest + length, 0, sizeof(uint32) - (length % sizeof(uint32)));
+ UpdateIter(iter, length);
+ return true;
}
-bool Pickle::WriteBytes(const void* data, int data_len) {
- DCHECK(capacity_ != kCapacityReadOnly) << "oops: pickle is readonly";
-
- char* dest = BeginWrite(data_len);
- if (!dest)
+bool Pickle::ReadLength(void** iter, int* result) const {
+ if (!ReadInt(iter, result))
return false;
-
- memcpy(dest, data, data_len);
-
- EndWrite(dest, data_len);
- return true;
+ return ((*result) >= 0);
}
bool Pickle::WriteString(const std::string& value) {
@@ -349,6 +312,19 @@ bool Pickle::WriteData(const char* data, int length) {
return length >= 0 && WriteInt(length) && WriteBytes(data, length);
}
+bool Pickle::WriteBytes(const void* data, int data_len) {
+ DCHECK(capacity_ != kCapacityReadOnly) << "oops: pickle is readonly";
+
+ char* dest = BeginWrite(data_len);
+ if (!dest)
+ return false;
+
+ memcpy(dest, data, data_len);
+
+ EndWrite(dest, data_len);
+ return true;
+}
+
char* Pickle::BeginWriteData(int length) {
DCHECK_EQ(variable_buffer_offset_, 0U) <<
"There can only be one variable buffer in a Pickle";
@@ -386,6 +362,30 @@ void Pickle::TrimWriteData(int new_length) {
*cur_length = new_length;
}
+char* Pickle::BeginWrite(size_t length) {
+ // write at a uint32-aligned offset from the beginning of the header
+ size_t offset = AlignInt(header_->payload_size, sizeof(uint32));
+
+ size_t new_size = offset + length;
+ size_t needed_size = header_size_ + new_size;
+ if (needed_size > capacity_ && !Resize(std::max(capacity_ * 2, needed_size)))
+ return NULL;
+
+#ifdef ARCH_CPU_64_BITS
+ DCHECK_LE(length, std::numeric_limits<uint32>::max());
+#endif
+
+ header_->payload_size = static_cast<uint32>(new_size);
+ return payload() + offset;
+}
+
+void Pickle::EndWrite(char* dest, int length) {
+ // Zero-pad to keep tools like purify from complaining about uninitialized
+ // memory.
+ if (length % sizeof(uint32))
+ memset(dest + length, 0, sizeof(uint32) - (length % sizeof(uint32)));
+}
+
bool Pickle::Resize(size_t new_capacity) {
new_capacity = AlignInt(new_capacity, kPayloadUnit);
diff --git a/base/ref_counted_memory.cc b/base/ref_counted_memory.cc
index 0a4a613..dc244b9 100644
--- a/base/ref_counted_memory.cc
+++ b/base/ref_counted_memory.cc
@@ -18,13 +18,6 @@ size_t RefCountedStaticMemory::size() const {
return length_;
}
-RefCountedBytes* RefCountedBytes::TakeVector(
- std::vector<unsigned char>* to_destroy) {
- RefCountedBytes* bytes = new RefCountedBytes;
- bytes->data.swap(*to_destroy);
- return bytes;
-}
-
RefCountedBytes::RefCountedBytes() {
}
@@ -32,7 +25,11 @@ RefCountedBytes::RefCountedBytes(const std::vector<unsigned char>& initializer)
: data(initializer) {
}
-RefCountedBytes::~RefCountedBytes() {
+RefCountedBytes* RefCountedBytes::TakeVector(
+ std::vector<unsigned char>* to_destroy) {
+ RefCountedBytes* bytes = new RefCountedBytes;
+ bytes->data.swap(*to_destroy);
+ return bytes;
}
const unsigned char* RefCountedBytes::front() const {
@@ -44,3 +41,6 @@ const unsigned char* RefCountedBytes::front() const {
size_t RefCountedBytes::size() const {
return data.size();
}
+
+RefCountedBytes::~RefCountedBytes() {
+}
diff --git a/base/task_queue.cc b/base/task_queue.cc
index e3c196b..fdff8ac 100644
--- a/base/task_queue.cc
+++ b/base/task_queue.cc
@@ -15,6 +15,22 @@ TaskQueue::~TaskQueue() {
STLDeleteElements(&queue_);
}
+void TaskQueue::Push(Task* task) {
+ DCHECK(task);
+
+ // Add the task to the back of the queue.
+ queue_.push_back(task);
+}
+
+void TaskQueue::Clear() {
+ // Delete all the elements in the queue and clear the dead pointers.
+ STLDeleteElements(&queue_);
+}
+
+bool TaskQueue::IsEmpty() const {
+ return queue_.empty();
+}
+
void TaskQueue::Run() {
// Nothing to run if our queue is empty.
if (queue_.empty())
@@ -31,19 +47,3 @@ void TaskQueue::Run() {
delete (*task);
}
}
-
-void TaskQueue::Push(Task* task) {
- DCHECK(task);
-
- // Add the task to the back of the queue.
- queue_.push_back(task);
-}
-
-void TaskQueue::Clear() {
- // Delete all the elements in the queue and clear the dead pointers.
- STLDeleteElements(&queue_);
-}
-
-bool TaskQueue::IsEmpty() const {
- return queue_.empty();
-}
diff --git a/base/values.cc b/base/values.cc
index 4553e68..3522569 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -263,6 +263,12 @@ bool StringValue::Equals(const Value* other) const {
///////////////////// BinaryValue ////////////////////
+BinaryValue::~BinaryValue() {
+ DCHECK(buffer_);
+ if (buffer_)
+ delete[] buffer_;
+}
+
// static
BinaryValue* BinaryValue::Create(char* buffer, size_t size) {
if (!buffer)
@@ -282,20 +288,6 @@ BinaryValue* BinaryValue::CreateWithCopiedBuffer(const char* buffer,
return new BinaryValue(buffer_copy, size);
}
-
-BinaryValue::BinaryValue(char* buffer, size_t size)
- : Value(TYPE_BINARY),
- buffer_(buffer),
- size_(size) {
- DCHECK(buffer_);
-}
-
-BinaryValue::~BinaryValue() {
- DCHECK(buffer_);
- if (buffer_)
- delete[] buffer_;
-}
-
Value* BinaryValue::DeepCopy() const {
return CreateWithCopiedBuffer(buffer_, size_);
}
@@ -309,6 +301,13 @@ bool BinaryValue::Equals(const Value* other) const {
return !memcmp(buffer_, other_binary->buffer_, size_);
}
+BinaryValue::BinaryValue(char* buffer, size_t size)
+ : Value(TYPE_BINARY),
+ buffer_(buffer),
+ size_(size) {
+ DCHECK(buffer_);
+}
+
///////////////////// DictionaryValue ////////////////////
DictionaryValue::DictionaryValue()
@@ -319,44 +318,6 @@ DictionaryValue::~DictionaryValue() {
Clear();
}
-Value* DictionaryValue::DeepCopy() const {
- DictionaryValue* result = new DictionaryValue;
-
- for (ValueMap::const_iterator current_entry(dictionary_.begin());
- current_entry != dictionary_.end(); ++current_entry) {
- result->SetWithoutPathExpansion(current_entry->first,
- current_entry->second->DeepCopy());
- }
-
- return result;
-}
-
-bool DictionaryValue::Equals(const Value* other) const {
- if (other->GetType() != GetType())
- return false;
-
- const DictionaryValue* other_dict =
- static_cast<const DictionaryValue*>(other);
- key_iterator lhs_it(begin_keys());
- key_iterator rhs_it(other_dict->begin_keys());
- while (lhs_it != end_keys() && rhs_it != other_dict->end_keys()) {
- Value* lhs;
- Value* rhs;
- if (*lhs_it != *rhs_it ||
- !GetWithoutPathExpansion(*lhs_it, &lhs) ||
- !other_dict->GetWithoutPathExpansion(*rhs_it, &rhs) ||
- !lhs->Equals(rhs)) {
- return false;
- }
- ++lhs_it;
- ++rhs_it;
- }
- if (lhs_it != end_keys() || rhs_it != other_dict->end_keys())
- return false;
-
- return true;
-}
-
bool DictionaryValue::HasKey(const std::string& key) const {
DCHECK(IsStringUTF8(key));
ValueMap::const_iterator current_entry = dictionary_.find(key);
@@ -685,6 +646,44 @@ void DictionaryValue::MergeDictionary(const DictionaryValue* dictionary) {
}
}
+Value* DictionaryValue::DeepCopy() const {
+ DictionaryValue* result = new DictionaryValue;
+
+ for (ValueMap::const_iterator current_entry(dictionary_.begin());
+ current_entry != dictionary_.end(); ++current_entry) {
+ result->SetWithoutPathExpansion(current_entry->first,
+ current_entry->second->DeepCopy());
+ }
+
+ return result;
+}
+
+bool DictionaryValue::Equals(const Value* other) const {
+ if (other->GetType() != GetType())
+ return false;
+
+ const DictionaryValue* other_dict =
+ static_cast<const DictionaryValue*>(other);
+ key_iterator lhs_it(begin_keys());
+ key_iterator rhs_it(other_dict->begin_keys());
+ while (lhs_it != end_keys() && rhs_it != other_dict->end_keys()) {
+ Value* lhs;
+ Value* rhs;
+ if (*lhs_it != *rhs_it ||
+ !GetWithoutPathExpansion(*lhs_it, &lhs) ||
+ !other_dict->GetWithoutPathExpansion(*rhs_it, &rhs) ||
+ !lhs->Equals(rhs)) {
+ return false;
+ }
+ ++lhs_it;
+ ++rhs_it;
+ }
+ if (lhs_it != end_keys() || rhs_it != other_dict->end_keys())
+ return false;
+
+ return true;
+}
+
///////////////////// ListValue ////////////////////
ListValue::ListValue() : Value(TYPE_LIST) {
diff --git a/base/version.cc b/base/version.cc
index 384be0a..571672c 100644
--- a/base/version.cc
+++ b/base/version.cc
@@ -12,6 +12,10 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+Version::Version() : is_valid_(false) {}
+
+Version::~Version() {}
+
// static
Version* Version::GetVersionFromString(const std::string& version_str) {
Version* vers = new Version();
@@ -23,10 +27,6 @@ Version* Version::GetVersionFromString(const std::string& version_str) {
return NULL;
}
-Version::Version() : is_valid_(false) {}
-
-Version::~Version() {}
-
Version* Version::Clone() const {
DCHECK(is_valid_);
Version* copy = new Version();