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

Side by Side Diff: content/browser/notifications/notification_database.cc

Issue 1025743002: Write the assigned notification id to the stored notification data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | content/browser/notifications/notification_database_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/notifications/notification_database.h" 5 #include "content/browser/notifications/notification_database.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 NotificationDatabase::Status NotificationDatabase::WriteNotificationData( 183 NotificationDatabase::Status NotificationDatabase::WriteNotificationData(
184 const GURL& origin, 184 const GURL& origin,
185 const NotificationDatabaseData& notification_database_data, 185 const NotificationDatabaseData& notification_database_data,
186 int64_t* notification_id) { 186 int64_t* notification_id) {
187 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); 187 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
188 DCHECK_EQ(STATE_INITIALIZED, state_); 188 DCHECK_EQ(STATE_INITIALIZED, state_);
189 DCHECK(notification_id); 189 DCHECK(notification_id);
190 DCHECK(origin.is_valid()); 190 DCHECK(origin.is_valid());
191 191
192 DCHECK_GE(next_notification_id_, kFirstNotificationId);
193
194 NotificationDatabaseData storage_data = notification_database_data;
195 storage_data.notification_id = next_notification_id_;
196
192 std::string serialized_data; 197 std::string serialized_data;
193 if (!SerializeNotificationDatabaseData(notification_database_data, 198 if (!SerializeNotificationDatabaseData(storage_data,
194 &serialized_data)) { 199 &serialized_data)) {
195 DLOG(ERROR) << "Unable to serialize data for a notification belonging " 200 DLOG(ERROR) << "Unable to serialize data for a notification belonging "
196 << "to: " << origin; 201 << "to: " << origin;
197 return STATUS_ERROR_FAILED; 202 return STATUS_ERROR_FAILED;
198 } 203 }
199 204
200 DCHECK_GE(next_notification_id_, kFirstNotificationId);
201
202 leveldb::WriteBatch batch; 205 leveldb::WriteBatch batch;
203 batch.Put(CreateDataKey(origin, next_notification_id_), serialized_data); 206 batch.Put(CreateDataKey(origin, next_notification_id_), serialized_data);
204 batch.Put(kNextNotificationIdKey, 207 batch.Put(kNextNotificationIdKey,
205 base::Int64ToString(next_notification_id_ + 1)); 208 base::Int64ToString(next_notification_id_ + 1));
206 209
207 Status status = LevelDBStatusToStatus( 210 Status status = LevelDBStatusToStatus(
208 db_->Write(leveldb::WriteOptions(), &batch)); 211 db_->Write(leveldb::WriteOptions(), &batch));
209 if (status != STATUS_OK) 212 if (status != STATUS_OK)
210 return status; 213 return status;
211 214
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 batch.Delete(iter->key()); 366 batch.Delete(iter->key());
364 } 367 }
365 368
366 if (deleted_notification_set->empty()) 369 if (deleted_notification_set->empty())
367 return STATUS_OK; 370 return STATUS_OK;
368 371
369 return LevelDBStatusToStatus(db_->Write(leveldb::WriteOptions(), &batch)); 372 return LevelDBStatusToStatus(db_->Write(leveldb::WriteOptions(), &batch));
370 } 373 }
371 374
372 } // namespace content 375 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/notifications/notification_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698