OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/sync_file_system/drive_backend/drive_backend_util.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/threading/thread_restrictions.h" |
11 #include "chrome/browser/drive/drive_api_util.h" | 12 #include "chrome/browser/drive/drive_api_util.h" |
12 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.
h" | 13 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.
h" |
13 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" | 14 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" |
14 #include "chrome/browser/sync_file_system/logger.h" | 15 #include "chrome/browser/sync_file_system/logger.h" |
15 #include "google_apis/drive/drive_api_parser.h" | 16 #include "google_apis/drive/drive_api_parser.h" |
16 #include "google_apis/drive/gdata_wapi_parser.h" | 17 #include "google_apis/drive/gdata_wapi_parser.h" |
| 18 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
17 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 19 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
18 | 20 |
19 namespace sync_file_system { | 21 namespace sync_file_system { |
20 namespace drive_backend { | 22 namespace drive_backend { |
21 | 23 |
22 void PutServiceMetadataToBatch(const ServiceMetadata& service_metadata, | 24 void PutServiceMetadataToBatch(const ServiceMetadata& service_metadata, |
23 leveldb::WriteBatch* batch) { | 25 leveldb::WriteBatch* batch) { |
| 26 if (!batch) |
| 27 return; |
| 28 |
24 std::string value; | 29 std::string value; |
25 bool success = service_metadata.SerializeToString(&value); | 30 bool success = service_metadata.SerializeToString(&value); |
26 DCHECK(success); | 31 DCHECK(success); |
27 batch->Put(kServiceMetadataKey, value); | 32 batch->Put(kServiceMetadataKey, value); |
28 } | 33 } |
29 | 34 |
30 void PutFileMetadataToBatch(const FileMetadata& file, | 35 void PutFileMetadataToBatch(const FileMetadata& file, |
31 leveldb::WriteBatch* batch) { | 36 leveldb::WriteBatch* batch) { |
32 if (!batch) | 37 if (!batch) |
33 return; | 38 return; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 if (out) | 159 if (out) |
155 *out = str; | 160 *out = str; |
156 return false; | 161 return false; |
157 } | 162 } |
158 | 163 |
159 if (out) | 164 if (out) |
160 *out = str.substr(prefix.size()); | 165 *out = str.substr(prefix.size()); |
161 return true; | 166 return true; |
162 } | 167 } |
163 | 168 |
| 169 scoped_ptr<ServiceMetadata> InitializeServiceMetadata(leveldb::DB* db) { |
| 170 base::ThreadRestrictions::AssertIOAllowed(); |
| 171 DCHECK(db); |
| 172 |
| 173 std::string value; |
| 174 leveldb::Status status = db->Get(leveldb::ReadOptions(), |
| 175 kServiceMetadataKey, |
| 176 &value); |
| 177 |
| 178 scoped_ptr<ServiceMetadata> service_metadata(new ServiceMetadata); |
| 179 if (!status.ok() || !service_metadata->ParseFromString(value)) |
| 180 service_metadata->set_next_tracker_id(1); |
| 181 |
| 182 return service_metadata.Pass(); |
| 183 } |
| 184 |
164 } // namespace drive_backend | 185 } // namespace drive_backend |
165 } // namespace sync_file_system | 186 } // namespace sync_file_system |
OLD | NEW |