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 } | |
530 int result = base::WriteFile(filename, serialized.data(), serialized.size()); | 526 int result = base::WriteFile(filename, serialized.data(), serialized.size()); |
531 return result == static_cast<int>(serialized.size()); | 527 return result == static_cast<int>(serialized.size()); |
532 } | 528 } |
533 | 529 |
534 // Loads all entities and server state from a protobuf file in |filename|. | 530 // Loads all entities and server state from a protobuf file in |filename|. |
535 bool LoopbackServer::LoadStateFromFile(const base::FilePath& filename) { | 531 bool LoopbackServer::LoadStateFromFile(const base::FilePath& filename) { |
536 if (base::PathExists(filename)) { | 532 if (base::PathExists(filename)) { |
537 std::string serialized; | 533 std::string serialized; |
538 if (base::ReadFileToString(filename, &serialized)) { | 534 if (base::ReadFileToString(filename, &serialized)) { |
539 sync_pb::LoopbackServerProto proto; | 535 sync_pb::LoopbackServerProto proto; |
(...skipping 11 matching lines...) Expand all Loading... |
551 // write. | 547 // write. |
552 LOG(ERROR) << "Loopback sync can not read the persistent state file."; | 548 LOG(ERROR) << "Loopback sync can not read the persistent state file."; |
553 return false; | 549 return false; |
554 } | 550 } |
555 } | 551 } |
556 LOG(WARNING) << "Loopback sync persistent state file does not exist."; | 552 LOG(WARNING) << "Loopback sync persistent state file does not exist."; |
557 return false; | 553 return false; |
558 } | 554 } |
559 | 555 |
560 } // namespace syncer | 556 } // namespace syncer |
OLD | NEW |