Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: google_apis/gcm/engine/gcm_store_impl.cc

Issue 2380003002: GCM Store: Fix invalid argument errors (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "google_apis/gcm/engine/gcm_store_impl.h" 5 #include "google_apis/gcm/engine/gcm_store_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 return key.substr(arraysize(kInstanceIDKeyStart) - 1); 171 return key.substr(arraysize(kInstanceIDKeyStart) - 1);
172 } 172 }
173 173
174 // Note: leveldb::Slice keeps a pointer to the data in |s|, which must therefore 174 // Note: leveldb::Slice keeps a pointer to the data in |s|, which must therefore
175 // outlive the slice. 175 // outlive the slice.
176 // For example: MakeSlice(MakeOutgoingKey(x)) is invalid. 176 // For example: MakeSlice(MakeOutgoingKey(x)) is invalid.
177 leveldb::Slice MakeSlice(const base::StringPiece& s) { 177 leveldb::Slice MakeSlice(const base::StringPiece& s) {
178 return leveldb::Slice(s.begin(), s.size()); 178 return leveldb::Slice(s.begin(), s.size());
179 } 179 }
180 180
181 bool DatabaseExists(const base::FilePath& path) {
182 // It's not enough to check that the directory exists, since DestroyDB
183 // sometimes leaves behind an empty directory
184 // (https://github.com/google/leveldb/issues/215).
185 return base::DirectoryExists(path) &&
186 base::PathExists(path.Append("CURRENT"));
Nicolas Zea 2016/09/29 16:49:57 is PathExists sufficient? Do we still need Directo
johnme 2016/09/29 17:08:29 Done (yeah, I was just trying to be explicit, but
187 }
188
181 } // namespace 189 } // namespace
182 190
183 class GCMStoreImpl::Backend 191 class GCMStoreImpl::Backend
184 : public base::RefCountedThreadSafe<GCMStoreImpl::Backend> { 192 : public base::RefCountedThreadSafe<GCMStoreImpl::Backend> {
185 public: 193 public:
186 Backend(const base::FilePath& path, 194 Backend(const base::FilePath& path,
187 scoped_refptr<base::SequencedTaskRunner> foreground_runner, 195 scoped_refptr<base::SequencedTaskRunner> foreground_runner,
188 std::unique_ptr<Encryptor> encryptor); 196 std::unique_ptr<Encryptor> encryptor);
189 197
190 // Blocking implementations of GCMStoreImpl methods. 198 // Blocking implementations of GCMStoreImpl methods.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 LoadStatus GCMStoreImpl::Backend::OpenStoreAndLoadData(StoreOpenMode open_mode, 288 LoadStatus GCMStoreImpl::Backend::OpenStoreAndLoadData(StoreOpenMode open_mode,
281 LoadResult* result) { 289 LoadResult* result) {
282 LoadStatus load_status; 290 LoadStatus load_status;
283 if (db_.get()) { 291 if (db_.get()) {
284 LOG(ERROR) << "Attempting to reload open database."; 292 LOG(ERROR) << "Attempting to reload open database.";
285 return RELOADING_OPEN_STORE; 293 return RELOADING_OPEN_STORE;
286 } 294 }
287 295
288 // Checks if the store exists or not. Calling DB::Open with create_if_missing 296 // Checks if the store exists or not. Calling DB::Open with create_if_missing
289 // not set will still create a new directory if the store does not exist. 297 // not set will still create a new directory if the store does not exist.
290 if (open_mode == DO_NOT_CREATE && !base::DirectoryExists(path_)) { 298 if (open_mode == DO_NOT_CREATE && !DatabaseExists(path_)) {
291 DVLOG(2) << "Database " << path_.value() << " does not exist"; 299 DVLOG(2) << "Database " << path_.value() << " does not exist";
292 return STORE_DOES_NOT_EXIST; 300 return STORE_DOES_NOT_EXIST;
293 } 301 }
294 302
295 leveldb::Options options; 303 leveldb::Options options;
296 options.create_if_missing = open_mode == CREATE_IF_MISSING; 304 options.create_if_missing = open_mode == CREATE_IF_MISSING;
297 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; 305 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue;
298 options.paranoid_checks = true; 306 options.paranoid_checks = true;
299 leveldb::DB* db; 307 leveldb::DB* db;
300 leveldb::Status status = 308 leveldb::Status status =
(...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 removed_message_counts.begin(); 1482 removed_message_counts.begin();
1475 iter != removed_message_counts.end(); ++iter) { 1483 iter != removed_message_counts.end(); ++iter) {
1476 DCHECK_NE(app_message_counts_.count(iter->first), 0U); 1484 DCHECK_NE(app_message_counts_.count(iter->first), 0U);
1477 app_message_counts_[iter->first] -= iter->second; 1485 app_message_counts_[iter->first] -= iter->second;
1478 DCHECK_GE(app_message_counts_[iter->first], 0); 1486 DCHECK_GE(app_message_counts_[iter->first], 0);
1479 } 1487 }
1480 callback.Run(true); 1488 callback.Run(true);
1481 } 1489 }
1482 1490
1483 } // namespace gcm 1491 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698