OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/sync/engine_impl/loopback_server/loopback_server.h" | 5 #include "components/sync/engine_impl/loopback_server/loopback_server.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 | 516 |
517 return true; | 517 return true; |
518 } | 518 } |
519 | 519 |
520 // Saves all entities and server state to a protobuf file in |filename|. | 520 // Saves all entities and server state to a protobuf file in |filename|. |
521 bool LoopbackServer::SaveStateToFile(const base::FilePath& filename) const { | 521 bool LoopbackServer::SaveStateToFile(const base::FilePath& filename) const { |
522 sync_pb::LoopbackServerProto proto; | 522 sync_pb::LoopbackServerProto proto; |
523 SerializeState(&proto); | 523 SerializeState(&proto); |
524 | 524 |
525 std::string serialized = proto.SerializeAsString(); | 525 std::string serialized = proto.SerializeAsString(); |
| 526 if (!base::CreateDirectory(filename.DirName())) { |
| 527 LOG(ERROR) << "Loopback sync could not create the storage directory."; |
| 528 return false; |
| 529 } |
526 int result = base::WriteFile(filename, serialized.data(), serialized.size()); | 530 int result = base::WriteFile(filename, serialized.data(), serialized.size()); |
527 return result == static_cast<int>(serialized.size()); | 531 return result == static_cast<int>(serialized.size()); |
528 } | 532 } |
529 | 533 |
530 // Loads all entities and server state from a protobuf file in |filename|. | 534 // Loads all entities and server state from a protobuf file in |filename|. |
531 bool LoopbackServer::LoadStateFromFile(const base::FilePath& filename) { | 535 bool LoopbackServer::LoadStateFromFile(const base::FilePath& filename) { |
532 if (base::PathExists(filename)) { | 536 if (base::PathExists(filename)) { |
533 std::string serialized; | 537 std::string serialized; |
534 if (base::ReadFileToString(filename, &serialized)) { | 538 if (base::ReadFileToString(filename, &serialized)) { |
535 sync_pb::LoopbackServerProto proto; | 539 sync_pb::LoopbackServerProto proto; |
(...skipping 11 matching lines...) Expand all Loading... |
547 // write. | 551 // write. |
548 LOG(ERROR) << "Loopback sync can not read the persistent state file."; | 552 LOG(ERROR) << "Loopback sync can not read the persistent state file."; |
549 return false; | 553 return false; |
550 } | 554 } |
551 } | 555 } |
552 LOG(WARNING) << "Loopback sync persistent state file does not exist."; | 556 LOG(WARNING) << "Loopback sync persistent state file does not exist."; |
553 return false; | 557 return false; |
554 } | 558 } |
555 | 559 |
556 } // namespace syncer | 560 } // namespace syncer |
OLD | NEW |