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) { |
tzik
2014/07/15 13:55:45
Can we add if (!batch)return; here and skip NULL c
peria
2014/07/16 02:08:50
Done.
| |
24 std::string value; | 26 std::string value; |
25 bool success = service_metadata.SerializeToString(&value); | 27 bool success = service_metadata.SerializeToString(&value); |
26 DCHECK(success); | 28 DCHECK(success); |
27 batch->Put(kServiceMetadataKey, value); | 29 batch->Put(kServiceMetadataKey, value); |
28 } | 30 } |
29 | 31 |
30 void PutFileMetadataToBatch(const FileMetadata& file, | 32 void PutFileMetadataToBatch(const FileMetadata& file, |
31 leveldb::WriteBatch* batch) { | 33 leveldb::WriteBatch* batch) { |
32 if (!batch) | 34 if (!batch) |
33 return; | 35 return; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 if (out) | 156 if (out) |
155 *out = str; | 157 *out = str; |
156 return false; | 158 return false; |
157 } | 159 } |
158 | 160 |
159 if (out) | 161 if (out) |
160 *out = str.substr(prefix.size()); | 162 *out = str.substr(prefix.size()); |
161 return true; | 163 return true; |
162 } | 164 } |
163 | 165 |
166 scoped_ptr<ServiceMetadata> InitializeServiceMetadata(leveldb::DB* db) { | |
167 base::ThreadRestrictions::AssertIOAllowed(); | |
168 DCHECK(db); | |
169 | |
170 std::string value; | |
171 leveldb::Status status = db->Get(leveldb::ReadOptions(), | |
172 kServiceMetadataKey, | |
173 &value); | |
174 | |
175 scoped_ptr<ServiceMetadata> service_metadata(new ServiceMetadata); | |
176 if (!status.ok() || !service_metadata->ParseFromString(value)) | |
177 service_metadata->set_next_tracker_id(1); | |
178 | |
179 return service_metadata.Pass(); | |
180 } | |
181 | |
164 } // namespace drive_backend | 182 } // namespace drive_backend |
165 } // namespace sync_file_system | 183 } // namespace sync_file_system |
OLD | NEW |