Commit f2456592 authored by gab@chromium.org's avatar gab@chromium.org

Get rid of FileThreadDeserializer.

Replace it with modern threading constructs:
 - PostTaskAndReplyWithResult gets rid of most of the logic FileThreadDeserializer was implementing.
 - The remainder logic didn't require any class state so it was moved to anonymous methods.

Also declare JsonPrefStore explicitly NonThreadSafe (the only actions outside the UI thread should happen by posting anonymous tasks to the |sequenced_task_runner_|).

This is a stepping stone in cleaning up JsonPrefStore to eventually get rid of PrefStore's ref-counting scheme.

BUG=393081

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284754 0039d316-1c4b-4281-b951-d872f2087c98
parent 4cbbeb41
This diff is collapsed.
......@@ -19,6 +19,7 @@
#include "base/observer_list.h"
#include "base/prefs/base_prefs_export.h"
#include "base/prefs/persistent_pref_store.h"
#include "base/threading/non_thread_safe.h"
class PrefFilter;
......@@ -30,13 +31,15 @@ class SequencedWorkerPool;
class Value;
}
// A writable PrefStore implementation that is used for user preferences.
class BASE_PREFS_EXPORT JsonPrefStore
: public PersistentPrefStore,
public base::ImportantFileWriter::DataSerializer,
public base::SupportsWeakPtr<JsonPrefStore> {
public base::SupportsWeakPtr<JsonPrefStore>,
public base::NonThreadSafe {
public:
struct ReadResult;
// Returns instance of SequencedTaskRunner which guarantees that file
// operations on the same file will be executed in sequenced order.
static scoped_refptr<base::SequencedTaskRunner> GetTaskRunnerForFile(
......@@ -94,23 +97,16 @@ class BASE_PREFS_EXPORT JsonPrefStore
void RegisterOnNextSuccessfulWriteCallback(
const base::Closure& on_next_successful_write);
private:
virtual ~JsonPrefStore();
// This method is called after the JSON file has been read. It then hands
// |value| (or an empty dictionary in some read error cases) to the
// |pref_filter| if one is set. It also gives a callback pointing at
// FinalizeFileRead() to that |pref_filter_| which is then responsible for
// invoking it when done. If there is no |pref_filter_|, FinalizeFileRead()
// is invoked directly.
// Note, this method is used with asynchronous file reading, so this class
// exposes it only for the internal needs (read: do not call it manually).
// TODO(gab): Move this method to the private section and hand a callback to
// it to FileThreadDeserializer rather than exposing this public method and
// giving a JsonPrefStore* to FileThreadDeserializer.
void OnFileRead(scoped_ptr<base::Value> value,
PrefReadError error,
bool no_dir);
private:
virtual ~JsonPrefStore();
void OnFileRead(scoped_ptr<ReadResult> read_result);
// ImportantFileWriter::DataSerializer overrides:
virtual bool SerializeData(std::string* output) OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment