diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-23 08:00:57 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-23 08:00:57 +0000 |
commit | 9e94ab77b2693454541a631a212b940378d824a7 (patch) | |
tree | cf0abc57748a31cecf5519057c129fd5100b3f26 /base | |
parent | bb8582c001573d8fa9451b882cc1a182d8ca0785 (diff) | |
download | chromium_src-9e94ab77b2693454541a631a212b940378d824a7.zip chromium_src-9e94ab77b2693454541a631a212b940378d824a7.tar.gz chromium_src-9e94ab77b2693454541a631a212b940378d824a7.tar.bz2 |
Revert 213003 "Move UploadList class to base/"
> Move UploadList class to base/
>
> I want to move CrashUploadList to components/breakpad. However, since
> other classes in chrome/ also inherit from UploadList, I need to move it
> to a "neutral" location.
>
> BUG=247431
> R=mark@chromium.org
>
> Review URL: https://chromiumcodereview.appspot.com/19955002
TBR=jochen@chromium.org
Review URL: https://codereview.chromium.org/20030002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213058 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gyp | 1 | ||||
-rw-r--r-- | base/base.gypi | 2 | ||||
-rw-r--r-- | base/upload_list.cc | 98 | ||||
-rw-r--r-- | base/upload_list.h | 99 | ||||
-rw-r--r-- | base/upload_list_unittest.cc | 49 |
5 files changed, 0 insertions, 249 deletions
diff --git a/base/base.gyp b/base/base.gyp index 58543eb..56a036a 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -619,7 +619,6 @@ 'tools_sanity_unittest.cc', 'tracked_objects_unittest.cc', 'tuple_unittest.cc', - 'upload_list_unittest.cc', 'values_unittest.cc', 'version_unittest.cc', 'vlog_unittest.cc', diff --git a/base/base.gypi b/base/base.gypi index 7381bea..02abd4b 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -586,8 +586,6 @@ 'tracking_info.cc', 'tracking_info.h', 'tuple.h', - 'upload_list.cc', - 'upload_list.h', 'values.cc', 'values.h', 'value_conversions.cc', diff --git a/base/upload_list.cc b/base/upload_list.cc deleted file mode 100644 index 50aa817..0000000 --- a/base/upload_list.cc +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2013 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/upload_list.h" - -#include <algorithm> -#include <iterator> - -#include "base/bind.h" -#include "base/file_util.h" -#include "base/location.h" -#include "base/single_thread_task_runner.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/string_split.h" -#include "base/threading/sequenced_worker_pool.h" - -namespace base { - -UploadList::UploadInfo::UploadInfo(const std::string& c, const Time& t) - : id(c), time(t) {} - -UploadList::UploadInfo::~UploadInfo() {} - -UploadList::UploadList(Delegate* delegate, - const FilePath& upload_log_path, - SingleThreadTaskRunner* task_runner) - : delegate_(delegate), - upload_log_path_(upload_log_path), - task_runner_(task_runner) {} - -UploadList::~UploadList() {} - -void UploadList::LoadUploadListAsynchronously( - base::SequencedWorkerPool* worker_pool) { - DCHECK(task_runner_->BelongsToCurrentThread()); - worker_pool->PostWorkerTask( - FROM_HERE, - Bind(&UploadList::LoadUploadListAndInformDelegateOfCompletion, this)); -} - -void UploadList::ClearDelegate() { - DCHECK(task_runner_->BelongsToCurrentThread()); - delegate_ = NULL; -} - -void UploadList::LoadUploadListAndInformDelegateOfCompletion() { - LoadUploadList(); - task_runner_->PostTask( - FROM_HERE, Bind(&UploadList::InformDelegateOfCompletion, this)); -} - -void UploadList::LoadUploadList() { - if (PathExists(upload_log_path_)) { - std::string contents; - file_util::ReadFileToString(upload_log_path_, &contents); - std::vector<std::string> log_entries; - SplitStringAlongWhitespace(contents, &log_entries); - ParseLogEntries(log_entries); - } -} - -void UploadList::AppendUploadInfo(const UploadInfo& info) { - uploads_.push_back(info); -} - -void UploadList::ParseLogEntries( - const std::vector<std::string>& log_entries) { - std::vector<std::string>::const_reverse_iterator i; - for (i = log_entries.rbegin(); i != log_entries.rend(); ++i) { - std::vector<std::string> components; - SplitString(*i, ',', &components); - // Skip any blank (or corrupted) lines. - if (components.size() != 2) - continue; - double seconds_since_epoch; - if (!StringToDouble(components[0], &seconds_since_epoch)) - continue; - UploadInfo info(components[1], Time::FromDoubleT(seconds_since_epoch)); - uploads_.push_back(info); - } -} - -void UploadList::InformDelegateOfCompletion() { - DCHECK(task_runner_->BelongsToCurrentThread()); - if (delegate_) - delegate_->OnUploadListAvailable(); -} - -void UploadList::GetUploads(unsigned int max_count, - std::vector<UploadInfo>* uploads) { - DCHECK(task_runner_->BelongsToCurrentThread()); - std::copy(uploads_.begin(), - uploads_.begin() + std::min<size_t>(uploads_.size(), max_count), - std::back_inserter(*uploads)); -} - -} // namespace base diff --git a/base/upload_list.h b/base/upload_list.h deleted file mode 100644 index dd136f0..0000000 --- a/base/upload_list.h +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2013 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_UPLOAD_LIST_H_ -#define BASE_UPLOAD_LIST_H_ - -#include <string> -#include <vector> - -#include "base/base_export.h" -#include "base/files/file_path.h" -#include "base/gtest_prod_util.h" -#include "base/memory/ref_counted.h" -#include "base/time/time.h" - -namespace base { - -class SingleThreadTaskRunner; -class SequencedWorkerPool; - -// Loads and parses an upload list text file of the format -// time,id -// time,id -// etc. -// where each line represents an upload and "time" is Unix time. Must be used -// from the UI thread. The loading and parsing is done on a blocking pool task -// runner. -class BASE_EXPORT UploadList : public RefCountedThreadSafe<UploadList> { - public: - struct BASE_EXPORT UploadInfo { - UploadInfo(const std::string& c, const Time& t); - ~UploadInfo(); - - std::string id; - Time time; - }; - - class Delegate { - public: - // Invoked when the upload list has been loaded. Will be called on the - // UI thread. - virtual void OnUploadListAvailable() = 0; - - protected: - virtual ~Delegate() {} - }; - - // Creates a new upload list with the given callback delegate. - UploadList(Delegate* delegate, - const FilePath& upload_log_path, - SingleThreadTaskRunner* task_runner); - - // Starts loading the upload list. OnUploadListAvailable will be called when - // loading is complete. - void LoadUploadListAsynchronously(SequencedWorkerPool* worker_pool); - - // Clears the delegate, so that any outstanding asynchronous load will not - // call the delegate on completion. - void ClearDelegate(); - - // Populates |uploads| with the |max_count| most recent uploads, - // in reverse chronological order. - // Must be called only after OnUploadListAvailable has been called. - void GetUploads(unsigned int max_count, std::vector<UploadInfo>* uploads); - - protected: - virtual ~UploadList(); - - // Reads the upload log and stores the entries in |uploads_|. - virtual void LoadUploadList(); - - // Adds |info| to |uploads_|. - void AppendUploadInfo(const UploadInfo& info); - - private: - friend class RefCountedThreadSafe<UploadList>; - FRIEND_TEST_ALL_PREFIXES(UploadListTest, ParseLogEntries); - - // Manages the background thread work for LoadUploadListAsynchronously(). - void LoadUploadListAndInformDelegateOfCompletion(); - - // Calls the delegate's callback method, if there is a delegate. - void InformDelegateOfCompletion(); - - // Parses upload log lines, converting them to UploadInfo entries. - void ParseLogEntries(const std::vector<std::string>& log_entries); - - std::vector<UploadInfo> uploads_; - Delegate* delegate_; - const FilePath upload_log_path_; - SingleThreadTaskRunner* task_runner_; - - DISALLOW_COPY_AND_ASSIGN(UploadList); -}; - -} // namespace base - -#endif // BASE_UPLOAD_LIST_H_ diff --git a/base/upload_list_unittest.cc b/base/upload_list_unittest.cc deleted file mode 100644 index 41e1782..0000000 --- a/base/upload_list_unittest.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2013 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 <string> - -#include "base/files/file_path.h" -#include "base/memory/ref_counted.h" -#include "base/message_loop/message_loop_proxy.h" -#include "base/strings/string_number_conversions.h" -#include "base/time/time.h" -#include "base/upload_list.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace base { - -// Test that UploadList can parse a vector of log entry strings to a vector of -// UploadInfo objects. See the UploadList declaration for a description of the -// log entry string format. -TEST(UploadListTest, ParseLogEntries) { - const char kTestTime[] = "1234567890"; - const char kTestID[] = "0123456789abcdef"; - std::string test_entry = kTestTime; - test_entry += ","; - test_entry.append(kTestID, sizeof(kTestID)); - - scoped_refptr<UploadList> upload_list = - new UploadList(NULL, base::FilePath(), MessageLoopProxy::current()); - - // 1 entry. - std::vector<std::string> log_entries; - log_entries.push_back(test_entry); - upload_list->ParseLogEntries(log_entries); - EXPECT_EQ(1u, upload_list->uploads_.size()); - double time_double = upload_list->uploads_[0].time.ToDoubleT(); - EXPECT_STREQ(kTestTime, base::DoubleToString(time_double).c_str()); - EXPECT_STREQ(kTestID, upload_list->uploads_[0].id.c_str()); - - // Add 3 more entries. - log_entries.push_back(test_entry); - log_entries.push_back(test_entry); - upload_list->ParseLogEntries(log_entries); - EXPECT_EQ(4u, upload_list->uploads_.size()); - time_double = upload_list->uploads_[3].time.ToDoubleT(); - EXPECT_STREQ(kTestTime, base::DoubleToString(time_double).c_str()); - EXPECT_STREQ(kTestID, upload_list->uploads_[3].id.c_str()); -} - -} // namespace base |