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

Side by Side Diff: components/safe_browsing_db/v4_database.cc

Issue 2103693002: SafeBrowsing PVer4: Send mutable response to the database and the stores (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@02_ReadFromDisk
Patch Set: Created 4 years, 5 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 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 <memory> 5 #include <memory>
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/debug/leak_annotations.h" 8 #include "base/debug/leak_annotations.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 V4Database* v4_database_raw = v4_database.release(); 85 V4Database* v4_database_raw = v4_database.release();
86 if (v4_database_raw) { 86 if (v4_database_raw) {
87 v4_database_raw->db_task_runner_->DeleteSoon(FROM_HERE, v4_database_raw); 87 v4_database_raw->db_task_runner_->DeleteSoon(FROM_HERE, v4_database_raw);
88 } 88 }
89 } 89 }
90 90
91 V4Database::~V4Database() { 91 V4Database::~V4Database() {
92 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 92 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
93 } 93 }
94 94
95 void V4Database::ApplyUpdate(const std::vector<ListUpdateResponse>& responses, 95 void V4Database::ApplyUpdate(
96 DatabaseUpdatedCallback db_updated_callback) { 96 std::unique_ptr<ParsedServerResponse> parsed_server_response,
97 DatabaseUpdatedCallback db_updated_callback) {
97 DCHECK_CURRENTLY_ON(BrowserThread::IO); 98 DCHECK_CURRENTLY_ON(BrowserThread::IO);
98 DCHECK(!pending_store_updates_); 99 DCHECK(!pending_store_updates_);
99 DCHECK(db_updated_callback_.is_null()); 100 DCHECK(db_updated_callback_.is_null());
100 101
101 db_updated_callback_ = db_updated_callback; 102 db_updated_callback_ = db_updated_callback;
102 103
103 // Post the V4Store update task on the task runner but get the callback on the 104 // Post the V4Store update task on the task runner but get the callback on the
104 // current thread. 105 // current thread.
105 const scoped_refptr<base::SingleThreadTaskRunner>& current_task_runner = 106 const scoped_refptr<base::SingleThreadTaskRunner>& current_task_runner =
106 base::MessageLoop::current()->task_runner(); 107 base::MessageLoop::current()->task_runner();
107 for (const ListUpdateResponse& response : responses) { 108 for (std::unique_ptr<ListUpdateResponse>& response :
Scott Hess - ex-Googler 2016/06/28 03:58:43 I'm not entirely comfortable with the non-const &,
Nathan Parker 2016/06/28 19:00:37 I think for(..:..) loops by default copy the eleme
vakh (use Gerrit instead) 2016/06/28 21:34:14 Removing the "&" also leads to a compile-time erro
vakh (use Gerrit instead) 2016/06/28 21:34:14 1. Adding constness leads to a compile-time error:
Scott Hess - ex-Googler 2016/06/28 22:22:25 Apologies - that's expected, because you need to m
vakh (use Gerrit instead) 2016/06/29 19:58:52 I am going ahead with the current implementation f
Scott Hess - ex-Googler 2016/06/29 20:15:58 Acknowledged. I wonder where we'd be if move sema
108 UpdateListIdentifier identifier(response); 109 *parsed_server_response) {
110 UpdateListIdentifier identifier(response.get());
109 StoreMap::const_iterator iter = store_map_->find(identifier); 111 StoreMap::const_iterator iter = store_map_->find(identifier);
110 if (iter != store_map_->end()) { 112 if (iter != store_map_->end()) {
111 const std::unique_ptr<V4Store>& old_store = iter->second; 113 const std::unique_ptr<V4Store>& old_store = iter->second;
112 if (old_store->state() != response.new_client_state()) { 114 if (old_store->state() != response->new_client_state()) {
113 // A different state implies there are updates to process. 115 // A different state implies there are updates to process.
114 pending_store_updates_++; 116 pending_store_updates_++;
115 UpdatedStoreReadyCallback store_ready_callback = base::Bind( 117 UpdatedStoreReadyCallback store_ready_callback = base::Bind(
116 &V4Database::UpdatedStoreReady, base::Unretained(this), identifier); 118 &V4Database::UpdatedStoreReady, base::Unretained(this), identifier);
117 db_task_runner_->PostTask( 119 db_task_runner_->PostTask(
118 FROM_HERE, 120 FROM_HERE,
119 base::Bind(&V4Store::ApplyUpdate, base::Unretained(old_store.get()), 121 base::Bind(&V4Store::ApplyUpdate, base::Unretained(old_store.get()),
120 response, current_task_runner, store_ready_callback)); 122 base::Passed(std::move(response)), current_task_runner,
123 store_ready_callback));
121 } 124 }
122 } else { 125 } else {
123 NOTREACHED() << "Got update for unexpected identifier: " << identifier; 126 NOTREACHED() << "Got update for unexpected identifier: " << identifier;
124 } 127 }
125 } 128 }
126 129
127 if (!pending_store_updates_) { 130 if (!pending_store_updates_) {
128 current_task_runner->PostTask(FROM_HERE, db_updated_callback_); 131 current_task_runner->PostTask(FROM_HERE, db_updated_callback_);
129 db_updated_callback_.Reset(); 132 db_updated_callback_.Reset();
130 } 133 }
(...skipping 26 matching lines...) Expand all
157 std::unique_ptr<StoreStateMap> V4Database::GetStoreStateMap() { 160 std::unique_ptr<StoreStateMap> V4Database::GetStoreStateMap() {
158 std::unique_ptr<StoreStateMap> store_state_map = 161 std::unique_ptr<StoreStateMap> store_state_map =
159 base::MakeUnique<StoreStateMap>(); 162 base::MakeUnique<StoreStateMap>();
160 for (const auto& store_map_iter : *store_map_) { 163 for (const auto& store_map_iter : *store_map_) {
161 (*store_state_map)[store_map_iter.first] = store_map_iter.second->state(); 164 (*store_state_map)[store_map_iter.first] = store_map_iter.second->state();
162 } 165 }
163 return store_state_map; 166 return store_state_map;
164 } 167 }
165 168
166 } // namespace safe_browsing 169 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698