OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/json_pref_store.h" | 5 #include "chrome/common/json_pref_store.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "content/common/json_value_serializer.h" | 15 #include "content/common/json_value_serializer.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // Some extensions we'll tack on to copies of the Preferences files. | 19 // Some extensions we'll tack on to copies of the Preferences files. |
20 const FilePath::CharType* kBadExtension = FILE_PATH_LITERAL("bad"); | 20 const FilePath::CharType* kBadExtension = FILE_PATH_LITERAL("bad"); |
21 | 21 |
22 // Differentiates file loading between origin thread and passed | 22 // Differentiates file loading between origin thread and passed |
23 // (aka file) thread. | 23 // (aka file) thread. |
24 class FileThreadDeserializer | 24 class FileThreadDeserializer |
25 : public base::RefCountedThreadSafe<FileThreadDeserializer> { | 25 : public base::RefCountedThreadSafe<FileThreadDeserializer> { |
26 public: | 26 public: |
27 explicit FileThreadDeserializer(JsonPrefStore* delegate, | 27 FileThreadDeserializer(JsonPrefStore* delegate, |
28 base::MessageLoopProxy* file_loop_proxy) | 28 base::MessageLoopProxy* file_loop_proxy) |
29 : no_dir_(false), | 29 : no_dir_(false), |
30 error_(PersistentPrefStore::PREF_READ_ERROR_NONE), | 30 error_(PersistentPrefStore::PREF_READ_ERROR_NONE), |
31 delegate_(delegate), | 31 delegate_(delegate), |
32 file_loop_proxy_(file_loop_proxy), | 32 file_loop_proxy_(file_loop_proxy), |
33 origin_loop_proxy_(base::MessageLoopProxy::CreateForCurrentThread()) { | 33 origin_loop_proxy_(base::MessageLoopProxy::CreateForCurrentThread()) { |
34 } | 34 } |
35 | 35 |
36 void Start(const FilePath& path) { | 36 void Start(const FilePath& path) { |
37 DCHECK(origin_loop_proxy_->BelongsToCurrentThread()); | 37 DCHECK(origin_loop_proxy_->BelongsToCurrentThread()); |
38 file_loop_proxy_->PostTask( | 38 file_loop_proxy_->PostTask( |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 } | 311 } |
312 | 312 |
313 bool JsonPrefStore::SerializeData(std::string* output) { | 313 bool JsonPrefStore::SerializeData(std::string* output) { |
314 // TODO(tc): Do we want to prune webkit preferences that match the default | 314 // TODO(tc): Do we want to prune webkit preferences that match the default |
315 // value? | 315 // value? |
316 JSONStringValueSerializer serializer(output); | 316 JSONStringValueSerializer serializer(output); |
317 serializer.set_pretty_print(true); | 317 serializer.set_pretty_print(true); |
318 scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren()); | 318 scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren()); |
319 return serializer.Serialize(*(copy.get())); | 319 return serializer.Serialize(*(copy.get())); |
320 } | 320 } |
OLD | NEW |