| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/filesystem/public/cpp/prefs/filesystem_json_pref_store.h" | 5 #include "components/filesystem/public/cpp/prefs/filesystem_json_pref_store.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/json/json_string_value_serializer.h" | 16 #include "base/json/json_string_value_serializer.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/task_runner_util.h" | 22 #include "base/task_runner_util.h" |
| 23 #include "base/time/default_clock.h" | 23 #include "base/time/default_clock.h" |
| 24 #include "base/values.h" | 24 #include "base/values.h" |
| 25 #include "components/prefs/pref_filter.h" | 25 #include "components/prefs/pref_filter.h" |
| 26 #include "mojo/common/common_type_converters.h" | |
| 27 | 26 |
| 28 namespace filesystem { | 27 namespace filesystem { |
| 29 | 28 |
| 30 // Result returned from internal read tasks. | 29 // Result returned from internal read tasks. |
| 31 struct FilesystemJsonPrefStore::ReadResult { | 30 struct FilesystemJsonPrefStore::ReadResult { |
| 32 public: | 31 public: |
| 33 ReadResult(); | 32 ReadResult(); |
| 34 ~ReadResult(); | 33 ~ReadResult(); |
| 35 | 34 |
| 36 std::unique_ptr<base::Value> value; | 35 std::unique_ptr<base::Value> value; |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 358 |
| 360 if (pref_filter_) | 359 if (pref_filter_) |
| 361 pref_filter_->FilterSerializeData(prefs_.get()); | 360 pref_filter_->FilterSerializeData(prefs_.get()); |
| 362 | 361 |
| 363 std::string output; | 362 std::string output; |
| 364 JSONStringValueSerializer serializer(&output); | 363 JSONStringValueSerializer serializer(&output); |
| 365 serializer.set_pretty_print(false); | 364 serializer.set_pretty_print(false); |
| 366 serializer.Serialize(*prefs_); | 365 serializer.Serialize(*prefs_); |
| 367 | 366 |
| 368 directory_->WriteFile( | 367 directory_->WriteFile( |
| 369 "tmp", | 368 "tmp", std::vector<uint8_t>(output.begin(), output.end()), |
| 370 mojo::Array<uint8_t>::From(output), | |
| 371 Bind(&FilesystemJsonPrefStore::OnTempFileWrite, AsWeakPtr())); | 369 Bind(&FilesystemJsonPrefStore::OnTempFileWrite, AsWeakPtr())); |
| 372 } | 370 } |
| 373 | 371 |
| 374 void FilesystemJsonPrefStore::OnTempFileWrite(mojom::FileError err) { | 372 void FilesystemJsonPrefStore::OnTempFileWrite(mojom::FileError err) { |
| 375 // TODO(erg): Error handling. The JsonPrefStore code assumes that writing the | 373 // TODO(erg): Error handling. The JsonPrefStore code assumes that writing the |
| 376 // file can never fail. | 374 // file can never fail. |
| 377 CHECK_EQ(mojom::FileError::OK, err); | 375 CHECK_EQ(mojom::FileError::OK, err); |
| 378 | 376 |
| 379 directory_->Rename( | 377 directory_->Rename( |
| 380 "tmp", path_, | 378 "tmp", path_, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 reinterpret_cast<char*>(&contents.front()), contents.size())); | 414 reinterpret_cast<char*>(&contents.front()), contents.size())); |
| 417 read_result->value = deserializer.Deserialize(&error_code, &error_msg); | 415 read_result->value = deserializer.Deserialize(&error_code, &error_msg); |
| 418 read_result->error = HandleReadErrors(read_result->value.get()); | 416 read_result->error = HandleReadErrors(read_result->value.get()); |
| 419 } | 417 } |
| 420 } | 418 } |
| 421 | 419 |
| 422 OnFileRead(std::move(read_result)); | 420 OnFileRead(std::move(read_result)); |
| 423 } | 421 } |
| 424 | 422 |
| 425 } // namespace filesystem | 423 } // namespace filesystem |
| OLD | NEW |